java/KinesisAggregator/src/main/java/com/amazonaws/kinesis/agg/RecordAggregator.java [36:145]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@NotThreadSafe
public class RecordAggregator {
	/**
	 * A listener interface for receiving notifications when this aggregated
	 * record has reached its maximum allowable size.
	 */
	public interface RecordCompleteListener {
		/**
		 * Called when an aggregated record is full and ready to be transmitted
		 * to Kinesis.
		 * 
		 * @param aggRecord
		 *            A complete aggregated record ready to transmit to Kinesis.
		 */
		public abstract void recordComplete(AggRecord aggRecord);
	}

	/** The current aggregated record being constructed. */
	private AggRecord currentRecord;
	/** The list of listeners to notify when a record is complete. */
	private List<ListenerExecutorPair> listeners;

	/**
	 * Construct a new empty record aggregator instance.
	 */
	public RecordAggregator() {
		this.currentRecord = new AggRecord();
		this.listeners = new LinkedList<>();
	}

	/**
	 * @return The number of user records currently contained in this aggregated
	 *         record.
	 */
	public int getNumUserRecords() {
		return this.currentRecord.getNumUserRecords();
	}

	/**
	 * @return The size of this aggregated record in bytes. This value is always
	 *         less than the Kinesis-defined maximum size for a PutRecordRequest
	 *         (i.e. 1MB as of 3/26/2016).
	 */
	public long getSizeBytes() {
		return this.currentRecord.getSizeBytes();
	}

	/**
	 * Clear all the user records from this aggregated record and reset it to an
	 * empty state.
	 * 
	 * NOTE: Will not affect any registered listeners.
	 */
	public void clearRecord() {
		this.currentRecord = new AggRecord();
	}

	/**
	 * Clear all the listeners from this object that were registered with the
	 * onRecordComplete method.
	 */
	public void clearListeners() {
		this.listeners.clear();
	}

	/**
	 * Register a callback method to be notified when there is a full aggregated
	 * record available. Callbacks registered via this method are executed on a
	 * separate thread from the common ForkJoin pool.
	 * 
	 * @param listener
	 *            The listener to receive a callback when there is a complete
	 *            aggregated record available (can be a lambda function).
	 */
	public void onRecordComplete(RecordCompleteListener listener) {
		onRecordComplete(listener, ForkJoinPool.commonPool());
	}

	/**
	 * Register a callback method to be notified when there is a full aggregated
	 * record available and invoke the callback using the specified executor.
	 * 
	 * @param listener
	 *            The listener to receive a callback when there is a complete
	 *            aggregated record available (can be a lambda function).
	 * @param executor
	 *            The executor to use to execute the callback.
	 */
	public void onRecordComplete(RecordCompleteListener listener, Executor executor) {
		this.listeners.add(new ListenerExecutorPair(listener, executor));
	}

	/**
	 * Get the current contents of this aggregated record (whether full or not)
	 * as a single record and then clear the contents of this object so it can
	 * be re-used. This method is useful for flushing the aggregated record when
	 * you need to transmit it before it is full (e.g. you're shutting down or
	 * haven't transmitted in a while).
	 * 
	 * @return This current object as an aggregated record or null if this
	 *         object is currently empty.
	 */
	public AggRecord clearAndGet() {
		if (getNumUserRecords() == 0) {
			return null;
		}

		AggRecord out = this.currentRecord;
		clearRecord();
		return out;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



java/KinesisAggregatorV2/src/main/java/com/amazonaws/kinesis/agg/RecordAggregator.java [38:143]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@NotThreadSafe
public class RecordAggregator {
	/**
	 * A listener interface for receiving notifications when this aggregated record
	 * has reached its maximum allowable size.
	 */
	public interface RecordCompleteListener {
		/**
		 * Called when an aggregated record is full and ready to be transmitted to
		 * Kinesis.
		 * 
		 * @param aggRecord A complete aggregated record ready to transmit to Kinesis.
		 */
		public abstract void recordComplete(AggRecord aggRecord);
	}

	/** The current aggregated record being constructed. */
	private AggRecord currentRecord;
	/** The list of listeners to notify when a record is complete. */
	private List<ListenerExecutorPair> listeners;

	/**
	 * Construct a new empty record aggregator instance.
	 */
	public RecordAggregator() {
		this.currentRecord = new AggRecord();
		this.listeners = new LinkedList<>();
	}

	/**
	 * @return The number of user records currently contained in this aggregated
	 *         record.
	 */
	public int getNumUserRecords() {
		return this.currentRecord.getNumUserRecords();
	}

	/**
	 * @return The size of this aggregated record in bytes. This value is always
	 *         less than the Kinesis-defined maximum size for a PutRecordRequest
	 *         (i.e. 1MB as of 3/26/2016).
	 */
	public long getSizeBytes() {
		return this.currentRecord.getSizeBytes();
	}

	/**
	 * Clear all the user records from this aggregated record and reset it to an
	 * empty state.
	 * 
	 * NOTE: Will not affect any registered listeners.
	 */
	public void clearRecord() {
		this.currentRecord = new AggRecord();
	}

	/**
	 * Clear all the listeners from this object that were registered with the
	 * onRecordComplete method.
	 */
	public void clearListeners() {
		this.listeners.clear();
	}

	/**
	 * Register a callback method to be notified when there is a full aggregated
	 * record available. Callbacks registered via this method are executed on a
	 * separate thread from the common ForkJoin pool.
	 * 
	 * @param listener The listener to receive a callback when there is a complete
	 *                 aggregated record available (can be a lambda function).
	 */
	public void onRecordComplete(RecordCompleteListener listener) {
		onRecordComplete(listener, ForkJoinPool.commonPool());
	}

	/**
	 * Register a callback method to be notified when there is a full aggregated
	 * record available and invoke the callback using the specified executor.
	 * 
	 * @param listener The listener to receive a callback when there is a complete
	 *                 aggregated record available (can be a lambda function).
	 * @param executor The executor to use to execute the callback.
	 */
	public void onRecordComplete(RecordCompleteListener listener, Executor executor) {
		this.listeners.add(new ListenerExecutorPair(listener, executor));
	}

	/**
	 * Get the current contents of this aggregated record (whether full or not) as a
	 * single record and then clear the contents of this object so it can be
	 * re-used. This method is useful for flushing the aggregated record when you
	 * need to transmit it before it is full (e.g. you're shutting down or haven't
	 * transmitted in a while).
	 * 
	 * @return This current object as an aggregated record or null if this object is
	 *         currently empty.
	 */
	public AggRecord clearAndGet() {
		if (getNumUserRecords() == 0) {
			return null;
		}

		AggRecord out = this.currentRecord;
		clearRecord();
		return out;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



