Click or drag to resize

IRingbufferTAddAsync Method

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:
  1. Overwrite : we just overwrite the oldest item in the ringbuffer and we violate the ttl
  2. 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);
}

Namespace:  Hazelcast.Core
Assembly:  Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.11
Syntax
Task<long> AddAsync(
	T item,
	OverflowPolicy overflowPolicy
)

Parameters

item
Type: T
the item to add
overflowPolicy
Type: Hazelcast.CoreOverflowPolicy
the OverflowPolicy to use.

Return Value

Type: TaskInt64
the sequenceId of the added item, or -1 if the add failed.
Exceptions
ExceptionCondition
ArgumentNullExceptionif item or overflowPolicy is null.
See Also