Package org.infinispan.api.sync
Interface SyncStrongCounter
public interface SyncStrongCounter
- Since:
- 14.0
-
Method Summary
Modifier and TypeMethodDescriptionlong
addAndGet
(long delta) Atomically adds the given value and return the new value.default boolean
compareAndSet
(long expect, long update) Atomically sets the value to the given updated value if the current value==
the expected value.long
compareAndSwap
(long expect, long update) Atomically sets the value to the given updated value if the current value==
the expected value.Return the container of this counterdefault long
Atomically decrements the counter and returns the new valuelong
getAndSet
(long value) Atomically sets the value to the given updated valuedefault long
Atomically increments the counter and returns the new value.listen
(Consumer<CounterEvent> listener) Registers aConsumer<CounterEvent>
to this counter.name()
reset()
Resets the counter to its initial value.long
value()
It fetches the current value.
-
Method Details
-
name
String name() -
container
SyncContainer container()Return the container of this counter- Returns:
-
value
long value()It fetches the current value.It may go remotely to fetch the current value.
- Returns:
- The current value.
-
incrementAndGet
default long incrementAndGet()Atomically increments the counter and returns the new value.- Returns:
- The new value.
-
decrementAndGet
default long decrementAndGet()Atomically decrements the counter and returns the new value- Returns:
- The new value.
-
addAndGet
long addAndGet(long delta) Atomically adds the given value and return the new value.- Parameters:
delta
- The non-zero value to add. It can be negative.- Returns:
- The new value.
-
reset
CompletableFuture<Void> reset()Resets the counter to its initial value. -
listen
Registers aConsumer<CounterEvent>
to this counter.- Parameters:
listener
- The listener to register.- Returns:
- A
AutoCloseable
that allows to remove the listener viaAutoCloseable.close()
.
-
compareAndSet
default boolean compareAndSet(long expect, long update) Atomically sets the value to the given updated value if the current value==
the expected value.It is the same as
return compareAndSwap(expect, update).thenApply(value -> value == expect);
- Parameters:
expect
- the expected valueupdate
- the new value- Returns:
true
if successful,false
otherwise.
-
compareAndSwap
long compareAndSwap(long expect, long update) Atomically sets the value to the given updated value if the current value==
the expected value.The operation is successful if the return value is equals to the expected value.
- Parameters:
expect
- the expected value.update
- the new value.- Returns:
- the previous counter's value.
-
getAndSet
long getAndSet(long value) Atomically sets the value to the given updated value- Parameters:
value
- the new value.- Returns:
- the old value of counter.
-
configuration
CounterConfiguration configuration()- Returns:
- the
CounterConfiguration
used by this counter.
-