Package org.infinispan.counter.api
Interface WeakCounter
-
public interface WeakCounterA 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.Note: the reset operation is not atomic.
- Since:
- 9.0
- Author:
- Pedro Ruivo
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CompletableFuture<Void>add(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>decrement()Decrements the counter.CounterConfigurationgetConfiguration()StringgetName()longgetValue()It returns the counter's value.default CompletableFuture<Void>increment()Increments the counter.CompletableFuture<Void>remove()It removes this counter from the cluster.CompletableFuture<Void>reset()Resets the counter to its initial value.SyncWeakCountersync()It returns a synchronous weak counter for this instance.
-
-
-
Method Detail
-
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
default CompletableFuture<Void> increment()
Increments the counter.
-
decrement
default CompletableFuture<Void> decrement()
Decrements the counter.
-
add
CompletableFuture<Void> add(long delta)
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
<T extends CounterListener> Handle<T> addListener(T listener)
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.
-
-