|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.util.RetransmitTable
public class RetransmitTable
A store for messages to be retransmitted or delivered. Used on sender and receiver side, as a replacement for HashMap. RetransmitTable should use less memory than HashMap, as HashMap.Entry has 4 fields, plus arrays for storage.
RetransmitTable maintains a matrix (an array of arrays) of messages. Messages are stored in the matrix by mapping their seqno to an index. E.g. when we have 10 rows of 1000 messages each, and first_seqno is 3000, then a message with seqno=5600, will be stored in the 3rd row, at index 600. Rows are removed when all messages in that row have been received. This class in not synchronized; the caller has to make sure access to it is synchronized
Field Summary | |
---|---|
protected boolean |
automatic_purging
By default, rows are only nulled and highest_seqno_purged is adjusted when purge(long) is called. |
protected static long |
DEFAULT_MAX_COMPACTION_TIME
|
protected static double |
DEFAULT_RESIZE_FACTOR
|
protected long |
highest_seqno
The highest seqno in the table |
protected long |
highest_seqno_purged
The highest seqno purged |
protected long |
last_compaction_timestamp
The time when the last compaction took place. |
protected static Log |
log
|
protected Message[][] |
matrix
|
protected long |
max_compaction_time
Time (in ms) after which a compaction should take place. |
protected int |
msgs_per_row
|
protected int |
num_rows
|
protected long |
offset
The first seqno, at matrix[0][0] |
protected double |
resize_factor
|
protected int |
size
|
Constructor Summary | |
---|---|
RetransmitTable()
|
|
RetransmitTable(int num_rows,
int msgs_per_row,
long offset)
|
|
RetransmitTable(int num_rows,
int msgs_per_row,
long offset,
double resize_factor)
|
|
RetransmitTable(int num_rows,
int msgs_per_row,
long offset,
double resize_factor,
long max_compaction_time,
boolean automatic_purging)
|
Method Summary | |
---|---|
int |
capacity()
Returns the total capacity in the matrix |
void |
clear()
Removes all elements. |
void |
compact()
Moves the contents of matrix down by the number of purged rows and resizes the matrix accordingly. |
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 highest_seqno_purged to highest_seqno and add up non-null values |
java.lang.String |
dump()
Dumps the seqnos in the table as a list |
java.lang.String |
dumpMatrix()
Dumps the non-null in the table in a pseudo graphic way |
Message |
get(long seqno)
|
java.util.List<Message> |
get(long from,
long to)
|
double |
getFillFactor()
Returns the ratio between size and capacity, as a percentage |
long |
getHighest()
|
long |
getHighestPurged()
|
long |
getMaxCompactionTime()
|
int |
getNullMessages(long from,
long to)
Returns the number of null elements in the range [from .. |
long |
getOffset()
|
protected Message[] |
getRow(int index)
Returns a row. |
boolean |
isAutomaticPurging()
|
boolean |
isEmpty()
|
protected void |
move(int num_rows)
Moves contents of matrix num_rows down. |
void |
purge(long seqno)
Removes all messages less than or equal to seqno from the table. |
boolean |
put(long seqno,
Message msg)
Adds a new message to the index computed as a function of seqno |
Message |
putIfAbsent(long seqno,
Message msg)
Adds a message if the element at the given index is null. |
Message |
remove(long seqno)
Removes the message with seqno from the table, nulls the index |
protected void |
resize(long seqno)
Moves rows down the matrix, by removing purged rows. |
void |
setAutomaticPurging(boolean automatic_purging)
|
void |
setMaxCompactionTime(long max_compaction_time)
|
int |
size()
Returns the numbers of messages in the table |
long |
sizeOfAllMessages(boolean include_headers)
Computes the size of all messages currently 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 msgs_per_row
protected final double resize_factor
protected Message[][] matrix
protected long offset
protected int size
protected long highest_seqno_purged
protected long highest_seqno
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 ms ago, a compaction will take place
protected boolean automatic_purging
purge(long)
is called.
When automatic_purging is enabled (default is off), rows are purged and highest_seqno_purged is adjusted
on remove(long)
protected static final long DEFAULT_MAX_COMPACTION_TIME
protected static final double DEFAULT_RESIZE_FACTOR
protected static final Log log
Constructor Detail |
---|
public RetransmitTable()
public RetransmitTable(int num_rows, int msgs_per_row, long offset)
public RetransmitTable(int num_rows, int msgs_per_row, long offset, double resize_factor)
public RetransmitTable(int num_rows, int msgs_per_row, long offset, double resize_factor, long max_compaction_time, boolean automatic_purging)
Method Detail |
---|
public long getOffset()
public int capacity()
public int size()
public boolean isEmpty()
public long getHighest()
public long getHighestPurged()
public long getMaxCompactionTime()
public void setMaxCompactionTime(long max_compaction_time)
public boolean isAutomaticPurging()
public void setAutomaticPurging(boolean automatic_purging)
public double getFillFactor()
public boolean put(long seqno, Message msg)
seqno
- msg
-
public Message putIfAbsent(long seqno, Message msg)
seqno
- msg
-
public Message get(long seqno)
public java.util.List<Message> get(long from, long to)
public Message remove(long seqno)
public void clear()
public void purge(long seqno)
seqno
- protected void resize(long seqno)
protected void move(int num_rows)
public void compact()
public int computeSize()
public int getNullMessages(long from, long to)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String dump()
public java.lang.String dumpMatrix()
public long sizeOfAllMessages(boolean include_headers)
include_headers
- If true, Message.size()
is used, which will include the size of all
headers and the dest and src addresses. Else Message.getLength()
is used to compute.
Note that the latter is way more efficient.
protected Message[] 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 |