Package org.apache.zookeeper.server.util
Class CircularBuffer<T>
java.lang.Object
org.apache.zookeeper.server.util.CircularBuffer<T>
Thread safe FIFO CircularBuffer implementation.
When the buffer is full write operation overwrites the oldest element.
Fun thing @todo, make this lock free as this is called on every quorum message
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
CircularBuffer
-
-
Method Details
-
write
Puts elements in the next available index in the array. If the array is full the oldest element is replaced with the new value.- Parameters:
element
-
-
take
Reads from the buffer in a FIFO manner. Returns the oldest element in the buffer if the buffer is not empty Returns null if the buffer is empty- Returns:
- the oldest element in the buffer
-
peek
-
size
public int size() -
isEmpty
public boolean isEmpty() -
isFull
public boolean isFull() -
reset
public void reset()
-