public class RingBuffer<T>
extends java.lang.Object
implements java.lang.Iterable<T>
stable(long)
method is called periodically; it nulls all elements between LOW and HD and advances LOW
to HD.
The design of RingBuffer is discussed in doc/design/RingBuffer.txt.
限定符和类型 | 类和说明 |
---|---|
protected class |
RingBuffer.RingBufferIterator |
限定符和类型 | 字段和说明 |
---|---|
protected T[] |
buf
Atomic ref array so that elements can be checked for null and set atomically.
|
protected java.util.concurrent.locks.Condition |
buffer_full |
protected long |
hd
The highest delivered seqno.
|
protected long |
hr
The highest received seqno.
|
protected java.util.concurrent.locks.Lock |
lock
Lock for adders to block on when the buffer is full
|
protected long |
low
The lowest seqno.
|
protected long |
offset |
protected java.util.concurrent.atomic.AtomicBoolean |
processing |
protected boolean |
running |
构造器和说明 |
---|
RingBuffer(int capacity,
long offset)
Creates a RingBuffer
|
限定符和类型 | 方法和说明 |
---|---|
T |
_get(long seqno)
Only used for testing !!
|
boolean |
add(long seqno,
T element) |
boolean |
add(long seqno,
T element,
boolean block)
Adds a new element to the buffer
|
protected boolean |
block(long seqno) |
int |
capacity() |
protected int |
count(boolean missing) |
void |
destroy() |
T |
get(long seqno) |
java.util.List<T> |
get(long from,
long to)
Returns a list of messages in the range [from .. to], including from and to
|
long[] |
getDigest() |
long |
getHighestDelivered() |
long |
getHighestReceived() |
long |
getLow() |
SeqnoList |
getMissing() |
java.util.concurrent.atomic.AtomicBoolean |
getProcessing() |
protected int |
index(long seqno) |
java.util.Iterator<T> |
iterator()
Returns an iterator over the elements of the ring buffer in the range [HD+1 ..
|
int |
missing() |
T |
remove()
Removes the next element (at hd +1).
|
T |
remove(boolean nullify)
Removes the next element (at hd +1).
|
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) |
double |
saturation() |
void |
setHighestDelivered(long hd) |
int |
size() |
int |
spaceUsed() |
void |
stable(long seqno)
Nulls elements between low and seqno and forwards low
|
java.lang.String |
toString() |
protected final T[] buf
protected long low
protected long hd
protected long hr
protected final long offset
protected final java.util.concurrent.locks.Lock lock
protected final java.util.concurrent.locks.Condition buffer_full
protected boolean running
protected final java.util.concurrent.atomic.AtomicBoolean processing
public RingBuffer(int capacity, long offset)
capacity
- The number of elements the ring buffer's array should hold.offset
- The offset. The first element to be added has to be offset +1.public long getLow()
public long getHighestDelivered()
public void setHighestDelivered(long hd)
public long getHighestReceived()
public long[] getDigest()
public java.util.concurrent.atomic.AtomicBoolean getProcessing()
public boolean add(long seqno, T element)
public boolean add(long seqno, T element, boolean block)
seqno
- The seqno of the elementelement
- The elementblock
- If true, add() will block when the buffer is full until there is space. Else, add() will
return immediately, either successfully or unsuccessfully (if the buffer is full)public T remove(boolean nullify)
nullify
- Nulls the element in the array if truepublic T remove()
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 T get(long seqno)
public T _get(long seqno)
public java.util.List<T> get(long from, long to)
from
- to
- public void stable(long seqno)
public void destroy()
public final int capacity()
public int size()
public int missing()
public int spaceUsed()
public double saturation()
public SeqnoList getMissing()
public java.util.Iterator<T> iterator()
iterator
在接口中 java.lang.Iterable<T>
java.util.NoSuchElementException
- is HD is moved forward during the iterationpublic java.lang.String toString()
toString
在类中 java.lang.Object
protected int index(long seqno)
protected boolean block(long seqno)
protected int count(boolean missing)