T
- the type of items in the ringbuffer containerE
- the type of items in the ringbufferpublic class RingbufferContainer<T,E> extends Object implements IdentifiedDataSerializable, Notifier, Versioned
Constructor and Description |
---|
RingbufferContainer()
For purposes of
IdentifiedDataSerializable instance creation. |
RingbufferContainer(ObjectNamespace namespace,
int partitionId)
Constructs the ring buffer container with only the name and the key for
blocking operations.
|
RingbufferContainer(ObjectNamespace namespace,
RingbufferConfig config,
NodeEngine nodeEngine,
int partitionId)
Constructs a fully initialized ringbuffer that can be used immediately.
|
Modifier and Type | Method and Description |
---|---|
long |
add(T item)
Adds one item to the ring buffer.
|
long |
addAll(T[] items)
Adds all items to the ringbuffer.
|
void |
checkBlockableReadSequence(long readSequence)
Check if the sequence is of an item that can be read immediately
or is the sequence of the next item to be added into the ringbuffer.
|
void |
cleanup() |
void |
clear()
Clears the data in the ringbuffer.
|
long |
getCapacity()
Returns the capacity of this ringbuffer.
|
RingbufferConfig |
getConfig() |
int |
getFactoryId()
Returns DataSerializableFactory factory ID for this class.
|
int |
getId()
Returns type identifier for this class.
|
ObjectNamespace |
getNamespace() |
WaitNotifyKey |
getNotifiedKey() |
Ringbuffer<E> |
getRingbuffer()
Returns the ringbuffer containing the actual items.
|
RingbufferWaitNotifyKey |
getRingEmptyWaitNotifyKey()
Gets the wait/notify key for the blocking operations of reading from the ring buffer.
|
RingbufferStoreWrapper |
getStore() |
long |
headSequence() |
void |
init(RingbufferConfig config,
NodeEngine nodeEngine)
Initializes the ring buffer with references to other services, the
ringbuffer store and the config.
|
boolean |
isEmpty() |
boolean |
isStaleSequence(long sequence) |
boolean |
isTooLargeSequence(long sequence) |
Data |
readAsData(long sequence)
Reads one item from the ring buffer and returns the serialized format.
|
void |
readData(ObjectDataInput in)
Reads fields from the input stream
|
long |
readMany(long beginSequence,
ReadResultSetImpl result)
Reads multiple items from the ring buffer and adds them to
result
in the stored format. |
long |
remainingCapacity()
Returns the remaining capacity of the ringbuffer.
|
void |
set(long sequenceId,
T item)
Sets the item at the given sequence ID and updates the expiration time
if TTL is configured.
|
void |
setHeadSequence(long sequence)
Sets the head sequence.
|
void |
setTailSequence(long sequence)
Sets the tail sequence.
|
boolean |
shouldNotify() |
boolean |
shouldWait(long sequence)
Returns if the sequence is one after the sequence of the newest item in
the ring buffer.
|
long |
size() |
long |
tailSequence() |
void |
writeData(ObjectDataOutput out)
Writes object fields to output stream
|
public RingbufferContainer()
IdentifiedDataSerializable
instance creation.
For any other purpose, use other constructors in this class.public RingbufferContainer(ObjectNamespace namespace, int partitionId)
init(RingbufferConfig, NodeEngine)
method to complete the initialization before usage.namespace
- the namespace of the ringbuffer containerpublic RingbufferContainer(ObjectNamespace namespace, RingbufferConfig config, NodeEngine nodeEngine, int partitionId)
namespace
- the namespace of the ring buffer containerconfig
- the configuration of the ring buffernodeEngine
- the NodeEnginepublic void init(RingbufferConfig config, NodeEngine nodeEngine)
config
- the configuration of the ring buffernodeEngine
- the NodeEnginepublic RingbufferStoreWrapper getStore()
public RingbufferWaitNotifyKey getRingEmptyWaitNotifyKey()
public RingbufferConfig getConfig()
public long tailSequence()
public long headSequence()
public void setHeadSequence(long sequence)
tailSequence() + 1
sequence
- the new head sequenceIllegalArgumentException
- if the target sequence is greater than tailSequence() + 1
tailSequence()
public void setTailSequence(long sequence)
headSequence() - 1
.sequence
- the new tail sequenceIllegalArgumentException
- if the target sequence is less than
headSequence() - 1
headSequence()
public long getCapacity()
public long size()
public boolean isEmpty()
public boolean shouldWait(long sequence)
sequence
- the requested sequenceStaleSequenceException
- if the requested sequence is
1. greater than the tail sequence + 1 or
2. smaller than the head sequence and the data store is not enabledpublic long remainingCapacity()
If TTL is disabled, the remaining capacity is equal to the total ringbuffer capacity.
public long add(T item)
item
can be Data
or the
deserialized object.
The provided item will be transformed to the configured ringbuffer
InMemoryFormat
if necessary.item
- item to be stored in the ring buffer and data store, can be
Data
or an deserialized objectHazelcastException
- if there was any exception thrown by the data storeHazelcastSerializationException
- if the ring buffer is configured to keep items in object format and the
item could not be deserializedpublic long addAll(T[] items)
items
- items to be stored in the ring buffer and data storeHazelcastException
- if there was any exception thrown by the data storeHazelcastSerializationException
- if the ring buffer is configured to keep items
in object format and the item could not be
deserializedpublic void set(long sequenceId, T item)
sequenceId
- the sequence ID under which the item is storeditem
- item to be stored in the ring buffer and data storeHazelcastSerializationException
- if the ring buffer is configured to keep items in object format and the
item could not be deserializedpublic Data readAsData(long sequence)
sequence
- The sequence of the item to be readStaleSequenceException
- if the sequence is :
1. larger than the tailSequence or
2. smaller than the headSequence and the data store is disabledpublic long readMany(long beginSequence, ReadResultSetImpl result)
result
in the stored format. If an item is not available, it will try and
load it from the ringbuffer store.beginSequence
- the sequence of the first item to read.result
- the List where the result are stored in.StaleSequenceException
- if the sequence is :
1. larger than the tailSequence or
2. smaller than the headSequence and the data store is disabledpublic void cleanup()
public boolean isStaleSequence(long sequence)
public boolean isTooLargeSequence(long sequence)
public void checkBlockableReadSequence(long readSequence)
tailSequence()
, the caller can use this method
to check the sequence before performing a possibly blocking read.
Also, the requested sequence can be smaller than the head sequence
if the data store is enabled.readSequence
- the sequence wanting to be readStaleSequenceException
- if the requested sequence is smaller than the head sequence and the data store is
not enabledIllegalArgumentException
- if the requested sequence is greater than the tail sequence + 1 orpublic void writeData(ObjectDataOutput out) throws IOException
DataSerializable
writeData
in interface DataSerializable
out
- outputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
input stream has been closed.public Ringbuffer<E> getRingbuffer()
public ObjectNamespace getNamespace()
public int getFactoryId()
IdentifiedDataSerializable
getFactoryId
in interface IdentifiedDataSerializable
public int getId()
IdentifiedDataSerializable
getId
in interface IdentifiedDataSerializable
public boolean shouldNotify()
shouldNotify
in interface Notifier
public WaitNotifyKey getNotifiedKey()
getNotifiedKey
in interface Notifier
public void clear()
Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.