public class RequestTable<T>
extends java.lang.Object
RequestCorrelator
. Grows and shrinks when needed.
Addition is always at the end, yielding monotonically increasing seqnos. Removal is done by nulling the element(s)
between low and high and advancing the low pointer whenever possible.
See JGRP-1982 for details.Modifier and Type | Class and Description |
---|---|
static interface |
RequestTable.Visitor<T> |
Modifier and Type | Field and Description |
---|---|
protected T[] |
buffer |
protected long |
high |
protected java.util.concurrent.locks.Lock |
lock |
protected long |
low |
protected int |
num_removes |
protected int |
removes_till_compaction |
Constructor and Description |
---|
RequestTable(int capacity) |
RequestTable(int capacity,
long low,
long high) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
_compact()
Shrinks the array to half of its current size if the current number of elements fit into half of the capacity.
|
protected boolean |
_contiguousSpaceAvailable(int space_needed)
Check if we have at least space_needed contiguous free slots available in range [low+1 ..
|
protected void |
_copy(int new_cap)
Copies elements from old into new array
|
protected void |
_grow(long new_capacity) |
long |
add(T element)
Adds a new element and returns the sequence number at which it was inserted.
|
protected void |
advanceLow() |
int |
capacity() |
RequestTable<T> |
clear()
Removes all elements, compacts the buffer and sets low=high=0
|
RequestTable<T> |
clear(long mark) |
boolean |
compact()
Shrinks the underlying array to half its size _if_ the new array can hold all of the existing elements.
|
boolean |
contiguousSpaceAvailable()
Checks if there is at least buffer.length/2 contiguous space in range [low+1 ..
|
java.lang.String |
dumpContents() |
RequestTable<T> |
forEach(RequestTable.Visitor<T> visitor) |
RequestTable<T> |
forEachNonBlocking(RequestTable.Visitor<T> visitor)
Non-blocking alternative to
forEach(Visitor) : iteration is performed on the array that exists at the
time of this call. |
T |
get(long seqno) |
RequestTable<T> |
grow(int new_capacity)
Grows the array to at least new_capacity.
|
long |
high() |
protected int |
highestContiguousSpaceAvailable() |
int |
index(long seqno) |
protected static int |
index(long seqno,
int length) |
long |
low() |
T |
remove(long seqno)
Removes the element at the index matching seqno.
|
int |
removesTillCompaction() |
RequestTable<T> |
removesTillCompaction(int rems) |
int |
size()
Returns the number of non-null elements in range [low ..
|
java.lang.String |
toString() |
protected T[] buffer
protected long low
protected long high
protected int removes_till_compaction
protected int num_removes
protected final java.util.concurrent.locks.Lock lock
public RequestTable(int capacity)
public RequestTable(int capacity, long low, long high)
public long low()
public long high()
public int capacity()
public int index(long seqno)
public int removesTillCompaction()
public RequestTable<T> removesTillCompaction(int rems)
public long add(T element)
element
- the element to be added. Must not be null or an exception will be thrownpublic T get(long seqno)
public T remove(long seqno)
seqno
- public RequestTable<T> clear()
public RequestTable<T> clear(long mark)
public RequestTable<T> forEach(RequestTable.Visitor<T> visitor)
public RequestTable<T> forEachNonBlocking(RequestTable.Visitor<T> visitor)
forEach(Visitor)
: iteration is performed on the array that exists at the
time of this call. Changes to the underlying array will not be reflected in the iteration.visitor
- the RequestTable.Visitor
.public RequestTable<T> grow(int new_capacity)
new_capacity
- the new capacity of the underlying array. Will be rounded up to the nearest power of 2 value.
A value smaller than the current capacity is ignored.public boolean compact()
public boolean contiguousSpaceAvailable()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
protected void _grow(long new_capacity)
protected boolean _compact()
public java.lang.String dumpContents()
protected void _copy(int new_cap)
protected boolean _contiguousSpaceAvailable(int space_needed)
space_needed
- the number of contiguous free slots required to do compaction, usually half of the current
buffer sizeprotected int highestContiguousSpaceAvailable()
protected void advanceLow()
protected static int index(long seqno, int length)
Copyright © 1998-2020 Red Hat. All Rights Reserved.