public class ObjectBuffer
extends java.lang.Object
ObjectBuffer
instances.ObjectBuffer
is a structure that contains a limited number of objects.
These elements are ordered in a first-in-first-out (FIFO) manner.Modifier and Type | Field and Description |
---|---|
static int |
DROP_OLDEST_ON_FULL_POLICY
Drop oldest element when buffer is full and an element is added.
|
static int |
SKIP_DATA_ON_FULL_POLICY
When buffer is full, no element can be added.
|
Constructor and Description |
---|
ObjectBuffer(Monitor lock,
int size,
int policy)
Constructs an
ObjectBuffer initialized with a buffer of size elements. |
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.Object o)
Add an element in this buffer.
|
java.lang.Object |
remove()
Remove the oldest element from this buffer and returns it.
This method is not blocking. |
public static final int DROP_OLDEST_ON_FULL_POLICY
public static final int SKIP_DATA_ON_FULL_POLICY
public ObjectBuffer(Monitor lock, int size, int policy)
ObjectBuffer
initialized with a buffer of size
elements.lock
- monitor used to synchronize accesses to the buffer.size
- maximum number of objects that can be stored in the buffer.policy
- DROP_OLDEST_ON_FULL_POLICY
or SKIP_DATA_ON_FULL_POLICY
public boolean add(java.lang.Object o)
o
- the object to add in the buffer.public java.lang.Object remove()