public class ExpandableRingBuffer extends Object
maxCapacity()
. Messages can be iterated via for-each methods
without consuming and having the option to begin iteration an offset from the current head()
position.
Note: This class is not thread safe.
Modifier and Type | Class and Description |
---|---|
static interface |
ExpandableRingBuffer.MessageConsumer
Consumers of messages implement this interface and pass it to
consume(MessageConsumer, int) . |
Modifier and Type | Field and Description |
---|---|
static int |
HEADER_ALIGNMENT
Alignment in bytes for the beginning of message header.
|
static int |
HEADER_LENGTH
Length of encapsulating header.
|
static int |
MAX_CAPACITY
Maximum capacity to which the ring buffer can grow which is 1GB.
|
Constructor and Description |
---|
ExpandableRingBuffer()
Create a new ring buffer which is initially compact and empty, has potential for
MAX_CAPACITY ,
and using a direct ByteBuffer . |
ExpandableRingBuffer(int initialCapacity,
int maxCapacity,
boolean isDirect)
Create a new ring buffer providing configuration for initial and max capacity, plus whether it is direct or not.
|
Modifier and Type | Method and Description |
---|---|
boolean |
append(DirectBuffer srcBuffer,
int srcOffset,
int srcLength)
Append a message into the ring buffer, expanding the buffer if required.
|
int |
capacity()
Current capacity of the ring buffer in bytes.
|
int |
consume(ExpandableRingBuffer.MessageConsumer messageConsumer,
int messageLimit)
Consume messages up to a limit and pass them to the
ExpandableRingBuffer.MessageConsumer . |
int |
forEach(ExpandableRingBuffer.MessageConsumer messageConsumer,
int limit)
Iterate encoded contents and pass messages to the
ExpandableRingBuffer.MessageConsumer which can stop by returning false. |
int |
forEach(int headOffset,
ExpandableRingBuffer.MessageConsumer messageConsumer,
int limit)
Iterate encoded contents and pass messages to the
ExpandableRingBuffer.MessageConsumer which can stop by returning false. |
long |
head()
Head position in the buffer from which bytes are consumed forward toward the
tail() . |
boolean |
isDirect()
Is the
ByteBuffer used for backing storage direct, that is off Java heap, or not. |
boolean |
isEmpty()
Is the ring buffer currently empty.
|
int |
maxCapacity()
The maximum capacity to which the buffer can expand.
|
void |
reset(int requiredCapacity)
Reset the buffer with a new capacity and empty state.
|
int |
size()
Size of the ring buffer currently populated in bytes.
|
long |
tail()
Tail position in the buffer at which new bytes are appended.
|
public static final int MAX_CAPACITY
public static final int HEADER_ALIGNMENT
public static final int HEADER_LENGTH
public ExpandableRingBuffer()
MAX_CAPACITY
,
and using a direct ByteBuffer
.public ExpandableRingBuffer(int initialCapacity, int maxCapacity, boolean isDirect)
initialCapacity
- required in the buffer.maxCapacity
- the the buffer can expand to.isDirect
- is the ByteBuffer
allocated direct or heap based.public boolean isDirect()
ByteBuffer
used for backing storage direct, that is off Java heap, or not.ByteBuffer
or false for heap based ByteBuffer
.public int maxCapacity()
public int capacity()
public int size()
public boolean isEmpty()
public long head()
tail()
.tail()
.consume(MessageConsumer, int)
public long tail()
append(DirectBuffer, int, int)
public void reset(int requiredCapacity)
requiredCapacity
- for the ring buffer. If the same as exiting capacity then no adjustment is made.public int forEach(ExpandableRingBuffer.MessageConsumer messageConsumer, int limit)
ExpandableRingBuffer.MessageConsumer
which can stop by returning false.messageConsumer
- to which the encoded messages are passed.limit
- for the number of entries to iterate over.ExpandableRingBuffer.MessageConsumer
public int forEach(int headOffset, ExpandableRingBuffer.MessageConsumer messageConsumer, int limit)
ExpandableRingBuffer.MessageConsumer
which can stop by returning false.headOffset
- offset from head
which must be <= tail()
, and be the start a message.messageConsumer
- to which the encoded messages are passed.limit
- for the number of entries to iterate over.ExpandableRingBuffer.MessageConsumer
public int consume(ExpandableRingBuffer.MessageConsumer messageConsumer, int messageLimit)
ExpandableRingBuffer.MessageConsumer
.messageConsumer
- to which the encoded messages are passed.messageLimit
- on the number of messages to consume per read operation.ExpandableRingBuffer.MessageConsumer
public boolean append(DirectBuffer srcBuffer, int srcOffset, int srcLength)
srcBuffer
- containing the encoded message.srcOffset
- within the buffer at which the message begins.srcLength
- of the encoded message in the buffer.maxCapacity()
is reached.Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.