Package org.jgroups.blocks.atomic
Interface SyncCounter
-
- All Superinterfaces:
BaseCounter
- All Known Subinterfaces:
Counter
public interface SyncCounter extends BaseCounter
A synchronous counter interface- Since:
- 5.2
- Author:
- Bela Ban, Pedro Ruivo
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description long
addAndGet(long delta)
Atomically adds the given value to the current value.default boolean
compareAndSet(long expect, long update)
Atomically updates the counter using a CAS operationlong
compareAndSwap(long expect, long update)
Atomically updates the counter using a compare-and-swap operation.default long
decrementAndGet()
Atomically decrements the counter and returns the new valuelong
get()
Gets the current value of the counterdefault long
incrementAndGet()
Atomically increments the counter and returns the new valuevoid
set(long new_value)
Sets the counter to a new valuedefault SyncCounter
sync()
Returns aSyncCounter
wrapper for this instance.default <T extends Streamable>
Tupdate(CounterFunction<T> updateFunction)
Atomically updates the counter's value.-
Methods inherited from interface org.jgroups.blocks.atomic.BaseCounter
async, getName
-
-
-
-
Method Detail
-
get
long get()
Gets the current value of the counter- Returns:
- The current value
-
set
void set(long new_value)
Sets the counter to a new value- Parameters:
new_value
- The new value
-
compareAndSet
default boolean compareAndSet(long expect, long update)
Atomically updates the counter using a CAS operation- Parameters:
expect
- The expected value of the counterupdate
- The new value of the counter- Returns:
- True if the counter could be updated, false otherwise
-
compareAndSwap
long compareAndSwap(long expect, long update)
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:
- The previous value of the counter
-
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 to the current value.- Parameters:
delta
- the value to add- Returns:
- the updated value
-
update
default <T extends Streamable> T update(CounterFunction<T> updateFunction)
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 theSyncCounter
.The
CounterView
is 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 function's return value.
- See Also:
CounterFunction
,CounterView
,LongSizeStreamable
-
sync
default 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;
-
-