Package org.jgroups.blocks.atomic
Interface AsyncCounter
- All Superinterfaces:
BaseCounter
- All Known Implementing Classes:
COUNTER.CounterImpl
An asynchronous counter interface.
- Since:
- 5.2
-
Method Summary
Modifier and TypeMethodDescriptionaddAndGet(long delta) Atomically adds the given value to the current value.default AsyncCounterasync()Returns anAsyncCounterwrapper for this instance.default CompletionStage<Boolean> compareAndSet(long expect, long update) Atomically updates the counter using a compare-and-set operation.compareAndSwap(long expect, long update) Atomically updates the counter using a compare-and-swap operation.default CompletionStage<Long> Atomically decrements the counter and returns the new valuedefault CompletionStage<Long> get()Gets the current value of the counter.default CompletionStage<Long> Atomically increments the counter and returns the new valueset(long new_value) Sets the counter to a new value.default <T extends Streamable>
CompletionStage<T> update(CounterFunction<T> updateFunction) Atomically updates the counter's value.Methods inherited from interface org.jgroups.blocks.atomic.BaseCounter
getName, sync
-
Method Details
-
get
Gets the current value of the counter.- Returns:
- A
CompletionStagethat is completed with the counter's value.
-
set
Sets the counter to a new value.- Returns:
- A
CompletionStagethat is completed with the counter's value is updated.
-
compareAndSet
Atomically updates the counter using a compare-and-set operation.- Parameters:
expect- The expected value of the counterupdate- The new value of the counter- Returns:
- A
CompletionStagethat is completed withtrueif the counter is updated andfalseotherwise.
-
compareAndSwap
Atomically updates the counter using a compare-and-swap operation.- Parameters:
expect- The expected value of the counterupdate- The new value of the counter- Returns:
- A
CompletionStagethat is completed with the current counter's value.
-
incrementAndGet
Atomically increments the counter and returns the new value- Returns:
- A
CompletionStagethat is completed with the new counter's value.
-
decrementAndGet
Atomically decrements the counter and returns the new value- Returns:
- A
CompletionStagethat is completed with the new counter's value.
-
addAndGet
Atomically adds the given value to the current value.- Parameters:
delta- the value to add- Returns:
- A
CompletionStagethat is completed with the updated counter's value.
-
update
Atomically updates the counter's value.Both
CounterFunctionand return value must implementStreamableto be sent over the network. The function should not block thread since it can cause deadlocks neither invoke any operation over theAsyncCounter.The
CounterViewis a copy of the counter's value and the lastCounterView.set(long)will be applied to the counter.- Type Parameters:
T- The return value type.- Parameters:
updateFunction- The updateCounterFunction.- Returns:
- The
CompletionStagewhich will be completed with theCounterFunctionreturn value. - See Also:
-
async
Description copied from interface:BaseCounterReturns anAsyncCounterwrapper for this instance. If this counter is already asynchronous, then this counter instance is returned (no-op)- Specified by:
asyncin interfaceBaseCounter- Returns:
- The
AsyncCounterinstance.
-