Class Buffer<T>
java.lang.Object
org.jgroups.util.Buffer<T>
- Type Parameters:
T- T
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<T>
- Direct Known Subclasses:
DynamicBuffer, FixedBuffer
Base class for message buffers. Used on the senders (keeping track of sent messages and purging
delivered messages) and receivers (delivering messages in the correct order and asking senders for missing messages).
- Since:
- 5.4
- Author:
- Bela Ban
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected classprotected classprotected classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicIntegerprotected longThe highest delivered (=removed) seqnoprotected longThe highest received/sent seqno.protected final Lockprotected longsender: highest seqno seen by everyone, receiver: highest delivered seqnoprotected longprotected intThe number of non-null elements -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract T_get(long seqno) booleanAdds an element if the element at the given index is null.abstract booleanAdds an element if the element at the given index is null.abstract booleanAdds elements from the listabstract booleanabstract intcapacity()Returns the current capacity in the buffer.voidclose()intIterates from hd to high and adds up non-null values.dump()Dumps all non-null messages (used for testing)abstract voidforEach(long from, long to, Buffer.Visitor<T> visitor, boolean nullify) voidforEach(Buffer.Visitor<T> visitor, boolean nullify) abstract Tget(long seqno) long[]longReturns the highest deliverable (= removable) seqno.Returns a list of missing (= null) elementsgetMissing(int max_msgs) Returns a list of missing messagesintReturns the number of messages that can be deliveredlonghd()longhigh()longhighestDelivered(long seqno) Only used internally on a state transfer (setting the digest).booleanisEmpty()iterator(long from, long to) lock()longlow()intReturns the number of null elements in the range [hd+1 ..longoffset()voidopen(boolean b) intpurge(long seqno) Removes all elements <= seqno from the buffer.abstract intpurge(long seqno, boolean force) Purges (nulls) all elements <= seqno.remove()abstract Tremove(boolean nullify) removeMany(boolean nullify, int max_results) removeMany(boolean nullify, int max_results, Predicate<T> filter) abstract <R> RremoveMany(boolean nullify, int max_results, Predicate<T> filter, Supplier<R> result_creator, BiConsumer<R, T> accumulator) voidintsize()stream()stream(long from, long to) toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, iterator, spliterator
-
Field Details
-
lock
-
adders
-
offset
protected long offset -
low
protected long lowsender: highest seqno seen by everyone, receiver: highest delivered seqno -
hd
protected long hdThe highest delivered (=removed) seqno -
high
protected long highThe highest received/sent seqno. Moved forward by add(). The next message to be added is high+1. low <= hd <= high always holds -
size
protected int sizeThe number of non-null elements
-
-
Constructor Details
-
Buffer
public Buffer()
-
-
Method Details
-
lock
-
getAdders
-
offset
public long offset() -
low
public long low() -
highestDelivered
public long highestDelivered() -
hd
public long hd() -
high
public long high() -
size
public int size() -
isEmpty
public boolean isEmpty() -
capacity
public abstract int capacity()Returns 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) -
resetStats
public void resetStats() -
open
public void open(boolean b) -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
add
Adds 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.- Returns:
- True if the element at the computed index was null, else false
-
add
public abstract boolean add(long seqno, T element, Predicate<T> remove_filter, boolean block_if_full) Adds 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.- 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
public abstract boolean add(MessageBatch batch, Function<T, Long> seqno_getter, boolean remove_from_batch, T const_value) -
add
Adds elements from the list- 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.
-
get
-
_get
-
remove
-
remove
-
removeMany
-
removeMany
-
removeMany
public abstract <R> R removeMany(boolean nullify, int max_results, Predicate<T> filter, Supplier<R> result_creator, BiConsumer<R, T> accumulator) -
purge
public int purge(long seqno) Removes all elements <= seqno from the buffer. Does this by nulling all elements < index(seqno) -
purge
public abstract int purge(long seqno, boolean force) Purges (nulls) all elements <= seqno.- Parameters:
seqno- All elements <= seqno will be purged.force- If false, seqno is max(seqno,hd), else max(seqno,high). In the latter case (seqno > hd), we might purge elements that have not yet been received- Returns:
- 0. The number of purged elements
-
forEach
-
forEach
-
iterator
-
stream
-
stream
-
computeSize
public int computeSize()Iterates from hd to high and adds up non-null values. Caller must hold the lock. -
numMissing
public int numMissing()Returns the number of null elements in the range [hd+1 .. hr-1] excluding hd and hr -
getMissing
Returns a list of missing (= null) elements- Returns:
- A SeqnoList of missing messages, or null if no messages are missing
-
getMissing
Returns a list of missing messages- Parameters:
max_msgs- If > 0, the max number of missing messages to be returned (oldest first), else no limit- Returns:
- A SeqnoList of missing messages, or null if no messages are missing
-
getNumDeliverable
public int getNumDeliverable()Returns the number of messages that can be delivered -
getHighestDeliverable
public long getHighestDeliverable()Returns the highest deliverable (= removable) seqno. This may be higher thanhighestDelivered(), e.g. if elements have been added but not yet removed -
getDigest
public long[] getDigest() -
highestDelivered
-
dump
Dumps all non-null messages (used for testing) -
toString
-