Package org.jgroups.protocols
Class COUNTER.CounterImpl
- java.lang.Object
-
- org.jgroups.protocols.COUNTER.CounterImpl
-
- All Implemented Interfaces:
AsyncCounter,BaseCounter
- Enclosing class:
- COUNTER
protected class COUNTER.CounterImpl extends java.lang.Object implements AsyncCounter
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringname
-
Constructor Summary
Constructors Modifier Constructor Description protectedCounterImpl(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Long>addAndGet(long delta)Atomically adds the given value to the current value.java.util.concurrent.CompletableFuture<java.lang.Long>compareAndSwap(long expect, long update)Atomically updates the counter using a compare-and-swap operation.java.lang.StringgetName()java.util.concurrent.CompletableFuture<java.lang.Void>set(long new_value)Sets the counter to a new value.SyncCountersync()Returns aSyncCounterwrapper for this instance.java.lang.StringtoString()<T extends Streamable>
java.util.concurrent.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, wait
-
Methods inherited from interface org.jgroups.blocks.atomic.AsyncCounter
async, compareAndSet, decrementAndGet, get, incrementAndGet
-
-
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceBaseCounter- Returns:
- The counter's name.
-
set
public java.util.concurrent.CompletableFuture<java.lang.Void> set(long new_value)
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
public java.util.concurrent.CompletableFuture<java.lang.Long> compareAndSwap(long expect, long update)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
public java.util.concurrent.CompletableFuture<java.lang.Long> addAndGet(long delta)
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
public <T extends Streamable> java.util.concurrent.CompletionStage<T> update(CounterFunction<T> updateFunction)
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:
CounterFunction,CounterView,LongSizeStreamable
-
sync
public SyncCounter 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-