public class RingBuffer<T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
RingBuffer.Filter<S> |
static interface |
RingBuffer.ForEachEvaluator<S>
Defines an interface that can be used to iterate over all of the elements in the RingBuffer via the
forEach(org.apache.nifi.util.RingBuffer.ForEachEvaluator<T>) method |
static class |
RingBuffer.IterationDirection |
Modifier and Type | Field and Description |
---|---|
private Object[] |
buffer |
private boolean |
filled |
private int |
insertionPointer |
private Lock |
readLock |
private ReadWriteLock |
rwLock |
private Lock |
writeLock |
Constructor and Description |
---|
RingBuffer(int size) |
Modifier and Type | Method and Description |
---|---|
T |
add(T value)
Adds the given value to the RingBuffer and returns the value that was removed in order to make room.
|
List<T> |
asList() |
int |
countSelectedElements(RingBuffer.Filter<T> filter) |
void |
forEach(RingBuffer.ForEachEvaluator<T> evaluator)
Iterates over each element in the RingBuffer, calling the
evaluate method on each element in the RingBuffer. |
void |
forEach(RingBuffer.ForEachEvaluator<T> evaluator,
RingBuffer.IterationDirection iterationDirection)
Iterates over each element in the RingBuffer, calling the
evaluate method on each element in the RingBuffer. |
private T |
getElementData(int index) |
T |
getNewestElement() |
T |
getOldestElement() |
List<T> |
getSelectedElements(RingBuffer.Filter<T> filter) |
List<T> |
getSelectedElements(RingBuffer.Filter<T> filter,
int maxElements) |
int |
getSize() |
int |
removeSelectedElements(RingBuffer.Filter<T> filter)
Removes all elements from the RingBuffer that match the given filter
|
private final Object[] buffer
private int insertionPointer
private boolean filled
private final ReadWriteLock rwLock
private final Lock readLock
private final Lock writeLock
public T add(T value)
value
- the new value to addpublic int getSize()
public List<T> getSelectedElements(RingBuffer.Filter<T> filter)
public List<T> getSelectedElements(RingBuffer.Filter<T> filter, int maxElements)
public int countSelectedElements(RingBuffer.Filter<T> filter)
public int removeSelectedElements(RingBuffer.Filter<T> filter)
filter
- to use for deciding what is removedpublic T getOldestElement()
public T getNewestElement()
private T getElementData(int index)
public void forEach(RingBuffer.ForEachEvaluator<T> evaluator)
evaluate
method on each element in the RingBuffer. If the Evaluator returns false
,
the method will skip all remaining elements in the RingBuffer; otherwise, the next element will be evaluated until all elements have been evaluated.evaluator
- used to evaluate each item in the ring bufferpublic void forEach(RingBuffer.ForEachEvaluator<T> evaluator, RingBuffer.IterationDirection iterationDirection)
evaluate
method on each element in the RingBuffer. If the Evaluator returns false
,
the method will skip all remaining elements in the RingBuffer; otherwise, the next element will be evaluated until all elements have been evaluated.evaluator
- the evaluatoriterationDirection
- the order in which to iterate over the elements in the RingBufferCopyright © 2016 Apache NiFi Project. All rights reserved.