public class Table<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
Table.Counter |
protected class |
Table.Dump |
protected class |
Table.Getter |
protected class |
Table.HighestDeliverable |
protected class |
Table.Missing |
protected class |
Table.Remover |
protected class |
Table.RemoverOnAdd |
static interface |
Table.Visitor<T> |
Modifier and Type | Field and Description |
---|---|
protected static long |
DEFAULT_MAX_COMPACTION_TIME |
protected static double |
DEFAULT_RESIZE_FACTOR |
protected int |
elements_per_row
Must be a power of 2 for efficient modular arithmetic
|
protected long |
hd
The highest delivered (= removed) seqno
|
protected long |
hr
The highest received seqno
|
protected long |
last_compaction_timestamp
The time when the last compaction took place.
|
protected java.util.concurrent.locks.Lock |
lock |
protected long |
low
The highest seqno purged
|
protected T[][] |
matrix |
protected long |
max_compaction_time
Time (in nanoseconds) after which a compaction should take place.
|
protected int |
num_compactions |
protected int |
num_moves |
protected int |
num_purges |
protected int |
num_resizes |
protected int |
num_rows |
protected long |
offset
The first seqno, at matrix[0][0]
|
protected java.util.concurrent.atomic.AtomicBoolean |
processing |
protected double |
resize_factor |
protected int |
size |
Constructor and Description |
---|
Table() |
Table(int num_rows,
int elements_per_row,
long offset) |
Table(int num_rows,
int elements_per_row,
long offset,
double resize_factor) |
Table(int num_rows,
int elements_per_row,
long offset,
double resize_factor,
long max_compaction_time)
Creates a new table
|
Table(long offset) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
_add(long seqno,
T element,
boolean check_if_resize_needed,
Filter<T> remove_filter) |
protected void |
_compact()
Moves the contents of matrix down by the number of purged rows and resizes the matrix accordingly.
|
T |
_get(long seqno)
To be used only for testing; doesn't do any index or sanity checks
|
boolean |
add(java.util.List<Tuple<java.lang.Long,T>> list)
Adds elements from list to the table
|
boolean |
add(java.util.List<Tuple<java.lang.Long,T>> list,
boolean remove_added_elements)
Adds elements from list to the table, removes elements from list that were not added to the table
|
boolean |
add(java.util.List<Tuple<java.lang.Long,T>> list,
boolean remove_added_elements,
T const_value)
Adds elements from the list to the table
|
boolean |
add(long seqno,
T element)
Adds an element if the element at the given index is null.
|
boolean |
add(long seqno,
T element,
Filter<T> remove_filter)
Adds an element if the element at the given index is null.
|
int |
capacity()
Returns the total capacity in the matrix
|
void |
compact() |
protected int |
computeIndex(long seqno)
Computes and returns the index within a row for seqno
|
protected int |
computeRow(long seqno)
Computes and returns the row index for seqno.
|
int |
computeSize()
Iterate from low to hr and add up non-null values.
|
java.lang.String |
dump()
Dumps the seqnos in the table as a list
|
protected long |
findHighestSeqno(java.util.List<Tuple<java.lang.Long,T>> list) |
void |
forEach(long from,
long to,
Table.Visitor<T> visitor)
Iterates over the matrix with range [from ..
|
T |
get(long seqno)
Returns an element at seqno
|
java.util.List<T> |
get(long from,
long to) |
long[] |
getDigest() |
int |
getElementsPerRow() |
long |
getHighestDeliverable()
Returns the highest deliverable (= removable) seqno.
|
long |
getHighestDelivered() |
long |
getHighestReceived() |
long |
getLow() |
long |
getMaxCompactionTime() |
SeqnoList |
getMissing()
Returns a list of missing (= null) elements
|
SeqnoList |
getMissing(int max_msgs)
Returns a list of missing messages
|
int |
getNumCompactions() |
int |
getNumMissing()
Returns the number of null elements in the range [hd+1 ..
|
int |
getNumMoves() |
int |
getNumPurges() |
int |
getNumResizes() |
int |
getNumRows() |
long |
getOffset() |
java.util.concurrent.atomic.AtomicBoolean |
getProcessing() |
protected T[] |
getRow(int index)
Returns a row.
|
boolean |
isEmpty() |
protected void |
move(int num_rows)
Moves contents of matrix num_rows down.
|
void |
purge(long seqno)
Removes all elements less than or equal to seqno from the table.
|
void |
purge(long seqno,
boolean force)
Removes all elements less than or equal to seqno from the table.
|
T |
remove() |
T |
remove(boolean nullify)
Removes the next non-null element and nulls the index if nullify=true
|
java.util.List<T> |
removeMany(java.util.concurrent.atomic.AtomicBoolean processing,
boolean nullify,
int max_results) |
java.util.List<T> |
removeMany(java.util.concurrent.atomic.AtomicBoolean processing,
boolean nullify,
int max_results,
Filter<T> filter)
Removes between 0 and max_results elements from the table and returns them in a list.
|
java.util.List<T> |
removeMany(boolean nullify,
int max_results) |
void |
resetStats() |
protected void |
resize(long seqno)
Moves rows down the matrix, by removing purged rows.
|
void |
setHighestDelivered(long seqno)
Only used internally by JGroups on a state transfer.
|
void |
setMaxCompactionTime(long max_compaction_time) |
int |
size()
Returns the numbers of elements in the table
|
java.lang.String |
toString() |
protected final int num_rows
protected final int elements_per_row
protected final double resize_factor
protected T[][] matrix
protected long offset
protected int size
protected long low
protected long hr
protected long hd
protected long max_compaction_time
protected long last_compaction_timestamp
compact()
takes place and sees that the
last compaction is more than max_compaction_time nanoseconds ago, a compaction will take placeprotected final java.util.concurrent.locks.Lock lock
protected final java.util.concurrent.atomic.AtomicBoolean processing
protected int num_compactions
protected int num_resizes
protected int num_moves
protected int num_purges
protected static final long DEFAULT_MAX_COMPACTION_TIME
protected static final double DEFAULT_RESIZE_FACTOR
public Table()
public Table(long offset)
public Table(int num_rows, int elements_per_row, long offset)
public Table(int num_rows, int elements_per_row, long offset, double resize_factor)
public Table(int num_rows, int elements_per_row, long offset, double resize_factor, long max_compaction_time)
num_rows
- the number of rows in the matrixelements_per_row
- the number of elements per rowoffset
- the seqno before the first seqno to be inserted. E.g. if 0 then the first seqno will be 1resize_factor
- teh factor with which to increase the number of rowsmax_compaction_time
- the max time in milliseconds after we attempt a compactionpublic java.util.concurrent.atomic.AtomicBoolean getProcessing()
public long getOffset()
public int getElementsPerRow()
public int capacity()
public int getNumCompactions()
public int getNumMoves()
public int getNumResizes()
public int getNumPurges()
public int size()
public boolean isEmpty()
public long getLow()
public long getHighestDelivered()
public long getHighestReceived()
public long getMaxCompactionTime()
public void setMaxCompactionTime(long max_compaction_time)
public int getNumRows()
public void resetStats()
public long getHighestDeliverable()
getHighestDelivered()
,
e.g. if elements have been added but not yet removedpublic void setHighestDelivered(long seqno)
seqno
- public boolean add(long seqno, T element)
seqno
- element
- public boolean add(long seqno, T element, Filter<T> remove_filter)
seqno
- element
- remove_filter
- If not null, a filter used to remove all consecutive messages passing the filterpublic boolean add(java.util.List<Tuple<java.lang.Long,T>> list)
list
- public boolean add(java.util.List<Tuple<java.lang.Long,T>> list, boolean remove_added_elements)
list
- public boolean add(java.util.List<Tuple<java.lang.Long,T>> list, boolean remove_added_elements, T const_value)
list
- The list of tuples of seqnos and elements. If remove_added_elements is true, if elements could
not be added to the table (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 tuplespublic T get(long seqno)
seqno
- public T _get(long seqno)
seqno
- public java.util.List<T> get(long from, long to)
public T remove()
public T remove(boolean nullify)
public java.util.List<T> removeMany(boolean nullify, int max_results)
public java.util.List<T> removeMany(java.util.concurrent.atomic.AtomicBoolean processing, boolean nullify, int max_results)
public java.util.List<T> removeMany(java.util.concurrent.atomic.AtomicBoolean processing, boolean nullify, int max_results, Filter<T> filter)
public void purge(long seqno)
seqno
- public void purge(long seqno, boolean force)
seqno
- All elements <= seqno will be nulledforce
- If true, we only ensure that seqno <= hr, but don't care about hd, and set hd=low=seqno.public void compact()
public void forEach(long from, long to, Table.Visitor<T> visitor)
Table.Visitor.visit(long,Object,int,int)
. If the visit() method returns false, the iteration is terminated.
This method must be called with the lock heldfrom
- The starting seqnoto
- The ending seqno, the range is [from .. to] including from and tovisitor
- An instance of Visitorprotected boolean _add(long seqno, T element, boolean check_if_resize_needed, Filter<T> remove_filter)
protected void resize(long seqno)
protected void move(int num_rows)
protected void _compact()
public int computeSize()
public int getNumMissing()
public SeqnoList getMissing()
public SeqnoList getMissing(int max_msgs)
max_msgs
- If > 0, the max number of missing messages to be returned (oldest first), else no limitpublic long[] getDigest()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String dump()
protected T[] getRow(int index)
index
- protected int computeRow(long seqno)
protected int computeIndex(long seqno)
Copyright © 1998-2020 Red Hat. All Rights Reserved.