Package org.infinispan.counter.api
Interface WeakCounter
public interface WeakCounter
A weak consistent counter interface.
This interface represents a weak counter in the way that the write operations does not return a consistent results.
In this way, all the writes return a CompletableFuture<Void>.
Note: the reset operation is not atomic.
- Since:
- 9.0
- Author:
- Pedro Ruivo
-
Method Summary
Modifier and TypeMethodDescriptionadd(long delta) Adds the given value to the new value.<T extends CounterListener>
Handle<T>addListener(T listener) Adds aCounterListenerto this counter.default CompletableFuture<Void>Decrements the counter.getName()longgetValue()It returns the counter's value.default CompletableFuture<Void>Increments the counter.remove()It removes this counter from the cluster.reset()Resets the counter to its initial value.sync()It returns a synchronous weak counter for this instance.
-
Method Details
-
getName
String getName()- Returns:
- The counter name.
-
getValue
long getValue()It returns the counter's value.This value may be not the mot up-to-data value.
- Returns:
- The counter's value.
-
increment
Increments the counter. -
decrement
Decrements the counter. -
add
Adds the given value to the new value.- Parameters:
delta- the value to add.
-
reset
CompletableFuture<Void> reset()Resets the counter to its initial value. -
addListener
Adds aCounterListenerto this counter.- Type Parameters:
T- The type of the listener. It must implementCounterListener.- Parameters:
listener- The listener to add.- Returns:
- A
Handlethat allows to remove the listener viaHandle.remove()()}.
-
getConfiguration
CounterConfiguration getConfiguration()- Returns:
- the
CounterConfigurationused by this counter.
-
remove
CompletableFuture<Void> remove()It removes this counter from the cluster.Note that it doesn't remove the counter from the
CounterManager. If you want to remove the counter from theCounterManageruseCounterManager.remove(String).- Returns:
- The
CompletableFuturethat is completed when the counter is removed from the cluster.
-
sync
SyncWeakCounter sync()It returns a synchronous weak counter for this instance.- Returns:
- a
SyncWeakCounter.
-