Class BroadcastTransmitter
java.lang.Object
org.agrona.concurrent.broadcast.BroadcastTransmitter
Transmit messages via an underlying broadcast buffer to zero or more
BroadcastReceivers.
Note: This class is not threadsafe. Only one transmitter is allowed per broadcast buffer.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBufferprivate final intprivate final intprivate final intprivate final intprivate final int -
Constructor Summary
ConstructorsConstructorDescriptionBroadcastTransmitter(AtomicBuffer buffer) Construct a new broadcast transmitter based on an underlyingAtomicBuffer. -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Get the capacity of the underlying broadcast buffer.private voidcheckMessageLength(int length) private static voidinsertPaddingRecord(AtomicBuffer buffer, int recordOffset, int length) intGet the maximum message length that can be transmitted for a buffer.private voidsignalTailIntent(AtomicBuffer buffer, long newTail) voidtransmit(int msgTypeId, DirectBuffer srcBuffer, int srcIndex, int length) Transmit a message toBroadcastReceivers via the broadcast buffer.
-
Field Details
-
buffer
-
capacity
private final int capacity -
maxMsgLength
private final int maxMsgLength -
tailIntentCountIndex
private final int tailIntentCountIndex -
tailCounterIndex
private final int tailCounterIndex -
latestCounterIndex
private final int latestCounterIndex
-
-
Constructor Details
-
BroadcastTransmitter
Construct a new broadcast transmitter based on an underlyingAtomicBuffer. The underlying buffer must a power of 2 in size plus sufficient space for theBroadcastBufferDescriptor.TRAILER_LENGTH.- Parameters:
buffer- via which messages will be exchanged.- Throws:
IllegalStateException- if the buffer capacity is not a power of 2 plusBroadcastBufferDescriptor.TRAILER_LENGTHin capacity.
-
-
Method Details
-
capacity
public int capacity()Get the capacity of the underlying broadcast buffer.- Returns:
- the capacity of the underlying broadcast buffer.
-
maxMsgLength
public int maxMsgLength()Get the maximum message length that can be transmitted for a buffer.- Returns:
- the maximum message length that can be transmitted for a buffer.
-
transmit
Transmit a message toBroadcastReceivers via the broadcast buffer.- Parameters:
msgTypeId- type of the message to be transmitted.srcBuffer- containing the encoded message to be transmitted.srcIndex- srcIndex in the source buffer at which the encoded message begins.length- in bytes of the encoded message.- Throws:
IllegalArgumentException- of the msgTypeId is not valid, or if the message length is greater thanmaxMsgLength().
-
signalTailIntent
-
insertPaddingRecord
-
checkMessageLength
private void checkMessageLength(int length)
-