|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.hazelcast.spi.AbstractDistributedObject<RingbufferService>
com.hazelcast.ringbuffer.impl.RingbufferProxy<E>
E - the type of the elements in the ringbuffer.public class RingbufferProxy<E>
The serverside proxy to access a Ringbuffer.
| Field Summary |
|---|
| Fields inherited from class com.hazelcast.spi.AbstractDistributedObject |
|---|
PARTITIONING_STRATEGY |
| Constructor Summary | |
|---|---|
RingbufferProxy(NodeEngine nodeEngine,
RingbufferService service,
String name,
RingbufferConfig config)
|
|
| Method Summary | |
|---|---|
long |
add(E item)
Adds an item to the tail of the Ringbuffer. |
ICompletableFuture<Long> |
addAllAsync(Collection<? extends E> collection,
OverflowPolicy overflowPolicy)
Adds all the items of a collection to the tail of the Ringbuffer. |
ICompletableFuture<Long> |
addAsync(E item,
OverflowPolicy overflowPolicy)
Asynchronously writes an item with a configurable OverflowPolicy. |
long |
capacity()
Returns the capacity of this Ringbuffer. |
String |
getName()
Returns the unique name for this DistributedObject. |
String |
getServiceName()
Returns the service name for this object. |
long |
headSequence()
Returns the sequence of the head. |
ICompletableFuture<ReadResultSet<E>> |
readManyAsync(long startSequence,
int minCount,
int maxCount,
IFunction<E,Boolean> filter)
Reads a batch of items from the Ringbuffer. |
E |
readOne(long sequence)
Reads one item from the Ringbuffer. |
long |
remainingCapacity()
Returns the remaining capacity of the ringbuffer. |
long |
size()
Returns number of items in the ringbuffer. |
long |
tailSequence()
Returns the sequence of the tail. |
String |
toString()
|
| Methods inherited from class com.hazelcast.spi.AbstractDistributedObject |
|---|
destroy, equals, getId, getNameAsPartitionAwareData, getNodeEngine, getOperationService, getPartitionKey, getService, hashCode, invalidate, postDestroy, throwNotActiveException |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.hazelcast.core.DistributedObject |
|---|
destroy, getId, getPartitionKey |
| Constructor Detail |
|---|
public RingbufferProxy(NodeEngine nodeEngine,
RingbufferService service,
String name,
RingbufferConfig config)
| Method Detail |
|---|
public String getName()
DistributedObject
getName in interface DistributedObjectpublic String getServiceName()
DistributedObject
getServiceName in interface DistributedObjectgetServiceName in class AbstractDistributedObject<RingbufferService>public long capacity()
Ringbuffer
capacity in interface Ringbuffer<E>public long size()
Ringbuffer
size in interface Ringbuffer<E>public long tailSequence()
Ringbuffer
tailSequence in interface Ringbuffer<E>public long headSequence()
Ringbuffer
headSequence in interface Ringbuffer<E>public long remainingCapacity()
Ringbuffer
remainingCapacity in interface Ringbuffer<E>public long add(E item)
RingbufferRingbuffer.addAsync(Object, OverflowPolicy) and the OverflowPolicy.
The returned value is the sequence of the added item. Using this sequence you can read the added item.
add in interface Ringbuffer<E>item - the item to add.
Ringbuffer.addAsync(Object, OverflowPolicy)
public ICompletableFuture<Long> addAsync(E item,
OverflowPolicy overflowPolicy)
RingbufferOverflowPolicy.
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:
OverflowPolicy.OVERWRITE: we just overwrite the oldest item in the ringbuffer and we violate
the ttlOverflowPolicy.FAIL: we return -1
long sleepMs = 100;
for (; ; ) {
long result = ringbuffer.addAsync(item, FAIL).get();
if (result != -1) {
break;
}
TimeUnit.MILLISECONDS.sleep(sleepMs);
sleepMs = min(5000, sleepMs * 2);
}
addAsync in interface Ringbuffer<E>item - the item to addoverflowPolicy - the OverflowPolicy to use.
public E readOne(long sequence)
throws InterruptedException
Ringbuffer
Ringbuffer<String> ringbuffer = hz.getRingbuffer("rb");
long seq = ringbuffer.headSequence();
while(true){
String item = ringbuffer.readOne(seq);
seq++;
... process item
}
This method is not destructive unlike e.g. a queue.take. So the same item can be read by multiple readers or it can be
read multiple times by the same reader.
Currently it isn't possible to control how long this call is going to block. In the future we could add e.g.
tryReadOne(long sequence, long timeout, TimeUnit unit).
readOne in interface Ringbuffer<E>sequence - the sequence of the item to read.
InterruptedException - todo
public ICompletableFuture<Long> addAllAsync(Collection<? extends E> collection,
OverflowPolicy overflowPolicy)
RingbufferRingbuffer.add(Object) due to better io utilization and a reduced number
of executed operations.
If the batch is empty, the call is ignored.
When the collection is not empty, the content is copied into a different data-structure. This means that:
addAllAsync in interface Ringbuffer<E>collection - the batch of items to add.
public ICompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence,
int minCount,
int maxCount,
IFunction<E,Boolean> filter)
Ringbuffer
readManyAsync in interface Ringbuffer<E>startSequence - the startSequence of the first item to read.minCount - the minimum number of items to read.maxCount - the maximum number of items to read.
public String toString()
toString in class AbstractDistributedObject<RingbufferService>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||