public class RingbufferContainer<T> extends Object implements IdentifiedDataSerializable, Notifier, Versioned
The expirationPolicy contains the expiration policy of the items. If a time to live is set, the policy is created, otherwise it is null to save space.
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,
SerializationService serializationService,
ClassLoader configClassLoader,
int partitionId) |
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 ring buffer.
|
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() |
long |
getCapacity() |
RingbufferConfig |
getConfig() |
int |
getFactoryId()
Returns DataSerializableFactory factory ID for this class.
|
int |
getId()
Returns type identifier for this class.
|
ObjectNamespace |
getNamespace() |
WaitNotifyKey |
getNotifiedKey() |
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,
SerializationService serializationService,
ClassLoader configClassLoader)
Initializes the ring buffer with references to other services, the ring buffer store and the config.
|
boolean |
isEmpty() |
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) |
long |
remainingCapacity()
Returns the remaining capacity of the ring buffer.
|
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) |
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, SerializationService, ClassLoader)
method to complete the initialization before usage.namespace
- the namespace of the ring buffer containerpublic RingbufferContainer(ObjectNamespace namespace, RingbufferConfig config, SerializationService serializationService, ClassLoader configClassLoader, int partitionId)
public void init(RingbufferConfig config, SerializationService serializationService, ClassLoader configClassLoader)
config
- the configuration of the ring bufferserializationService
- the serialization serviceconfigClassLoader
- the class loader for which the ring buffer store classes will be loadedpublic RingbufferStoreWrapper getStore()
public RingbufferWaitNotifyKey getRingEmptyWaitNotifyKey()
public RingbufferConfig getConfig()
public long tailSequence()
public long headSequence()
public void setHeadSequence(long sequence)
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)
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 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
public void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
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
Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.