| IRingbufferT Interface |
A Ringbuffer is a data-structure where the content is stored in a ring like structure.
Namespace:
Hazelcast.Core
Assembly:
Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.9.3
Syntax public interface IRingbuffer<T> : IDistributedObject
Public Interface IRingbuffer(Of T)
Inherits IDistributedObject
generic<typename T>
public interface class IRingbuffer : IDistributedObject
type IRingbuffer<'T> =
interface
interface IDistributedObject
end
Type Parameters
- T
The IRingbufferT type exposes the following members.
Methods
| Name | Description |
---|
| Add | Adds an item to the tail of the Ringbuffer. |
| AddAllAsyncTE | Adds all the items of a collection to the tail of the Ringbuffer. |
| AddAsync |
Asynchronously writes an item with a configurable
OverflowPolicy
.
If there is space in the ringbuffer, the call will return the sequence of the written item.
If there is no space, it depends on the overflow policy what happens:
- Overwrite
: we just overwrite the oldest item in the ringbuffer and we violate
the ttl
- Fail
: we return -1
The reason that FAIL exist is to give the opportunity to obey the ttl. If blocking behavior is required,
this can be implemented using retrying in combination with a exponential backoff. Example:
int sleepMs = 100;
for (; ; ) {
long result = ringbuffer.AddAsync(item, OverflowPolicy.Fail).Result;
if (result != -1) {
break;
}
Thread.Sleep(sleepMs);
sleepMs = Math.Min(5000, sleepMs * 2);
} |
| Capacity | Returns the capacity of this Ringbuffer. |
| Destroy | Destroys this object cluster-wide. (Inherited from IDistributedObject.) |
| GetName | Returns the unique name for this IDistributedObject. (Inherited from IDistributedObject.) |
| GetPartitionKey | Returns the key of partition this IDistributedObject is assigned to. (Inherited from IDistributedObject.) |
| GetServiceName | Returns the service name for this object. (Inherited from IDistributedObject.) |
| HeadSequence | Returns the sequence of the head. |
| ReadManyAsync | Reads a batch of items from the Ringbuffer. |
| ReadOne | Reads one item from the Ringbuffer. |
| RemainingCapacity | Returns the remaining capacity of the ringbuffer. |
| Size | Returns number of items in the ringbuffer. |
| TailSequence | Returns the sequence of the tail. |
TopRemarks
A Ringbuffer is a data-structure where the content is stored in a ring like structure. A ringbuffer has a capacity so it
won't grow beyond that capacity and endanger the stability of the system. If that capacity is exceeded, than the oldest
item in the ringbuffer is overwritten.
The ringbuffer has 2 always incrementing sequences:
-
tailSequence: this is the side where the youngest item is found. So the tail is the side of the ringbuffer where
items are added to.
-
headSequence: this is the side where the oldest items are found. So the head is the side where items gets
discarded.
The items in the ringbuffer can be found by a sequence that is in between (inclusive) the head and tail sequence.
If data is read from a ringbuffer with a sequence that is smaller than the headSequence, it means that the data
is not available anymore and a
StaleSequenceException
is thrown.
A Ringbuffer currently is not a distributed data-structure. So all data is stored in a single partition; comparable to the
IQueue implementation. But we'll provide an option to partition the data in the near future.
A Ringbuffer can be used in a similar way as a queue, but one of the key differences is that a queue.take is destructive,
meaning that only 1 thread is able to take an item. A ringbuffer.read is not destructive, so you can have multiple threads
reading the same item multiple times.
The Ringbuffer is the backing data-structure for the reliable
ITopicT
implementation.
See Also