Package org.jgroups.protocols
Class COUNTER.CounterImpl
java.lang.Object
org.jgroups.protocols.COUNTER.CounterImpl
- All Implemented Interfaces:
AsyncCounter,BaseCounter
- Enclosing class:
COUNTER
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final String(package private) final COUNTER.SyncCounterImpl -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAndGet(long delta) Atomically adds the given value to the current value.compareAndSwap(long expect, long update) Atomically updates the counter using a compare-and-swap operation.getName()set(long new_value) Sets the counter to a new value.sync()Returns aSyncCounterwrapper for this instance.toString()<T extends Streamable>
CompletionStage<T> update(CounterFunction<T> updateFunction) Atomically updates the counter's value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jgroups.blocks.atomic.AsyncCounter
async, compareAndSet, decrementAndGet, get, incrementAndGet
-
Field Details
-
name
-
sync
-
-
Constructor Details
-
CounterImpl
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceBaseCounter- Returns:
- The counter's name.
-
set
Description copied from interface:AsyncCounterSets the counter to a new value.- Specified by:
setin interfaceAsyncCounter- Returns:
- A
CompletionStagethat is completed with the counter's value is updated.
-
compareAndSwap
Description copied from interface:AsyncCounterAtomically updates the counter using a compare-and-swap operation.- Specified by:
compareAndSwapin interfaceAsyncCounter- 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.
-
addAndGet
Description copied from interface:AsyncCounterAtomically adds the given value to the current value.- Specified by:
addAndGetin interfaceAsyncCounter- Parameters:
delta- the value to add- Returns:
- A
CompletionStagethat is completed with the updated counter's value.
-
update
Description copied from interface:AsyncCounterAtomically 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.- Specified by:
updatein interfaceAsyncCounter- Type Parameters:
T- The return value type.- Parameters:
updateFunction- The updateCounterFunction.- Returns:
- The
CompletionStagewhich will be completed with theCounterFunctionreturn value. - See Also:
-
sync
Description copied from interface:BaseCounterReturns aSyncCounterwrapper for this instance. If this counter is already synchronous, then this counter instance is returned (no-op)- Specified by:
syncin interfaceBaseCounter- Returns:
- The
SyncCounterinstance;
-
toString
-