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 aCounterListener
to this counter.default CompletableFuture
<Void> Decrements the counter.getName()
long
getValue()
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 aCounterListener
to this counter.- Type Parameters:
T
- The type of the listener. It must implementCounterListener
.- Parameters:
listener
- The listener to add.- Returns:
- A
Handle
that allows to remove the listener viaHandle.remove()
()}.
-
getConfiguration
CounterConfiguration getConfiguration()- Returns:
- the
CounterConfiguration
used 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 theCounterManager
useCounterManager.remove(String)
.- Returns:
- The
CompletableFuture
that 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
.
-