- See Also:
Constructors Constructor Description
Modifier and Type Method Description
Object item)(Adds an item to the tail of the ringbuffer.
()Clears the data in the ringbuffer.
()Returns the capacity of this ringbuffer.
()Returns the sequence of the head.
()Returns the array representing this ringbuffer.
()Returns the sequence of the tail.
()Returns a read-only iterator.
(long sequence)Reads one item from the ringbuffer.
Object data)(long seq,Sets the item at the given sequence.
(long sequence)Sets the head sequence.
(long sequence)Sets the tail sequence.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
RingbufferMergeDatapublic RingbufferMergeData(int capacity)
RingbufferMergeDatapublic RingbufferMergeData(com.hazelcast.ringbuffer.impl.Ringbuffer<Object> ringbuffer)
getTailSequencepublic long getTailSequence()Returns the sequence of the tail. The tail is the side of the ringbuffer where the items are added to.
The initial value of the tail is
- the sequence of the tail
setTailSequencepublic void setTailSequence(long sequence)Sets the tail sequence. The tail sequence cannot be less than
headSequence() - 1.
getHeadSequencepublic long getHeadSequence()Returns the sequence of the head. The head is the side of the ringbuffer where the oldest items in the ringbuffer are found.
If the RingBuffer is empty, the head will be one more than the
The initial value of the head is 0 (1 more than tail).
- the sequence of the head
setHeadSequencepublic void setHeadSequence(long sequence)Sets the head sequence. The head sequence cannot be larger than
tailSequence() + 1.
getCapacitypublic int getCapacity()Returns the capacity of this ringbuffer.
- the capacity
sizepublic int size()Returns number of items in the ringbuffer (meaning the number of items between the
- the size
addpublic long add(Object item)Adds an item to the tail of the ringbuffer. If there is no space in the ringbuffer, the add will overwrite the oldest item in the ringbuffer. The method allows null values.
The returned value is the sequence of the added item. Using this sequence you can read the added item.
Using the sequence as IDThis sequence will always be unique for this ringbuffer instance so it can be used as a unique ID generator if you are publishing items on this ringbuffer. However you need to take care of correctly determining an initial ID when any node uses the ringbuffer for the first time. The most reliable way to do that is to write a dummy item into the ringbuffer and use the returned sequence as initial ID. On the reading side, this dummy item should be discard. Please keep in mind that this ID is not the sequence of the item you are about to publish but from a previously published item. So it can't be used to find that item.
item- the item to add
- the sequence of the added item
readpublic <E> E read(long sequence)Reads one item from the ringbuffer.
setpublic void set(long seq, Object data)Sets the item at the given sequence. The method allows
seq- the target sequence
data- the data to be set
clearpublic void clear()Clears the data in the ringbuffer.
getItemspublic Object getItems()Returns the array representing this ringbuffer.
Items at the beginning of this array may have higher sequence IDs than items at the end of this array. This means that this array is not sorted by sequence ID and the index of the item in this array must be calculated using the sequence and the modulo of the array.
iteratorReturns a read-only iterator. Mutation methods will throw a