Package org.agrona.concurrent.broadcast
Class BroadcastTransmitter
- java.lang.Object
-
- org.agrona.concurrent.broadcast.BroadcastTransmitter
-
public class BroadcastTransmitter extends java.lang.Object
Transmit messages via an underlying broadcast buffer to zero or moreBroadcastReceiver
s.Note: This class is not threadsafe. Only one transmitter is allowed per broadcast buffer.
-
-
Field Summary
Fields Modifier and Type Field Description private AtomicBuffer
buffer
private int
capacity
private int
latestCounterIndex
private int
maxMsgLength
private int
tailCounterIndex
private int
tailIntentCountIndex
-
Constructor Summary
Constructors Constructor Description BroadcastTransmitter(AtomicBuffer buffer)
Construct a new broadcast transmitter based on an underlyingAtomicBuffer
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
capacity()
Get the capacity of the underlying broadcast buffer.private void
checkMessageLength(int length)
private static void
insertPaddingRecord(AtomicBuffer buffer, int recordOffset, int length)
int
maxMsgLength()
Get the maximum message length that can be transmitted for a buffer.private void
signalTailIntent(AtomicBuffer buffer, long newTail)
void
transmit(int msgTypeId, DirectBuffer srcBuffer, int srcIndex, int length)
Transmit a message toBroadcastReceiver
s via the broadcast buffer.
-
-
-
Field Detail
-
buffer
private final AtomicBuffer 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 Detail
-
BroadcastTransmitter
public BroadcastTransmitter(AtomicBuffer buffer)
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:
java.lang.IllegalStateException
- if the buffer capacity is not a power of 2 plusBroadcastBufferDescriptor.TRAILER_LENGTH
in capacity.
-
-
Method Detail
-
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
public void transmit(int msgTypeId, DirectBuffer srcBuffer, int srcIndex, int length)
Transmit a message toBroadcastReceiver
s 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:
java.lang.IllegalArgumentException
- of the msgTypeId is not valid, or if the message length is greater thanmaxMsgLength()
.
-
signalTailIntent
private void signalTailIntent(AtomicBuffer buffer, long newTail)
-
insertPaddingRecord
private static void insertPaddingRecord(AtomicBuffer buffer, int recordOffset, int length)
-
checkMessageLength
private void checkMessageLength(int length)
-
-