Package org.apache.nifi.util
Class RingBuffer<T>
java.lang.Object
org.apache.nifi.util.RingBuffer<T>
Thread-safe implementation of a RingBuffer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceDefines an interface that can be used to iterate over all of the elements in the RingBuffer via theforEach(org.apache.nifi.util.RingBuffer.ForEachEvaluator<T>)methodstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object[]private booleanprivate intprivate final Lockprivate final ReadWriteLockprivate final Lock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the given value to the RingBuffer and returns the value that was removed in order to make room.asList()intcountSelectedElements(RingBuffer.Filter<T> filter) voidforEach(RingBuffer.ForEachEvaluator<T> evaluator) Iterates over each element in the RingBuffer, calling theevaluatemethod on each element in the RingBuffer.voidforEach(RingBuffer.ForEachEvaluator<T> evaluator, RingBuffer.IterationDirection iterationDirection) Iterates over each element in the RingBuffer, calling theevaluatemethod on each element in the RingBuffer.private TgetElementData(int index) getSelectedElements(RingBuffer.Filter<T> filter) getSelectedElements(RingBuffer.Filter<T> filter, int maxElements) intgetSize()intremoveSelectedElements(RingBuffer.Filter<T> filter) Removes all elements from the RingBuffer that match the given filter
-
Field Details
-
buffer
-
insertionPointer
private int insertionPointer -
filled
private boolean filled -
rwLock
-
readLock
-
writeLock
-
-
Constructor Details
-
RingBuffer
public RingBuffer(int size)
-
-
Method Details
-
add
Adds the given value to the RingBuffer and returns the value that was removed in order to make room.- Parameters:
value- the new value to add- Returns:
- value previously in the buffer
-
getSize
public int getSize() -
getSelectedElements
-
getSelectedElements
-
countSelectedElements
-
removeSelectedElements
Removes all elements from the RingBuffer that match the given filter- Parameters:
filter- to use for deciding what is removed- Returns:
- always zero
-
asList
-
getOldestElement
-
getNewestElement
-
getElementData
-
forEach
Iterates over each element in the RingBuffer, calling theevaluatemethod on each element in the RingBuffer. If the Evaluator returnsfalse, the method will skip all remaining elements in the RingBuffer; otherwise, the next element will be evaluated until all elements have been evaluated.- Parameters:
evaluator- used to evaluate each item in the ring buffer
-
forEach
public void forEach(RingBuffer.ForEachEvaluator<T> evaluator, RingBuffer.IterationDirection iterationDirection) Iterates over each element in the RingBuffer, calling theevaluatemethod on each element in the RingBuffer. If the Evaluator returnsfalse, the method will skip all remaining elements in the RingBuffer; otherwise, the next element will be evaluated until all elements have been evaluated.- Parameters:
evaluator- the evaluatoriterationDirection- the order in which to iterate over the elements in the RingBuffer
-