Package org.hobbit.core.rabbit
Class DataSenderImpl
- java.lang.Object
-
- org.hobbit.core.rabbit.DataSenderImpl
-
- All Implemented Interfaces:
Closeable,AutoCloseable,DataSender
public class DataSenderImpl extends Object implements DataSender
Implementation of theDataSenderinterface.Use the internal
DataSenderImpl.Builderclass for creating instances of theDataSenderImplclass. Note that the createdDataSenderImplwill either use a givenRabbitQueueor create a new one. In both cases the receiver will become the owner of the queue, i.e., if theDataSenderImplinstance is closed the queue will be closed as well.Note that choosing a message buffer size smaller than
DEFAULT_MESSAGE_BUFFER_SIZE=1000 might lead the sender to get stuck since confirmations might be sent rarely by the RabbitMQ broker.- Author:
- Michael Röder (roeder@informatik.uni-leipzig.de)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataSenderImpl.Builderprotected classDataSenderImpl.DataSenderConfirmHandlerprotected static classDataSenderImpl.Message
-
Field Summary
Fields Modifier and Type Field Description private DataSenderImpl.DataSenderConfirmHandlerconfirmHandlerprivate static intDEFAULT_DELIVERY_MODEprivate static intDEFAULT_MESSAGE_BUFFER_SIZEprivate intdeliveryModeprivate static org.slf4j.LoggerLOGGERprivate RabbitQueuequeue
-
Constructor Summary
Constructors Modifier Constructor Description protectedDataSenderImpl(RabbitQueue queue, int deliveryMode, int messageConfirmBuffer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataSenderImpl.Builderbuilder()Returns a newly createdDataSenderImpl.Builder.voidclose()voidcloseWhenFinished()A blocking method that closes the sender when its work is done, i.e., all messages have been consumed by receivers from the queue.voidsendData(byte[] data)Send the given data to the queue.protected voidsendData(byte[] data, com.rabbitmq.client.AMQP.BasicProperties.Builder probBuilder)protected voidsendData(com.rabbitmq.client.AMQP.BasicProperties properties, byte[] data)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DEFAULT_MESSAGE_BUFFER_SIZE
private static final int DEFAULT_MESSAGE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_DELIVERY_MODE
private static final int DEFAULT_DELIVERY_MODE
- See Also:
- Constant Field Values
-
queue
private RabbitQueue queue
-
deliveryMode
private final int deliveryMode
-
confirmHandler
private final DataSenderImpl.DataSenderConfirmHandler confirmHandler
-
-
Constructor Detail
-
DataSenderImpl
protected DataSenderImpl(RabbitQueue queue, int deliveryMode, int messageConfirmBuffer)
-
-
Method Detail
-
sendData
public void sendData(byte[] data) throws IOExceptionDescription copied from interface:DataSenderSend the given data to the queue.- Specified by:
sendDatain interfaceDataSender- Parameters:
data- the data that should be sent- Throws:
IOException- if an exception occurs during the communication with the queue
-
sendData
protected void sendData(byte[] data, com.rabbitmq.client.AMQP.BasicProperties.Builder probBuilder) throws IOException- Throws:
IOException
-
sendData
protected void sendData(com.rabbitmq.client.AMQP.BasicProperties properties, byte[] data) throws IOException- Throws:
IOException
-
closeWhenFinished
public void closeWhenFinished()
Description copied from interface:DataSenderA blocking method that closes the sender when its work is done, i.e., all messages have been consumed by receivers from the queue.- Specified by:
closeWhenFinishedin interfaceDataSender
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
builder
public static DataSenderImpl.Builder builder()
Returns a newly createdDataSenderImpl.Builder.- Returns:
- a new
DataSenderImpl.Builderinstance
-
-