public class SegmentedRingByteBuffer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SegmentedRingByteBuffer.BufferMode
Buffer mode.
|
class |
SegmentedRingByteBuffer.ReadSegment
Segment available for data reading.
|
class |
SegmentedRingByteBuffer.WriteSegment
Segment available for data writing.
|
| Modifier and Type | Field and Description |
|---|---|
ByteBuffer |
buf
Buffer.
|
| Constructor and Description |
|---|
SegmentedRingByteBuffer(int cap,
long maxSegmentSize,
SegmentedRingByteBuffer.BufferMode mode)
Creates ring buffer with given capacity.
|
SegmentedRingByteBuffer(int cap,
long maxSegmentSize,
SegmentedRingByteBuffer.BufferMode mode,
DataStorageMetricsImpl metrics)
Creates ring buffer with given capacity.
|
SegmentedRingByteBuffer(MappedByteBuffer buf,
DataStorageMetricsImpl metrics)
Creates ring buffer with given capacity which mapped to file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the buffer.
|
void |
free()
Frees allocated memory in case of direct byte buffer.
|
void |
init(long pos)
Performs initialization of ring buffer state.
|
SegmentedRingByteBuffer.BufferMode |
mode()
Returns buffer mode.
|
SegmentedRingByteBuffer.WriteSegment |
offer(int size)
Reserves
size bytes in SegmentedRingByteBuffer and returns instance of SegmentedRingByteBuffer.WriteSegment
class that points to wrapped ByteBuffer instance with corresponding capacity. |
SegmentedRingByteBuffer.WriteSegment |
offerSafe(int size)
Behaves like
offer(int) but in safe manner: there are no any concurrent threads and buffer in
closed state. |
List<SegmentedRingByteBuffer.ReadSegment> |
poll()
Retrieves list of
SegmentedRingByteBuffer.ReadSegment instances that point to ByteBuffer that contains all data available
for reading from SegmentedRingByteBuffer or null if there are no available data for reading. |
List<SegmentedRingByteBuffer.ReadSegment> |
poll(long pos)
Retrieves list of
SegmentedRingByteBuffer.ReadSegment instances that point to ByteBuffer that contains data
available for reading from SegmentedRingByteBuffer limited by pos parameter or null
if there are no available data for reading. |
SegmentedRingByteBuffer |
reset()
Resets the state of the buffer and returns new instance but with the same underlying buffer.
|
long |
tail()
Returns actual buffer tail.
|
public final ByteBuffer buf
public SegmentedRingByteBuffer(int cap,
long maxSegmentSize,
SegmentedRingByteBuffer.BufferMode mode)
cap - Buffer's capacity.maxSegmentSize - Max segment size.mode - Buffer mode.public SegmentedRingByteBuffer(int cap,
long maxSegmentSize,
SegmentedRingByteBuffer.BufferMode mode,
DataStorageMetricsImpl metrics)
cap - Buffer's capacity.maxSegmentSize - Max segment size.mode - Buffer mode.metrics - Metrics.public SegmentedRingByteBuffer(MappedByteBuffer buf, DataStorageMetricsImpl metrics)
buf - MappedByteBuffer instance.metrics - Metrics.public void init(long pos)
pos - Position.public SegmentedRingByteBuffer.BufferMode mode()
public long tail()
public SegmentedRingByteBuffer.WriteSegment offer(int size)
size bytes in SegmentedRingByteBuffer and returns instance of SegmentedRingByteBuffer.WriteSegment
class that points to wrapped ByteBuffer instance with corresponding capacity. This ByteBuffer
instance should be used only for data writing to SegmentedRingByteBuffer.
Returned result can be null in case of requested amount of bytes greater then available space
in SegmentedRingByteBuffer. Also SegmentedRingByteBuffer.WriteSegment.buffer() can return null in case of
maxSegmentSize value is exceeded. In this case buffer will be closed in order to prevent any
concurrent threads from trying of reserve new segment.
This method can be invoked by many producer threads and each producer will get own ByteBuffer instance
that mapped to own SegmentedRingByteBuffer slice.
Once the data has been written into the ByteBuffer client code must notify
SegmentedRingByteBuffer instance using SegmentedRingByteBuffer.WriteSegment.release() method in order to provide
possibility to consumer get data for reading.
size - Amount of bytes for reserve.SegmentedRingByteBuffer.WriteSegment instance that point to ByteBuffer instance with given size.
null if buffer space is not enough.public SegmentedRingByteBuffer.WriteSegment offerSafe(int size)
offer(int) but in safe manner: there are no any concurrent threads and buffer in
closed state.size - Amount of bytes for reserve.SegmentedRingByteBuffer.WriteSegment instance that point to ByteBuffer instance with given size.
null if buffer space is not enough.public void close()
public List<SegmentedRingByteBuffer.ReadSegment> poll()
SegmentedRingByteBuffer.ReadSegment instances that point to ByteBuffer that contains all data available
for reading from SegmentedRingByteBuffer or null if there are no available data for reading.
This method can be invoked only by one consumer thread.
Once the data has been read from the returned SegmentedRingByteBuffer.ReadSegment client code must notify
SegmentedRingByteBuffer instance using SegmentedRingByteBuffer.ReadSegment.release() method in order to release occupied
space in the SegmentedRingByteBuffer and make it available for writing.
ReadSegment instances with all available data for reading or null if
there are no available data.public List<SegmentedRingByteBuffer.ReadSegment> poll(long pos)
SegmentedRingByteBuffer.ReadSegment instances that point to ByteBuffer that contains data
available for reading from SegmentedRingByteBuffer limited by pos parameter or null
if there are no available data for reading.
This method can be invoked only by one consumer thread.
Once the data has been read from the returned SegmentedRingByteBuffer.ReadSegment client code must notify
SegmentedRingByteBuffer instance using SegmentedRingByteBuffer.ReadSegment.release() method in order to release occupied
space in the SegmentedRingByteBuffer and make it available for writing.
pos - End position in buffer.ReadSegment instances with all available data for reading or null if
there are no available data.public void free()
public SegmentedRingByteBuffer reset()
Follow @ApacheIgnite
Ignite Fabric : ver. 2.6.0 Release Date : July 10 2018