public class RingBufferSeqnoLockless<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 RingBufferLockless is discussed in doc/design/RingBufferLockless.txt.
Modifier and Type | Class and Description |
---|---|
protected class |
RingBufferSeqnoLockless.RingBufferIterator |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.atomic.AtomicReferenceArray<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 java.util.concurrent.atomic.AtomicLong |
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 |
Constructor and Description |
---|
RingBufferSeqnoLockless(int capacity,
long offset)
Creates a RingBuffer
|
Modifier and Type | Method and Description |
---|---|
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 ..
|
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 static void |
validate(long seqno) |
protected final java.util.concurrent.atomic.AtomicReferenceArray<T> buf
protected volatile long low
protected volatile long hd
protected final java.util.concurrent.atomic.AtomicLong hr
protected final long offset
protected final java.util.concurrent.locks.Lock lock
protected final java.util.concurrent.locks.Condition buffer_full
protected volatile boolean running
protected final java.util.concurrent.atomic.AtomicBoolean processing
public RingBufferSeqnoLockless(int capacity, long offset)
capacity
- The number of elements the ring buffer's array should holdoffset
- 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
in interface java.lang.Iterable<T>
java.util.NoSuchElementException
- is HD is moved forward during the iterationpublic java.lang.String toString()
toString
in class java.lang.Object
protected static final void validate(long seqno)
protected int index(long seqno)
protected boolean block(long seqno)
protected int count(boolean missing)
Copyright © 1998-2020 Red Hat. All Rights Reserved.