public class DataReceiverImpl extends Object implements DataReceiver
DataReceiver interface.
Use the internal DataReceiverImpl.Builder class for creating instances of the
DataReceiverImpl class. Note that the created
DataReceiverImpl will either use a given RabbitQueue or
create a new one. In both cases the receiver will become the owner of the
queue, i.e., if the DataReceiverImpl instance is closed the queue
will be closed as well.
Internally, the receiver uses a multithreaded consumer that handles incoming
streams, sorts the messages that belong to these streams and sends the
received data via an InputStream to the given
IncomingStreamHandler instance. Note that since the consumer
is multithreaded the
IncomingStreamHandler.handleIncomingStream(String, InputStream)
should be thread safe since it might be called in parallel. Even setting the
maximum number of parallel processed messages to 1 (via
DataReceiverImpl.Builder.maxParallelProcessedMsgs(int)) the given handler might be
called with several InputStream instances in parallel.
The DataReceiverImpl owns recources that need to be freed if its work
is done. This can be achieved by closing the receiver. In most cases, this
should be done using the closeWhenFinished() method which waits
until all incoming messages are processed and all streams are closed. Note
that using the close() method leads to a direct shutdown of the
queue which could lead to data loss and threads getting stuck.
| Modifier and Type | Class and Description |
|---|---|
static class |
DataReceiverImpl.Builder |
| Modifier and Type | Field and Description |
|---|---|
private static int |
CHECKS_BEFORE_CLOSING |
private MessageConsumer |
consumer |
private IncomingStreamHandler |
dataHandler |
private int |
errorCount |
private static org.slf4j.Logger |
LOGGER |
private String |
name |
protected RabbitQueue |
queue |
| Modifier | Constructor and Description |
|---|---|
protected |
DataReceiverImpl(RabbitQueue queue,
IncomingStreamHandler handler,
MessageConsumerBuilder consumerBuilder,
int maxParallelProcessedMsgs,
String name) |
| Modifier and Type | Method and Description |
|---|---|
static DataReceiverImpl.Builder |
builder()
Returns a newly created
DataReceiverImpl.Builder. |
void |
close()
A rude way to close the receiver.
|
void |
closeWhenFinished()
This method waits for the data receiver to finish its work and closes the
incoming queue as well as the internal thread pool after that.
|
IncomingStreamHandler |
getDataHandler() |
int |
getErrorCount()
Returns the number of errors that have been encountered while receiving
data.
|
RabbitQueue |
getQueue() |
void |
increaseErrorCount() |
private static final org.slf4j.Logger LOGGER
private static final int CHECKS_BEFORE_CLOSING
protected RabbitQueue queue
private int errorCount
private IncomingStreamHandler dataHandler
private MessageConsumer consumer
private String name
protected DataReceiverImpl(RabbitQueue queue, IncomingStreamHandler handler, MessageConsumerBuilder consumerBuilder, int maxParallelProcessedMsgs, String name) throws IOException
IOExceptionpublic IncomingStreamHandler getDataHandler()
getDataHandler in interface DataReceiverpublic void increaseErrorCount()
increaseErrorCount in interface DataReceiverpublic int getErrorCount()
DataReceivergetErrorCount in interface DataReceiverpublic RabbitQueue getQueue()
getQueue in interface DataReceiverpublic void closeWhenFinished()
closeWhenFinished in interface DataReceiverpublic void close()
close in interface Closeableclose in interface AutoCloseablepublic static DataReceiverImpl.Builder builder()
DataReceiverImpl.Builder.DataReceiverImpl.Builder instanceCopyright © 2017–2018. All rights reserved.