@ThreadSafe public class FirehoseProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record> extends Object implements IProducer<O,R>
| Modifier and Type | Class and Description |
|---|---|
static class |
FirehoseProducer.UserRecordResult |
| Constructor and Description |
|---|
FirehoseProducer(String deliveryStream,
com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehose firehoseClient,
Properties configProps) |
| Modifier and Type | Method and Description |
|---|---|
com.google.common.util.concurrent.ListenableFuture<O> |
addUserRecord(R record)
This method should send data to an specific destination.
|
com.google.common.util.concurrent.ListenableFuture<O> |
addUserRecord(R record,
long timeoutInMillis)
This method is responsible for taking a lock adding a
Record into the producerBuffer, in case the producerBuffer is full
waits releasing the lock for the given bufferFullWaitTimeoutInMillis. |
void |
destroy()
Make sure that any pending scheduled thread terminates before closing as well as cleans the producerBuffer pool,
allowing GC to collect.
|
void |
flush()
This method instructs the flusher thread to perform a flush on the buffer without waiting for completion.
|
void |
flushSync()
This method instructs the flusher thread to perform the flush on the buffer and wait for the completion.
|
int |
getOutstandingRecordsCount()
Should return the number of outstanding records if the producer implements buffering.
|
boolean |
isDestroyed()
Returns whether the producer has been destroyed or not
|
boolean |
isFlushFailed()
A flag representing whether the flush has failed or not.
|
public FirehoseProducer(String deliveryStream, com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehose firehoseClient, Properties configProps)
public com.google.common.util.concurrent.ListenableFuture<O> addUserRecord(R record) throws Exception
IProduceraddUserRecord in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>record - the type of data to be sentListenableFuture with the result for the operation.Exceptionpublic com.google.common.util.concurrent.ListenableFuture<O> addUserRecord(R record, long timeoutInMillis) throws TimeoutExpiredException, InterruptedException
Record into the producerBuffer, in case the producerBuffer is full
waits releasing the lock for the given bufferFullWaitTimeoutInMillis.
There are cases where the producerBuffer cannot be flushed then this method keeps waiting until the given operation timeout
passed as timeoutInMillisaddUserRecord in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>record - the type of data to be bufferedtimeoutInMillis - the operation timeout in case the record cannot be added into the producerBuffer.TimeoutExpiredException - if the operation got stuck and is not able to proceed.InterruptedException - if any thread interrupted the current thread before or while the current thread
was waiting for a notification. The interrupted status of the current thread is cleared when
this exception is thrown.public void destroy()
throws Exception
public boolean isDestroyed()
IProducerisDestroyed in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>public int getOutstandingRecordsCount()
IProducergetOutstandingRecordsCount in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>public boolean isFlushFailed()
IProducerisFlushFailed in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>boolean representing whether the success of failure of flush buffer operation.public void flush()
This implementation does not guarantee the whole buffer is flushed or if the flusher thread
has completed the flush or not.
In order to flush all records and wait until completion, use {@link #flushSync()}
flush in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>public void flushSync()
This implementation is useful once there is a need to guarantee the buffer is flushed before making further progress. i.e. Shutting down the producer. i.e. Taking synchronous snapshots.
The caller needs to make sure to assert the status ofisFlushFailed() in order guarantee whether
the flush has successfully completed or not.flushSync in interface IProducer<O extends FirehoseProducer.UserRecordResult,R extends com.amazonaws.services.kinesisfirehose.model.Record>Copyright © 2019. All rights reserved.