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.String
name
-
Constructor Summary
Constructors Modifier Constructor Description protected
CounterImpl(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.String
getName()
java.util.concurrent.CompletableFuture<java.lang.Void>
set(long new_value)
Sets the counter to a new value.SyncCounter
sync()
Returns aSyncCounter
wrapper for this instance.java.lang.String
toString()
<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:
getName
in interfaceBaseCounter
- Returns:
- The counter's name.
-
set
public java.util.concurrent.CompletableFuture<java.lang.Void> set(long new_value)
Description copied from interface:AsyncCounter
Sets the counter to a new value.- Specified by:
set
in interfaceAsyncCounter
- Returns:
- A
CompletionStage
that 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:AsyncCounter
Atomically updates the counter using a compare-and-swap operation.- Specified by:
compareAndSwap
in interfaceAsyncCounter
- Parameters:
expect
- The expected value of the counterupdate
- The new value of the counter- Returns:
- A
CompletionStage
that is completed with the current counter's value.
-
addAndGet
public java.util.concurrent.CompletableFuture<java.lang.Long> addAndGet(long delta)
Description copied from interface:AsyncCounter
Atomically adds the given value to the current value.- Specified by:
addAndGet
in interfaceAsyncCounter
- Parameters:
delta
- the value to add- Returns:
- A
CompletionStage
that 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:AsyncCounter
Atomically updates the counter's value.Both
CounterFunction
and return value must implementStreamable
to be sent over the network. The function should not block thread since it can cause deadlocks neither invoke any operation over theAsyncCounter
.The
CounterView
is a copy of the counter's value and the lastCounterView.set(long)
will be applied to the counter.- Specified by:
update
in interfaceAsyncCounter
- Type Parameters:
T
- The return value type.- Parameters:
updateFunction
- The updateCounterFunction
.- Returns:
- The
CompletionStage
which will be completed with theCounterFunction
return value. - See Also:
CounterFunction
,CounterView
,LongSizeStreamable
-
sync
public SyncCounter sync()
Description copied from interface:BaseCounter
Returns aSyncCounter
wrapper for this instance. If this counter is already synchronous, then this counter instance is returned (no-op)- Specified by:
sync
in interfaceBaseCounter
- Returns:
- The
SyncCounter
instance;
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-