|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.util.Table<T>
public class Table<T>
A store for elements (typically messages) to be retransmitted or delivered. Used on sender and receiver side, as a replacement for HashMap. Table should use less memory than HashMap, as HashMap.Entry has 4 fields, plus arrays for storage.
Table maintains a matrix (an array of arrays) of elements, which are stored in the matrix by mapping their seqno to an index. E.g. when we have 10 rows of 1000 elements each, and first_seqno is 3000, then an element with seqno=5600, will be stored in the 3rd row, at index 600. Rows are removed when all elements in that row have been received. Table started out as a copy of RetransmitTable, but is synchronized and maintains its own low, hd and hr pointers, so it can be used as a replacement for NakReceiverWindow. The idea is to put messages into Table, deliver them in order of seqnos, and periodically scan over all tables in NAKACK2 to do retransmission.
Nested Class Summary | |
---|---|
protected class |
Table.Counter
|
protected class |
Table.Dump
|
protected class |
Table.Getter
|
protected class |
Table.Missing
|
protected class |
Table.Remover
|
static interface |
Table.Visitor<T>
|
Field Summary | |
---|---|
protected static long |
DEFAULT_MAX_COMPACTION_TIME
|
protected static double |
DEFAULT_RESIZE_FACTOR
|
protected int |
elements_per_row
|
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 Summary | |
---|---|
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)
|
Method Summary | |
---|---|
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(long seqno,
T element)
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 |
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()
|
long |
getHighestDelivered()
|
long |
getHighestReceived()
|
long |
getLow()
|
long |
getMaxCompactionTime()
|
SeqnoList |
getMissing()
Returns a list of missing (= null) 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(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()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
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 place
protected 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
Constructor Detail |
---|
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 messages per row.offset
- 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 compactionMethod Detail |
---|
public java.util.concurrent.atomic.AtomicBoolean getProcessing()
public long getOffset()
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 void setHighestDelivered(long seqno)
seqno
- public boolean add(long seqno, T element)
seqno
- element
-
public 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 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 held
from
- The starting seqnoto
- The ending seqno, the range is [from .. to] including from and tovisitor
- An instance of Visitorprotected void resize(long seqno)
protected void move(int num_rows)
protected void _compact()
public int computeSize()
public int getNumMissing()
public SeqnoList getMissing()
public 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)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |