Package akka.stream.impl
Class ResizableMultiReaderRingBuffer<T>
- java.lang.Object
-
- akka.stream.impl.ResizableMultiReaderRingBuffer<T>
-
public class ResizableMultiReaderRingBuffer<T> extends java.lang.Object
INTERNAL API A mutable RingBuffer that can grow in size and supports multiple readers. Contrary to many other ring buffer implementations this one does not automatically overwrite the oldest elements, rather, if full, the buffer tries to grow and rejects further writes if max capacity is reached.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ResizableMultiReaderRingBuffer.Cursor
static interface
ResizableMultiReaderRingBuffer.Cursors
static class
ResizableMultiReaderRingBuffer.NothingToReadException$
-
Constructor Summary
Constructors Constructor Description ResizableMultiReaderRingBuffer(int initialSize, int maxSize, ResizableMultiReaderRingBuffer.Cursors cursors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
count(ResizableMultiReaderRingBuffer.Cursor cursor)
Returns the number of elements that the buffer currently contains for the given cursor.ResizableMultiReaderRingBuffer.Cursors
cursors()
int
immediatelyAvailable()
The number of elements the buffer can still take without having to be resized.void
initCursor(ResizableMultiReaderRingBuffer.Cursor cursor)
Initializes the given Cursor to the oldest buffer entry that is still available.boolean
isEmpty()
int
maxAvailable()
The maximum number of elements the buffer can still take.boolean
nonEmpty()
void
onCursorRemoved(ResizableMultiReaderRingBuffer.Cursor cursor)
T
read(ResizableMultiReaderRingBuffer.Cursor cursor)
Tries to read from the buffer using the given Cursor.int
size()
The number of elements currently in the buffer.java.lang.String
toString()
protected java.lang.Object[]
underlyingArray()
boolean
write(T value)
Tries to write the given value into the buffer thereby potentially growing the backing array.
-
-
-
Constructor Detail
-
ResizableMultiReaderRingBuffer
public ResizableMultiReaderRingBuffer(int initialSize, int maxSize, ResizableMultiReaderRingBuffer.Cursors cursors)
-
-
Method Detail
-
cursors
public ResizableMultiReaderRingBuffer.Cursors cursors()
-
size
public int size()
The number of elements currently in the buffer.
-
isEmpty
public boolean isEmpty()
-
nonEmpty
public boolean nonEmpty()
-
immediatelyAvailable
public int immediatelyAvailable()
The number of elements the buffer can still take without having to be resized.
-
maxAvailable
public int maxAvailable()
The maximum number of elements the buffer can still take.
-
count
public int count(ResizableMultiReaderRingBuffer.Cursor cursor)
Returns the number of elements that the buffer currently contains for the given cursor.
-
initCursor
public void initCursor(ResizableMultiReaderRingBuffer.Cursor cursor)
Initializes the given Cursor to the oldest buffer entry that is still available.
-
write
public boolean write(T value)
Tries to write the given value into the buffer thereby potentially growing the backing array. Returnstrue
if the write was successful and false if the buffer is full and cannot grow anymore.
-
read
public T read(ResizableMultiReaderRingBuffer.Cursor cursor)
Tries to read from the buffer using the given Cursor. If there are no more data to be read (i.e. the cursor is already at writeIx) the method throws ResizableMultiReaderRingBuffer.NothingToReadException!
-
onCursorRemoved
public void onCursorRemoved(ResizableMultiReaderRingBuffer.Cursor cursor)
-
underlyingArray
protected java.lang.Object[] underlyingArray()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-