Top Description Fields Constructors Methods
com.jogamp.common.util

public Class SyncedRingbuffer<T>

extends Object
implements Ringbuffer<T>
Class Inheritance
All Implemented Interfaces
com.jogamp.common.util.Ringbuffer
Imports
java.io.PrintStream, java.lang.reflect.Array

Simple synchronized implementation of Ringbuffer.

All methods utilize global synchronization.

Characteristics:

EmptywritePos == readPossize == 0
FullwritePos == readPossize == capacity

Field Summary

Modifier and TypeField and Description
private T[]
private int
private int
private int
private final Object
private int

Constructor Summary

AccessConstructor and Description
public
SyncedRingbuffer(final T[]
mandatory source array determining ring buffer's net capacity() and initial content.
copyFrom
)

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 capacity.

Method Summary

Modifier and TypeMethod and Description
public final int
capacity()

Implements com.jogamp.common.util.Ringbuffer.capacity.

Returns the net capacity of this ring buffer.
public final void
clear()

Implements com.jogamp.common.util.Ringbuffer.clear.

Resets the read and write position according to an empty ring buffer and set all ring buffer slots to null.
public final void
dump(final PrintStream stream, final String prefix)

Implements com.jogamp.common.util.Ringbuffer.dump.

Debug functionality - Dumps the contents of the internal array.
public final T
get()

Implements com.jogamp.common.util.Ringbuffer.get.

Dequeues the oldest enqueued element if available, otherwise null.
public final T
getBlocking()

Implements com.jogamp.common.util.Ringbuffer.getBlocking.

Dequeues the oldest enqueued element.
public final int
getFreeSlots()

Implements com.jogamp.common.util.Ringbuffer.getFreeSlots.

Returns the number of free slots available to put.
private final T
getImpl(final boolean blocking, final boolean peek)

public final void
growEmptyBuffer(final T[]
array of new full elements the empty buffer shall grow about.
newElements
)

Implements com.jogamp.common.util.Ringbuffer.growEmptyBuffer.

Grows an empty ring buffer, increasing it's capacity about the amount.
public final void
growFullBuffer(final int
the amount of elements the buffer shall grow about
growAmount
)

Implements com.jogamp.common.util.Ringbuffer.growFullBuffer.

Grows a full ring buffer, increasing it's capacity about the amount.
public final boolean
isEmpty()

Implements com.jogamp.common.util.Ringbuffer.isEmpty.

Returns true if this ring buffer is empty, otherwise false.
public final boolean
isFull()

Implements com.jogamp.common.util.Ringbuffer.isFull.

Returns true if this ring buffer is full, otherwise false.
private static <T> T[]
newArray(final Class<? extends T[]> arrayType, final int length)

public final T
peek()

Implements com.jogamp.common.util.Ringbuffer.peek.

Peeks the next element at the read position w/o modifying pointer, nor blocking.
public final T
peekBlocking()

Implements com.jogamp.common.util.Ringbuffer.peekBlocking.

Peeks the next element at the read position w/o modifying pointer, but w/ blocking.
public final boolean
put(final T e)

Implements com.jogamp.common.util.Ringbuffer.put.

Enqueues the given element.
public final void
putBlocking(final T e)

Implements com.jogamp.common.util.Ringbuffer.putBlocking.

Enqueues the given element.
private final boolean
putImpl(final T e, final boolean sameRef, final boolean blocking)

public final boolean
putSame(final boolean
if true, wait until a free slot becomes available via get.
blocking
)

Implements com.jogamp.common.util.Ringbuffer.putSame.

Enqueues the same element at it's write position, if not full.
public final void
resetFull(final T[]
Mandatory array w/ length capacity() to be copied into the internal array.
copyFrom
)

Implements com.jogamp.common.util.Ringbuffer.resetFull.

Resets the read and write position according to a full ring buffer and fill all slots w/ elements of array copyFrom.
private final void
resetImpl(final boolean full, final T[] copyFrom)

public final int
size()

Implements com.jogamp.common.util.Ringbuffer.size.

Returns the number of elements in this ring buffer.
public final String
toString()

Overrides java.lang.Object.toString.

Implements com.jogamp.common.util.Ringbuffer.toString.

Returns a short string representation incl.
public final void
waitForFreeSlots(final int count)

Implements com.jogamp.common.util.Ringbuffer.waitForFreeSlots.

Blocks until at least count free slots become available.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

arrayback to summary
private T[] array
capacityback to summary
private int capacity
readPosback to summary
private int readPos
sizeback to summary
private int size
syncGlobalback to summary
private final Object syncGlobal
writePosback to summary
private int writePos

Constructor Detail

SyncedRingbufferback 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 rb = new SyncedRingbuffer(source);

isFull() returns true on the newly created full ring buffer.

Implementation will allocate an internal array with size of array copyFrom and copy all elements from array copyFrom into the internal array.

Parameters
copyFrom:T[]

mandatory source array determining ring buffer's net capacity() and initial content.

Annotations
@SuppressWarnings:unchecked
Exceptions
IllegalArgumentException:
if copyFrom is null
SyncedRingbufferback to summary
public SyncedRingbuffer(final Class<? extends T[]> arrayType, final int capacity)

Create an empty ring buffer instance w/ the given net capacity.

Example for a 10 element Integer array:

 Ringbuffer rb = new SyncedRingbuffer(10, Integer[].class);

isEmpty() returns true on the newly created empty ring buffer.

Implementation will allocate an internal array of size capacity.

Parameters
arrayType:Class<? extends T[]>

the array type of the created empty internal array.

capacity:int

the initial net capacity of the ring buffer

Method Detail

capacityback to summary
public final int capacity()

Implements com.jogamp.common.util.Ringbuffer.capacity.

Doc from com.jogamp.common.util.Ringbuffer.capacity.

Returns the net capacity of this ring buffer.

Annotations
@Override
clearback to summary
public final void clear()

Implements com.jogamp.common.util.Ringbuffer.clear.

Doc from com.jogamp.common.util.Ringbuffer.clear.

Resets the read and write position according to an empty ring buffer and set all ring buffer slots to null.

isEmpty() will return true after calling this method.

Implementation sets read and write position to zero.

Annotations
@Override
dumpback to summary
public final void dump(final PrintStream stream, final String prefix)

Implements com.jogamp.common.util.Ringbuffer.dump.

Doc from com.jogamp.common.util.Ringbuffer.dump.

Debug functionality - Dumps the contents of the internal array.

Annotations
@Override
getback to summary
public final T get()

Implements com.jogamp.common.util.Ringbuffer.get.

Doc from com.jogamp.common.util.Ringbuffer.get.

Dequeues the oldest enqueued element if available, otherwise null.

The returned ring buffer slot will be set to null to release the reference and move ownership to the caller.

Method is non blocking and returns immediately;.

Implementation returns the element at the current read position and advances it, if not empty.

Returns:T

the oldest put element if available, otherwise null.

Annotations
@Override
getBlockingback to summary
public final T getBlocking() throws InterruptedException

Implements com.jogamp.common.util.Ringbuffer.getBlocking.

Doc from com.jogamp.common.util.Ringbuffer.getBlocking.

Dequeues the oldest enqueued element.

The returned ring buffer slot will be set to null to release the reference and move ownership to the caller.

Methods blocks until an element becomes available via put.

Implementation returns the element at the current read position and advances it, if not empty.

Returns:T

the oldest put element

Annotations
@Override
getFreeSlotsback to summary
public final int getFreeSlots()

Implements com.jogamp.common.util.Ringbuffer.getFreeSlots.

Doc from com.jogamp.common.util.Ringbuffer.getFreeSlots.

Returns the number of free slots available to put.

Annotations
@Override
getImplback to summary
private final T getImpl(final boolean blocking, final boolean peek) throws InterruptedException
growEmptyBufferback to summary
public final void growEmptyBuffer(final T[] newElements) throws IllegalStateException, IllegalArgumentException

Implements com.jogamp.common.util.Ringbuffer.growEmptyBuffer.

Doc from com.jogamp.common.util.Ringbuffer.growEmptyBuffer.

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 get() etc.

Parameters
newElements:T[]

array of new full elements the empty buffer shall grow about.

Annotations
@Override
Exceptions
IllegalStateException:
if buffer is not empty
IllegalArgumentException:
if newElements is null
growFullBufferback to summary
public final void growFullBuffer(final int growAmount) throws IllegalStateException, IllegalArgumentException

Implements com.jogamp.common.util.Ringbuffer.growFullBuffer.

Doc from com.jogamp.common.util.Ringbuffer.growFullBuffer.

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 null elements are inserted at the write position, able to be written to via put(Object) etc.

Parameters
growAmount:int

the amount of elements the buffer shall grow about

Annotations
@Override
Exceptions
IllegalStateException:
if buffer is not full
IllegalArgumentException:
if amount is < 0
isEmptyback to summary
public final boolean isEmpty()

Implements com.jogamp.common.util.Ringbuffer.isEmpty.

Doc from com.jogamp.common.util.Ringbuffer.isEmpty.

Returns true if this ring buffer is empty, otherwise false.

Annotations
@Override
isFullback to summary
public final boolean isFull()

Implements com.jogamp.common.util.Ringbuffer.isFull.

Doc from com.jogamp.common.util.Ringbuffer.isFull.

Returns true if this ring buffer is full, otherwise false.

Annotations
@Override
newArrayback to summary
private static <T> T[] newArray(final Class<? extends T[]> arrayType, final int length)
Annotations
@SuppressWarnings:unchecked
peekback to summary
public final T peek()

Implements com.jogamp.common.util.Ringbuffer.peek.

Doc from com.jogamp.common.util.Ringbuffer.peek.

Peeks the next element at the read position w/o modifying pointer, nor blocking.

Returns:T

null if empty, otherwise the element which would be read next.

Annotations
@Override
peekBlockingback to summary
public final T peekBlocking() throws InterruptedException

Implements com.jogamp.common.util.Ringbuffer.peekBlocking.

Doc from com.jogamp.common.util.Ringbuffer.peekBlocking.

Peeks the next element at the read position w/o modifying pointer, but w/ blocking.

Returns:T

null if empty, otherwise the element which would be read next.

Annotations
@Override
putback to summary
public final boolean put(final T e)

Implements com.jogamp.common.util.Ringbuffer.put.

Doc from com.jogamp.common.util.Ringbuffer.put.

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.

Annotations
@Override
putBlockingback to summary
public final void putBlocking(final T e) throws InterruptedException

Implements com.jogamp.common.util.Ringbuffer.putBlocking.

Doc from com.jogamp.common.util.Ringbuffer.putBlocking.

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.

Annotations
@Override
putImplback to summary
private final boolean putImpl(final T e, final boolean sameRef, final boolean blocking) throws InterruptedException
putSameback to summary
public final boolean putSame(final boolean blocking) throws InterruptedException

Implements com.jogamp.common.util.Ringbuffer.putSame.

Doc from com.jogamp.common.util.Ringbuffer.putSame.

Enqueues the same element at it's write position, if not full.

Returns true if successful, otherwise false in case buffer is full.

If blocking is true, method blocks until a free slot becomes available via get.

Implementation keeps the element at the current write position and advances it, if not full.

Parameters
blocking:boolean

if true, wait until a free slot becomes available via get.

Annotations
@Override
resetFullback to summary
public final void resetFull(final T[] copyFrom) throws IllegalArgumentException

Implements com.jogamp.common.util.Ringbuffer.resetFull.

Doc from com.jogamp.common.util.Ringbuffer.resetFull.

Resets the read and write position according to a full ring buffer and fill all slots w/ elements of array copyFrom.

Array's copyFrom elements will be copied into the internal array, hence it's length must be equal to capacity().

Parameters
copyFrom:T[]

Mandatory array w/ length capacity() to be copied into the internal array.

Annotations
@Override
Exceptions
IllegalArgumentException:
  • if copyFrom is null.
  • if copyFrom's length is different from capacity().
resetImplback to summary
private final void resetImpl(final boolean full, final T[] copyFrom) throws IllegalArgumentException
sizeback to summary
public final int size()

Implements com.jogamp.common.util.Ringbuffer.size.

Doc from com.jogamp.common.util.Ringbuffer.size.

Returns the number of elements in this ring buffer.

Annotations
@Override
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Implements com.jogamp.common.util.Ringbuffer.toString.

Doc from com.jogamp.common.util.Ringbuffer.toString.

Returns a short string representation incl. size/capacity and internal r/w index (impl. dependent).

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
waitForFreeSlotsback to summary
public final void waitForFreeSlots(final int count) throws InterruptedException

Implements com.jogamp.common.util.Ringbuffer.waitForFreeSlots.

Doc from com.jogamp.common.util.Ringbuffer.waitForFreeSlots.

Blocks until at least count free slots become available.

Annotations
@Override