Class FixedBuffer<T>
java.lang.Object
org.jgroups.util.Buffer<T>
org.jgroups.util.FixedBuffer<T>
- Type Parameters:
T- T
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<T>
Ring buffer of fixed capacity. Indices low and high point to the beginning and end of the buffer. Sequence numbers
(seqnos) are mapped to an index by
Note that 'null' is not a valid element, but signifies a missing element
The design is described in doc/design/FixedBuffer.txt.
seqno % capacity. High can never pass low, and drops the element or blocks when that's the case.
Note that 'null' is not a valid element, but signifies a missing element
The design is described in doc/design/FixedBuffer.txt.
- Since:
- 5.4
- Author:
- Bela Ban
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class Buffer
Buffer.HighestDeliverable, Buffer.Missing, Buffer.NumDeliverable, Buffer.Remover<R>, Buffer.Visitor<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AverageMinMaxprotected T[]Holds the elementsprotected final Conditionprotected final LongAdderprotected final LongAdderNumber of received messages dropped due to full bufferprotected booleanUsed to unblock blocked senders on close(). -
Constructor Summary
ConstructorsConstructorDescriptionFixedBuffer(int capacity, long offset) Creates a RingBufferFixedBuffer(long offset) -
Method Summary
Modifier and TypeMethodDescription_get(long seqno) Only used for testing !!booleanAdds an element if the element at the given index is null.booleanAdds elements from the listbooleanprotected booleanblock(long seqno) intcapacity()Returns the current capacity in the buffer.voidchangeCapacity(int new_capacity) Changes the size of the buffer.protected voiddecreaseCapacity(int new_cap) voidforEach(long from, long to, Buffer.Visitor<T> visitor, boolean nullify) voidforEach(long from, long to, Buffer.Visitor<T> visitor, boolean nullify, boolean respect_stop) get(long seqno) protected voidincreaseCapacity(int new_cap) protected intindex(long seqno) iterator()Returns an iterator over the elements of the ring buffer in the range [LOW+1 ..iterator(long from, long to) longlongvoidopen(boolean b) intpurge(long seqno, boolean force) Purges (nulls) all elements <= seqno.remove(boolean nullify) Removes the next non-null element and advances hdremoveMany(boolean nullify, int max_results, Predicate<T> filter) <R> RremoveMany(boolean nullify, int max_results, Predicate<T> filter, Supplier<R> result_creator, BiConsumer<R, T> accumulator) voidstream()stream(long from, long to) Methods inherited from class Buffer
add, close, computeSize, dump, forEach, getAdders, getDigest, getHighestDeliverable, getMissing, getMissing, getNumDeliverable, hd, high, highestDelivered, highestDelivered, isEmpty, lock, low, numMissing, offset, purge, remove, removeMany, size, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
buf
Holds the elements -
buffer_full
-
open
protected boolean openUsed to unblock blocked senders on close(). When false, senders don't block when full but discard element -
num_blockings
-
avg_time_blocked
-
num_dropped_msgs
Number of received messages dropped due to full buffer
-
-
Constructor Details
-
FixedBuffer
public FixedBuffer() -
FixedBuffer
public FixedBuffer(long offset) -
FixedBuffer
public FixedBuffer(int capacity, long offset) Creates a RingBuffer- Parameters:
capacity- The number of elements the ring buffer's array should hold.offset- The offset. The first element to be added has to be offset +1.
-
-
Method Details
-
capacity
public int capacity()Description copied from class:BufferReturns the current capacity in the buffer. This value is fixed in a fixed-size buffer (e.g.FixedBuffer), but can change in a dynamic buffer (DynamicBuffer) -
numBlockings
public long numBlockings() -
avgTimeBlocked
-
numDroppedMessages
public long numDroppedMessages() -
add
Description copied from class:BufferAdds an element if the element at the given index is null. Returns true if no element existed at the given index, else returns false and doesn't set the element.- Specified by:
addin classBuffer<T>- Parameters:
seqno- The seqno of the elementelement- The element to be addedremove_filter- A filter used to remove all consecutive messages passing the filter (and non-null). This doesn't necessarily null a removed message, but may simply advance an index (e.g. highest delivered). Ignored if null.block_if_full- If true: blocks when an element is to be added to the buffer, else drops the element- Returns:
- True if the element at the computed index was null, else false
-
add
-
add
Description copied from class:BufferAdds elements from the list- Specified by:
addin classBuffer<T>- Parameters:
list- The list of tuples of seqnos and elements. If remove_added_elements is true, if elements could not be added (e.g. because they were already present or the seqno was < HD), those elements will be removed from listremove_added_elements- If true, elements that could not be added to the table are removed from listconst_value- If non-null, this value should be used rather than the values of the list tuples- Returns:
- True if at least 1 element was added successfully, false otherwise.
-
remove
-
removeMany
-
removeMany
public <R> R removeMany(boolean nullify, int max_results, Predicate<T> filter, Supplier<R> result_creator, BiConsumer<R, T> accumulator) - Specified by:
removeManyin classBuffer<T>
-
get
-
_get
-
purge
public int purge(long seqno, boolean force) Description copied from class:BufferPurges (nulls) all elements <= seqno. -
changeCapacity
public void changeCapacity(int new_capacity) Changes the size of the buffer. This method should NOT be used; it is only here to change config in perf tests dynamically!! -
forEach
-
forEach
public void forEach(long from, long to, Buffer.Visitor<T> visitor, boolean nullify, boolean respect_stop) -
resetStats
public void resetStats()- Overrides:
resetStatsin classBuffer<T>
-
open
-
iterator
Returns an iterator over the elements of the ring buffer in the range [LOW+1 .. HIGH]- Returns:
- FixedBufferIterator
- Throws:
NoSuchElementException- is HD is moved forward during the iteration
-
iterator
-
stream
-
stream
-
index
protected int index(long seqno) -
block
protected boolean block(long seqno) -
increaseCapacity
protected void increaseCapacity(int new_cap) -
decreaseCapacity
protected void decreaseCapacity(int new_cap)
-