E
- the type of the data stored in the ringbufferpublic class ArrayRingbuffer<E> extends Object implements Ringbuffer<E>
Currently the Ringbuffer is not a partitioned data-structure. So all data of a ringbuffer is stored in a single partition and replicated to the replicas. No thread safety is needed since a partition can only be accessed by a single thread at any given moment.
Constructor and Description |
---|
ArrayRingbuffer(int capacity) |
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.
|
Iterator<E> |
iterator() |
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 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public long tailSequence()
Ringbuffer
-1
.tailSequence
in interface Ringbuffer<E>
public long peekNextTailSequence()
Ringbuffer
peekNextTailSequence
in interface Ringbuffer<E>
public void setTailSequence(long sequence)
Ringbuffer
headSequence() - 1
.setTailSequence
in interface Ringbuffer<E>
sequence
- the new tail sequenceRingbuffer.headSequence()
public long headSequence()
Ringbuffer
Ringbuffer.tailSequence()
.
The initial value of the head is 0 (1 more than tail).headSequence
in interface Ringbuffer<E>
public void setHeadSequence(long sequence)
Ringbuffer
tailSequence() + 1
setHeadSequence
in interface Ringbuffer<E>
sequence
- the new head sequenceRingbuffer.tailSequence()
public long getCapacity()
Ringbuffer
getCapacity
in interface Ringbuffer<E>
public long size()
Ringbuffer
Ringbuffer.headSequence()
and Ringbuffer.tailSequence()
).size
in interface Ringbuffer<E>
public boolean isEmpty()
Ringbuffer
isEmpty
in interface Ringbuffer<E>
true
if the ringbuffer is empty, false
otherwisepublic long add(E 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<E>
item
- the item to addpublic E read(long sequence)
Ringbuffer
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<E>
sequence
- the sequence of the item to readpublic void checkBlockableReadSequence(long readSequence)
Ringbuffer
Ringbuffer.tailSequence()
,
giving the opportunity to block until the item is added into the ringbuffer.checkBlockableReadSequence
in interface Ringbuffer<E>
readSequence
- the sequence wanting to be readRingbuffer.headSequence()
,
Ringbuffer.tailSequence()
public void checkReadSequence(long sequence)
Ringbuffer
checkReadSequence
in interface Ringbuffer<E>
sequence
- the sequence wanting to be readRingbuffer.headSequence()
,
Ringbuffer.tailSequence()
public void set(long seq, E data)
Ringbuffer
null
data.set
in interface Ringbuffer<E>
seq
- the target sequencedata
- the data to be setpublic void clear()
Ringbuffer
clear
in interface Ringbuffer<E>
public E[] getItems()
Ringbuffer
getItems
in interface Ringbuffer<E>
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.