GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
com.jogamp.common.util.SyncedRingbuffer< T > Class Template Reference

Simple synchronized implementation of Ringbuffer. More...

Inheritance diagram for com.jogamp.common.util.SyncedRingbuffer< T >:
Collaboration diagram for com.jogamp.common.util.SyncedRingbuffer< T >:

Public Member Functions

final String toString ()
 Returns a short string representation incl. More...
 
final void dump (final PrintStream stream, final String prefix)
 Debug functionality - Dumps the contents of the internal array. More...
 
 SyncedRingbuffer (final T[] copyFrom) throws IllegalArgumentException
 Create a full ring buffer instance w/ the given array's net capacity and content. More...
 
 SyncedRingbuffer (final Class<? extends T[]> arrayType, final int capacity)
 Create an empty ring buffer instance w/ the given net capacity. More...
 
final int capacity ()
 Returns the net capacity of this ring buffer. More...
 
final void 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. More...
 
final void resetFull (final T[] copyFrom) throws IllegalArgumentException
 Resets the read and write position according to a full ring buffer and fill all slots w/ elements of array copyFrom. More...
 
final int size ()
 Returns the number of elements in this ring buffer. More...
 
final int getFreeSlots ()
 Returns the number of free slots available to put. More...
 
final boolean isEmpty ()
 Returns true if this ring buffer is empty, otherwise false. More...
 
final boolean isFull ()
 Returns true if this ring buffer is full, otherwise false. More...
 
final T 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;.
Returns
the oldest put element if available, otherwise null.
More...
 
final T getBlocking () throws InterruptedException
 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.
Returns
the oldest put element
Exceptions
InterruptedException
More...
 
final T peek ()
 Peeks the next element at the read position w/o modifying pointer, nor blocking. More...
 
final T peekBlocking () throws InterruptedException
 Peeks the next element at the read position w/o modifying pointer, but w/ blocking. More...
 
final boolean put (final T e)
 Enqueues the given element.Returns true if successful, otherwise false in case buffer is full. Method is non blocking and returns immediately;. More...
 
final void putBlocking (final T e) throws InterruptedException
 Enqueues the given element.Method blocks until a free slot becomes available via get.
Exceptions
InterruptedException
More...
 
final boolean putSame (final boolean blocking) throws InterruptedException
 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.
Parameters
blockingif true, wait until a free slot becomes available via get.
Exceptions
InterruptedException
More...
 
final void waitForFreeSlots (final int count) throws InterruptedException
 Blocks until at least count free slots become available. More...
 
final void growEmptyBuffer (final T[] newElements) throws IllegalStateException, IllegalArgumentException
 Grows an empty ring buffer, increasing it's capacity about the amount. More...
 
final void growFullBuffer (final int growAmount) throws IllegalStateException, IllegalArgumentException
 Grows a full ring buffer, increasing it's capacity about the amount. More...
 
String toString ()
 Returns a short string representation incl. More...
 
void dump (PrintStream stream, String prefix)
 Debug functionality - Dumps the contents of the internal array. More...
 
int capacity ()
 Returns the net capacity of this ring buffer. More...
 
void clear ()
 Resets the read and write position according to an empty ring buffer and set all ring buffer slots to null. More...
 
void resetFull (T[] copyFrom) throws IllegalArgumentException
 Resets the read and write position according to a full ring buffer and fill all slots w/ elements of array copyFrom. More...
 
int size ()
 Returns the number of elements in this ring buffer. More...
 
int getFreeSlots ()
 Returns the number of free slots available to put. More...
 
boolean isEmpty ()
 Returns true if this ring buffer is empty, otherwise false. More...
 
boolean isFull ()
 Returns true if this ring buffer is full, otherwise false. More...
 
get ()
 Dequeues the oldest enqueued element if available, otherwise null. More...
 
getBlocking () throws InterruptedException
 Dequeues the oldest enqueued element. More...
 
peek ()
 Peeks the next element at the read position w/o modifying pointer, nor blocking. More...
 
peekBlocking () throws InterruptedException
 Peeks the next element at the read position w/o modifying pointer, but w/ blocking. More...
 
boolean put (T e)
 Enqueues the given element. More...
 
void putBlocking (T e) throws InterruptedException
 Enqueues the given element. More...
 
boolean putSame (boolean blocking) throws InterruptedException
 Enqueues the same element at it's write position, if not full. More...
 
void waitForFreeSlots (int count) throws InterruptedException
 Blocks until at least count free slots become available. More...
 
void growEmptyBuffer (T[] newElements) throws IllegalStateException, IllegalArgumentException
 Grows an empty ring buffer, increasing it's capacity about the amount. More...
 
void growFullBuffer (int amount) throws IllegalStateException, IllegalArgumentException
 Grows a full ring buffer, increasing it's capacity about the amount. More...
 

Detailed Description

Simple synchronized implementation of Ringbuffer.

All methods utilize global synchronization.

Characteristics:

  • Read position points to the next read element.
  • Write position points to the next write element.
EmptywritePos == readPossize == 0
FullwritePos == readPossize == capacity

Definition at line 51 of file SyncedRingbuffer.java.

Constructor & Destructor Documentation

◆ SyncedRingbuffer() [1/2]

com.jogamp.common.util.SyncedRingbuffer< T >.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<Integer> rb = new SyncedRingbuffer<Integer>(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
copyFrommandatory source array determining ring buffer's net capacity() and initial content.
Exceptions
IllegalArgumentExceptionif copyFrom is null

Definition at line 95 of file SyncedRingbuffer.java.

◆ SyncedRingbuffer() [2/2]

com.jogamp.common.util.SyncedRingbuffer< T >.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<Integer> rb = new SyncedRingbuffer<Integer>(10, Integer[].class);

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

Implementation will allocate an internal array of size capacity.

Parameters
arrayTypethe array type of the created empty internal array.
capacitythe initial net capacity of the ring buffer

Definition at line 118 of file SyncedRingbuffer.java.

Member Function Documentation

◆ capacity()

final int com.jogamp.common.util.SyncedRingbuffer< T >.capacity ( )

Returns the net capacity of this ring buffer.

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 125 of file SyncedRingbuffer.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

final void com.jogamp.common.util.SyncedRingbuffer< T >.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.

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 134 of file SyncedRingbuffer.java.

◆ dump()

final void com.jogamp.common.util.SyncedRingbuffer< T >.dump ( final PrintStream  stream,
final String  prefix 
)

Debug functionality - Dumps the contents of the internal array.

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 66 of file SyncedRingbuffer.java.

Here is the call graph for this function:

◆ 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;.

Returns
the oldest put element if available, otherwise null.

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 199 of file SyncedRingbuffer.java.

◆ getBlocking()

final T com.jogamp.common.util.SyncedRingbuffer< T >.getBlocking ( ) throws InterruptedException

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.

Returns
the oldest put element
Exceptions
InterruptedException

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 212 of file SyncedRingbuffer.java.

◆ getFreeSlots()

final int com.jogamp.common.util.SyncedRingbuffer< T >.getFreeSlots ( )

Returns the number of free slots available to put.


Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 172 of file SyncedRingbuffer.java.

◆ growEmptyBuffer()

final void com.jogamp.common.util.SyncedRingbuffer< T >.growEmptyBuffer ( final T[]  newElements) throws IllegalStateException, IllegalArgumentException

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
newElementsarray of new full elements the empty buffer shall grow about.
Exceptions
IllegalStateExceptionif buffer is not empty
IllegalArgumentExceptionif newElements is null

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 322 of file SyncedRingbuffer.java.

◆ growFullBuffer()

final void com.jogamp.common.util.SyncedRingbuffer< T >.growFullBuffer ( final int  amount) throws IllegalStateException, IllegalArgumentException

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
amountthe amount of elements the buffer shall grow about
Exceptions
IllegalStateExceptionif buffer is not full
IllegalArgumentExceptionif amount is < 0

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 367 of file SyncedRingbuffer.java.

◆ isEmpty()

final boolean com.jogamp.common.util.SyncedRingbuffer< T >.isEmpty ( )

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 179 of file SyncedRingbuffer.java.

◆ isFull()

final boolean com.jogamp.common.util.SyncedRingbuffer< T >.isFull ( )

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 186 of file SyncedRingbuffer.java.

◆ peek()

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

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 217 of file SyncedRingbuffer.java.

◆ peekBlocking()

final T com.jogamp.common.util.SyncedRingbuffer< T >.peekBlocking ( ) throws InterruptedException

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

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 223 of file SyncedRingbuffer.java.

◆ put()

final boolean com.jogamp.common.util.SyncedRingbuffer< T >.put ( final T  e)

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.

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 257 of file SyncedRingbuffer.java.

◆ putBlocking()

final void com.jogamp.common.util.SyncedRingbuffer< T >.putBlocking ( final T  e) throws InterruptedException

Enqueues the given element.Method blocks until a free slot becomes available via get.

Exceptions
InterruptedException

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 270 of file SyncedRingbuffer.java.

◆ putSame()

final boolean com.jogamp.common.util.SyncedRingbuffer< T >.putSame ( final boolean  blocking) throws InterruptedException

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.

Parameters
blockingif true, wait until a free slot becomes available via get.
Exceptions
InterruptedException

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

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 283 of file SyncedRingbuffer.java.

◆ resetFull()

final void com.jogamp.common.util.SyncedRingbuffer< T >.resetFull ( final T[]  copyFrom) throws IllegalArgumentException

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
copyFromMandatory array w/ length capacity() to be copied into the internal array.
Exceptions
IllegalArgumentExceptionif copyFrom is null.
IllegalArgumentExceptionif copyFrom's length is different from capacity().

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 144 of file SyncedRingbuffer.java.

◆ size()

final int com.jogamp.common.util.SyncedRingbuffer< T >.size ( )

Returns the number of elements in this ring buffer.

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 165 of file SyncedRingbuffer.java.

◆ toString()

final String com.jogamp.common.util.SyncedRingbuffer< T >.toString ( )

Returns a short string representation incl.

size/capacity and internal r/w index (impl. dependent).

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 61 of file SyncedRingbuffer.java.

Here is the caller graph for this function:

◆ waitForFreeSlots()

final void com.jogamp.common.util.SyncedRingbuffer< T >.waitForFreeSlots ( final int  count) throws InterruptedException

Blocks until at least count free slots become available.

Exceptions
InterruptedException

Implements com.jogamp.common.util.Ringbuffer< T >.

Definition at line 310 of file SyncedRingbuffer.java.


The documentation for this class was generated from the following file: