E
- the type of the data stored in the ringbufferpublic interface Ringbuffer<E> extends Iterable<E>
Modifier and Type | Method and Description |
---|---|
long |
add(E item)
Adds an item to the tail of the ringbuffer.
|
void |
checkBlockableReadSequence(long readSequence)
Check if the sequence can be read from the ringbuffer 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 ringbuffer.
|
void |
clear()
Clears the data in the ringbuffer.
|
long |
getCapacity()
Returns the capacity of this ringbuffer.
|
E[] |
getItems()
Returns the array representing this ringbuffer.
|
long |
headSequence()
Returns the sequence of the head.
|
boolean |
isEmpty()
Checks if the ringbuffer is empty.
|
long |
peekNextTailSequence()
Returns the next sequence which the tail will be at after the next item
is added.
|
E |
read(long sequence)
Reads one item from the ringbuffer.
|
void |
set(long seq,
E data)
Sets the item at the given sequence.
|
void |
setHeadSequence(long sequence)
Sets the head sequence.
|
void |
setTailSequence(long tailSequence)
Sets the tail sequence.
|
long |
size()
Returns number of items in the ringbuffer (meaning the number of items
between the
headSequence() and tailSequence() ). |
long |
tailSequence()
Returns the sequence of the tail.
|
forEach, iterator, spliterator
long getCapacity()
long size()
headSequence()
and tailSequence()
).long tailSequence()
-1
.long peekNextTailSequence()
void setTailSequence(long tailSequence)
headSequence() - 1
.tailSequence
- the new tail sequenceIllegalArgumentException
- if the target sequence is less than
headSequence() - 1
headSequence()
long headSequence()
tailSequence()
.
The initial value of the head is 0 (1 more than tail).void setHeadSequence(long sequence)
tailSequence() + 1
sequence
- the new head sequenceIllegalArgumentException
- if the target sequence is greater than tailSequence() + 1
tailSequence()
boolean isEmpty()
true
if the ringbuffer is empty, false
otherwiselong add(E item)
The returned value is the sequence of the added item. Using this sequence you can read the added item.
item
- the item to addE read(long sequence)
queue.take
. So the
same item can be read by multiple readers or it can be read multiple
times by the same reader.sequence
- the sequence of the item to readStaleSequenceException
- if the sequence is smaller then headSequence()
or larger than
tailSequence()
. Because a ringbuffer won't store all event
indefinitely, it can be that the data for the given sequence doesn't
exist anymore and the StaleSequenceException
is thrown.
It is up to the caller to deal with this particular situation, e.g.
throw an Exception
or restart from the last known head.
That is why the StaleSequenceException contains the last known head.void checkBlockableReadSequence(long readSequence)
tailSequence()
,
giving the opportunity to block until the item is added into the ringbuffer.readSequence
- the sequence wanting to be readStaleSequenceException
- if the requested sequence is smaller than the headSequence()
IllegalArgumentException
- if the requested sequence is greater than the tailSequence() + 1
headSequence()
,
tailSequence()
void checkReadSequence(long sequence)
sequence
- the sequence wanting to be readStaleSequenceException
- if the requested sequence is smaller than the headSequence()
IllegalArgumentException
- if the requested sequence is greater than the tailSequence()
headSequence()
,
tailSequence()
void set(long seq, E data)
null
data.seq
- the target sequencedata
- the data to be setvoid clear()
E[] getItems()
Copyright © 2022 Hazelcast, Inc.. All Rights Reserved.