public class ArrayRingbuffer extends Object implements Ringbuffer
Constructor and Description |
---|
ArrayRingbuffer(int capacity) |
Modifier and Type | Method and Description |
---|---|
long |
add(Object item)
Adds an item to the tail of the Ringbuffer.
|
void |
checkBlockableReadSequence(long readSequence)
Check if the sequence can be read from the ring buffer or if the sequence is of the next item to be added into the
ringbuffer.
|
void |
checkReadSequence(long sequence)
Check if the sequence can be read from the ring buffer.
|
long |
getCapacity()
Returns the capacity of this Ringbuffer.
|
long |
headSequence()
Returns the sequence of the head.
|
boolean |
isEmpty()
Is the ring buffer empty.
|
Object |
read(long sequence)
Reads one item from the Ringbuffer.
|
void |
set(long seq,
Object data)
Sets the item at the given sequence.
|
void |
setHeadSequence(long sequence)
Sets the head sequence.
|
void |
setTailSequence(long sequence)
Sets the tail sequence.
|
long |
size()
Returns number of items in the ringbuffer (meaning the number of items between the
Ringbuffer.headSequence() and
Ringbuffer.tailSequence() ). |
long |
tailSequence()
Returns the sequence of the tail.
|
public long tailSequence()
Ringbuffer
The initial value of the tail is -1.
tailSequence
in interface Ringbuffer
public void setTailSequence(long sequence)
Ringbuffer
Ringbuffer.headSequence()
- 1.setTailSequence
in interface Ringbuffer
sequence
- the new tail sequencepublic long headSequence()
Ringbuffer
If the RingBuffer is empty, the head will be one more than the Ringbuffer.tailSequence()
.
The initial value of the head is 0 (1 more than tail).
headSequence
in interface Ringbuffer
public void setHeadSequence(long sequence)
Ringbuffer
Ringbuffer.tailSequence()
+ 1setHeadSequence
in interface Ringbuffer
sequence
- The new head sequence.public long getCapacity()
Ringbuffer
getCapacity
in interface Ringbuffer
public long size()
Ringbuffer
Ringbuffer.headSequence()
and
Ringbuffer.tailSequence()
).size
in interface Ringbuffer
public boolean isEmpty()
Ringbuffer
isEmpty
in interface Ringbuffer
public long add(Object item)
Ringbuffer
The returned value is the sequence of the added item. Using this sequence you can read the added item.
add
in interface Ringbuffer
item
- the item to add.public Object read(long sequence)
Ringbuffer
This method is not destructive unlike e.g. a queue.take. So the same item can be read by multiple readers or it can be read multiple times by the same reader.
read
in interface Ringbuffer
sequence
- the sequence of the item to read.public void checkBlockableReadSequence(long readSequence)
Ringbuffer
Ringbuffer.tailSequence()
, giving the
oportunity to block until the item is added into the ring buffer.checkBlockableReadSequence
in interface Ringbuffer
readSequence
- the sequence wanting to be readpublic void checkReadSequence(long sequence)
Ringbuffer
checkReadSequence
in interface Ringbuffer
sequence
- the sequence wanting to be readpublic void set(long seq, Object data)
Ringbuffer
set
in interface Ringbuffer
seq
- The target sequence.data
- The data to be setCopyright © 2017 Hazelcast, Inc.. All Rights Reserved.