public class OneToOneRingBuffer extends java.lang.Object implements RingBuffer
This single producer ring-buffer can be used in combination a consumer using the ManyToOneRingBuffer
provided no other producers are accessing the same ring-buffer.
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 |
---|
OneToOneRingBuffer(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 OneToOneRingBuffer(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 RingBuffer
public boolean write(int msgTypeId, DirectBuffer srcBuffer, int srcIndex, int length)
write
in interface RingBuffer
msgTypeId
- 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 RingBuffer
handler
- 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 RingBuffer
handler
- 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 RingBuffer
public long nextCorrelationId()
This method should be thread safe.
nextCorrelationId
in interface RingBuffer
public AtomicBuffer buffer()
buffer
in interface RingBuffer
public 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 RingBuffer
time
- of the last consumer heartbeat.public long consumerHeartbeatTime()
consumerHeartbeatTime
in interface RingBuffer
public long producerPosition()
producerPosition
in interface RingBuffer
public long consumerPosition()
consumerPosition
in interface RingBuffer
public 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 RingBuffer
public boolean unblock()
If no action is required at the position then none will be taken.
unblock
in interface RingBuffer
Copyright © 2014-2017 Real Logic Ltd. All Rights Reserved.