public final class UtlConcurrentRingBuffer<T> extends Object
This class implements a ring buffer of a specific size with the following semantics - write will block if no space is available and read will return null if nothing to read.
| Modifier and Type | Class and Description |
|---|---|
static interface |
UtlConcurrentRingBuffer.ItemFactory<T>
The interface of the item creation factory.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> UtlConcurrentRingBuffer<T> |
create(int size,
UtlConcurrentRingBuffer.ItemFactory<T> factory)
Create a ring buffer.
|
T |
get(long slot)
Get the item at the specified slot.
|
boolean |
hasSpace() |
long |
head() |
int |
length()
Get number of items in buffer
|
long |
nextRead()
Get the read slot i.e. the slot at the head of the buffer
|
long |
nextWrite()
Get the write slot i.e. the slot at the tail of the buffer
The calling thread will block in case the buffer is full until
a slot frees us
|
long |
numFulls()
Get the number of times the buffer was full during a write attempt
|
void |
read(long slot)
Advance the read slot
|
int |
size()
Get buffer capacity
|
long |
tail() |
void |
write(long slot)
Advance the write slot
|
public static <T> UtlConcurrentRingBuffer<T> create(int size, UtlConcurrentRingBuffer.ItemFactory<T> factory)
size - The size of the buffer to createfactory - The item factorypublic final boolean hasSpace()
public final long head()
public final long tail()
public final int size()
public final int length()
public final T get(long slot)
slot - The slot returned by #nextIllegalArgumentException - if the supplied slot does not match what is
returned by #nextpublic final long nextWrite()
The calling thread will block in case the buffer is full until a slot frees us
public final void write(long slot)
slot - The slot returned by nextWrite().IllegalArgumentException - if the supplied slot does not match what is
returned by nextWrite()public final long nextRead()
public final void read(long slot)
slot - The slot returned by nextRead().IllegalArgumentException - if the supplied slot does not match what is
returned by nextRead()public final long numFulls()
Copyright © 2019 N5 Technologies, Inc. All Rights Reserved.