Ringbuffer.
All methods utilize global synchronization.
Characteristics:
| Empty | writePos == readPos | size == 0 |
| Full | writePos == readPos | size == capacity |
| Modifier and Type | Field and Description |
|---|---|
| private T[] | |
| private int | |
| private int | |
| private int | |
| private final Object | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | SyncedRingbuffer(final T[]
mandatory source array determining ring buffer's net copyFrom)capacity() and initial content.Create a full ring buffer instance w/ the given array's net capacity and content. |
| public | SyncedRingbuffer(final Class<? extends T[]>
the array type of the created empty internal array. arrayType, final int the initial net capacity of the ring buffer capacity)Create an empty ring buffer instance w/ the given net |
| Modifier and Type | Method and Description |
|---|---|
| public final int | capacity()
Implements com. |
| public final void | clear()
Implements com. null.
|
| public final void | dump(final PrintStream stream, final String prefix)
Implements com. |
| public final T | get()
Implements com. |
| public final T | getBlocking()
Implements com. |
| public final int | getFreeSlots()
Implements com. |
| private final T | |
| public final void | growEmptyBuffer(final T[]
array of new full elements the empty buffer shall grow about. newElements)Implements com. |
| public final void | growFullBuffer(final int
the amount of elements the buffer shall grow about growAmount)Implements com. |
| public final boolean | isEmpty()
Implements com. |
| public final boolean | isFull()
Implements com. |
| private static <T> T[] | |
| public final T | peek()
Implements com. |
| public final T | peekBlocking()
Implements com. |
| public final boolean | |
| public final void | putBlocking(final T e)
Implements com. |
| private final boolean | |
| public final boolean | putSame(final boolean
if true, wait until a free slot becomes available via get. blocking)Implements com. |
| public final void | resetFull(final T[]
Mandatory array w/ length copyFrom)capacity() to be copied into the internal array.Implements com. copyFrom.
|
| private final void | |
| public final int | size()
Implements com. |
| public final String | toString()
Overrides java. Implements com. |
| public final void | waitForFreeSlots(final int count)
Implements com. count free slots become available.
|
| array | back to summary |
|---|---|
| private T[] array | |
| capacity | back to summary |
|---|---|
| private int capacity | |
| readPos | back to summary |
|---|---|
| private int readPos | |
| size | back to summary |
|---|---|
| private int size | |
| syncGlobal | back to summary |
|---|---|
| private final Object syncGlobal | |
| writePos | back to summary |
|---|---|
| private int writePos | |
| SyncedRingbuffer | back to summary |
|---|---|
| public SyncedRingbuffer(final T[] copyFrom) throws IllegalArgumentException Create a full ring buffer instance w/ the given array's net capacity and content. Example for a 10 element Integer array: Integer[] source = new Integer[10]; // fill source with content .. Ringbuffer
Implementation will allocate an internal array with size of array
| |
| SyncedRingbuffer | back to summary |
|---|---|
| public SyncedRingbuffer(final Class<? extends T[]> arrayType, final int capacity) Create an empty ring buffer instance w/ the given net Example for a 10 element Integer array: Ringbuffer
Implementation will allocate an internal array of size
| |
| capacity | back to summary |
|---|---|
| public final int capacity() Implements com. Doc from com. Returns the net capacity of this ring buffer.
| |
| clear | back to summary |
|---|---|
| public final void clear() Implements com. Doc from com. Resets the read and write position according to an empty ring buffer
and set all ring buffer slots to
Implementation sets read and write position to zero.
| |
| dump | back to summary |
|---|---|
| public final void dump(final PrintStream stream, final String prefix) Implements com. Doc from com. Debug functionality - Dumps the contents of the internal array.
| |
| get | back to summary |
|---|---|
| public final T get() Implements com. Doc from com. Dequeues the oldest enqueued element if available, otherwise null.
The returned ring buffer slot will be set to Method is non blocking and returns immediately;. Implementation returns the element at the current read position and advances it, if not empty.
| |
| getBlocking | back to summary |
|---|---|
| public final T getBlocking() throws InterruptedException Implements com. Doc from com. Dequeues the oldest enqueued element.
The returned ring buffer slot will be set to Methods blocks until an element becomes available via put. Implementation returns the element at the current read position and advances it, if not empty.
| |
| getFreeSlots | back to summary |
|---|---|
| public final int getFreeSlots() Implements com. Doc from com. Returns the number of free slots available to put.
| |
| getImpl | back to summary |
|---|---|
| private final T getImpl(final boolean blocking, final boolean peek) throws InterruptedException | |
| growEmptyBuffer | back to summary |
|---|---|
| public final void growEmptyBuffer(final T[] newElements) throws IllegalStateException, IllegalArgumentException Implements com. Doc from com. Grows an empty ring buffer, increasing it's capacity about the amount.
Growing an empty ring buffer increases it's size about the amount, i.e. renders it not empty.
The new elements are inserted at the read position, able to be read out via
| |
| growFullBuffer | back to summary |
|---|---|
| public final void growFullBuffer(final int growAmount) throws IllegalStateException, IllegalArgumentException Implements com. Doc from com. Grows a full ring buffer, increasing it's capacity about the amount.
Growing a full ring buffer leaves the size intact, i.e. renders it not full.
New
| |
| isEmpty | back to summary |
|---|---|
| public final boolean isEmpty() Implements com. Doc from com. Returns true if this ring buffer is empty, otherwise false.
| |
| isFull | back to summary |
|---|---|
| public final boolean isFull() Implements com. Doc from com. Returns true if this ring buffer is full, otherwise false.
| |
| newArray | back to summary |
|---|---|
private static <T> T[] newArray(final Class<? extends T[]> arrayType, final int length)
| |
| peek | back to summary |
|---|---|
| public final T peek() Implements com. Doc from com. Peeks the next element at the read position w/o modifying pointer, nor blocking.
| |
| peekBlocking | back to summary |
|---|---|
| public final T peekBlocking() throws InterruptedException Implements com. Doc from com. Peeks the next element at the read position w/o modifying pointer, but w/ blocking.
| |
| put | back to summary |
|---|---|
| public final boolean put(final T e) Implements com. Doc from com. Enqueues the given element. Returns true if successful, otherwise false in case buffer is full. Method is non blocking and returns immediately;. Implementation stores the element at the current write position and advances it, if not full.
| |
| putBlocking | back to summary |
|---|---|
| public final void putBlocking(final T e) throws InterruptedException Implements com. Doc from com. Enqueues the given element. Method blocks until a free slot becomes available via get. Implementation stores the element at the current write position and advances it, if not full.
| |
| putImpl | back to summary |
|---|---|
| private final boolean putImpl(final T e, final boolean sameRef, final boolean blocking) throws InterruptedException | |
| putSame | back to summary |
|---|---|
| public final boolean putSame(final boolean blocking) throws InterruptedException Implements com. Doc from com. Enqueues the same element at it's write position, if not full. Returns true if successful, otherwise false in case buffer is full.
If Implementation keeps the element at the current write position and advances it, if not full.
| |
| resetFull | back to summary |
|---|---|
| public final void resetFull(final T[] copyFrom) throws IllegalArgumentException Implements com. Doc from com. Resets the read and write position according to a full ring buffer
and fill all slots w/ elements of array
Array's
| |
| resetImpl | back to summary |
|---|---|
| private final void resetImpl(final boolean full, final T[] copyFrom) throws IllegalArgumentException | |
| size | back to summary |
|---|---|
| public final int size() Implements com. Doc from com. Returns the number of elements in this ring buffer.
| |
| toString | back to summary |
|---|---|
| public final String toString() Overrides java. Implements com. Doc from com. Returns a short string representation incl. size/capacity and internal r/w index (impl. dependent).
| |
| waitForFreeSlots | back to summary |
|---|---|
| public final void waitForFreeSlots(final int count) throws InterruptedException Implements com. Doc from com. Blocks until at least
| |