public class RingbufferContainer extends Object implements IdentifiedDataSerializable
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()
This constructor only supports IdentifiedDataSerializable instance creation.
|
RingbufferContainer(String name)
Constructs the ring buffer container with only the name and the key for blocking operations.
|
RingbufferContainer(String name,
RingbufferConfig config,
SerializationService serializationService,
ClassLoader configClassLoader) |
Modifier and Type | Method and Description |
---|---|
long |
add(Data item)
Adds one item to the ring buffer.
|
long |
addAll(Data[] 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.
|
RingbufferWaitNotifyKey |
getRingEmptyWaitNotifyKey()
Gets the wait/notify key for the blocking operations of reading from the ring buffer.
|
RingbufferStoreWrapper |
getStore() |
long |
headSequence() |
void |
init(String name,
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 |
read(long sequence)
Reads one item from the ring buffer.
|
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,
Data dataItem)
Sets the item at the given sequence ID and updates the expiration time if TTL is configured.
|
void |
setHeadSequence(long sequence) |
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()
public RingbufferContainer(String name)
init(String, RingbufferConfig, SerializationService, ClassLoader)
method to complete the initialization before
usage.name
- the name of the ring buffer containerpublic RingbufferContainer(String name, RingbufferConfig config, SerializationService serializationService, ClassLoader configClassLoader)
public void init(String name, RingbufferConfig config, SerializationService serializationService, ClassLoader configClassLoader)
name
- the name of the ring bufferconfig
- 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(Data item)
item
- item 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 long addAll(Data[] 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, Data dataItem)
sequenceId
- the sequence ID under which the item is storeddataItem
- 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 read(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)
{@link #tailSequence()}
,
the caller can use this method to determine if he is checking the sequence ID 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 int getFactoryId()
IdentifiedDataSerializable
getFactoryId
in interface IdentifiedDataSerializable
public int getId()
IdentifiedDataSerializable
getId
in interface IdentifiedDataSerializable
Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.