public class ManyToOneRingBuffer extends java.lang.Object implements RingBuffer
| Modifier and Type | Field and Description |
|---|---|
static int |
PADDING_MSG_TYPE_ID
Record type is padding to prevent fragmentation in the buffer.
|
| Constructor and Description |
|---|
ManyToOneRingBuffer(AtomicBuffer buffer)
Construct a new
RingBuffer based on an underlying AtomicBuffer. |
| Modifier and Type | Method and Description |
|---|---|
AtomicBuffer |
buffer()
Get the underlying buffer used by the RingBuffer for storage.
|
int |
capacity()
Get the capacity of the ring-buffer in bytes for exchange.
|
long |
consumerHeartbeatTime()
The time of the last consumer heartbeat.
|
void |
consumerHeartbeatTime(long time)
Set the time of the last consumer heartbeat.
|
long |
consumerPosition()
The position in bytes from start up for the consumers.
|
int |
maxMsgLength()
The maximum message length in bytes supported by the underlying ring buffer.
|
long |
nextCorrelationId()
Get the next value that can be used for a correlation id on an message when a response needs to be correlated.
|
long |
producerPosition()
The position in bytes from start up of the producers.
|
int |
read(MessageHandler handler)
Read as many messages as are available to the end of the ring buffer.
|
int |
read(MessageHandler handler,
int messageCountLimit)
Read as many messages as are available to end of the ring buffer to up a supplied maximum.
|
int |
size()
Size of the buffer backlog in bytes between producers and consumers.
|
boolean |
unblock()
Unblock a multi-producer ring buffer when a producer has died during the act of offering.
|
boolean |
write(int msgTypeId,
DirectBuffer srcBuffer,
int srcIndex,
int length)
Non-blocking write of an message to an underlying ring-buffer.
|
public static final int PADDING_MSG_TYPE_ID
public ManyToOneRingBuffer(AtomicBuffer buffer)
RingBuffer based on an underlying AtomicBuffer.
The underlying buffer must a power of 2 in size plus sufficient space
for the RingBufferDescriptor.TRAILER_LENGTH.buffer - via which events will be exchanged.java.lang.IllegalStateException - if the buffer capacity is not a power of 2
plus RingBufferDescriptor.TRAILER_LENGTH in capacity.public int capacity()
capacity in interface RingBufferpublic boolean write(int msgTypeId,
DirectBuffer srcBuffer,
int srcIndex,
int length)
write in interface RingBuffermsgTypeId - type of the message encoding.srcBuffer - containing the encoded binary message.srcIndex - at which the encoded message begins.length - of the encoded message in bytes.public int read(MessageHandler handler)
If the ring buffer wraps or encounters a type of record, such a a padding record, then an implementation
may choose to return and expect the caller to try again. The RingBuffer.size() method may be called to
determine of a backlog of message bytes remains in the ring buffer.
read in interface RingBufferhandler - to be called for processing each message in turn.public int read(MessageHandler handler, int messageCountLimit)
If the ring buffer wraps or encounters a type of record, such a a padding record, then an implementation
may choose to return and expect the caller to try again. The RingBuffer.size() method may be called to
determine of a backlog of message bytes remains in the ring buffer.
read in interface RingBufferhandler - to be called for processing each message in turn.messageCountLimit - the number of messages will be read in a single invocation.public int maxMsgLength()
maxMsgLength in interface RingBufferpublic long nextCorrelationId()
This method should be thread safe.
nextCorrelationId in interface RingBufferpublic AtomicBuffer buffer()
buffer in interface RingBufferpublic void consumerHeartbeatTime(long time)
Note: The value for time must be valid across processes which means System.nanoTime()
is not a valid option.
consumerHeartbeatTime in interface RingBuffertime - of the last consumer heartbeat.public long consumerHeartbeatTime()
consumerHeartbeatTime in interface RingBufferpublic long producerPosition()
producerPosition in interface RingBufferpublic long consumerPosition()
consumerPosition in interface RingBufferpublic int size()
This method gives a concurrent snapshot of the buffer whereby a concurrent read or write may be partially complete and thus the value should be taken as an indication.
size in interface RingBufferpublic boolean unblock()
If no action is required at the position then none will be taken.
unblock in interface RingBufferCopyright © 2014-2019 Real Logic Ltd. All Rights Reserved.