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 longaddAndGet(long delta)Atomically adds the given value to the current value.default booleancompareAndSet(long expect, long update)Atomically updates the counter using a CAS operationlongcompareAndSwap(long expect, long update)Atomically updates the counter using a compare-and-swap operation.default longdecrementAndGet()Atomically decrements the counter and returns the new valuelongget()Gets the current value of the counterdefault longincrementAndGet()Atomically increments the counter and returns the new valuevoidset(long new_value)Sets the counter to a new valuedefault SyncCountersync()Returns aSyncCounterwrapper 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
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 theSyncCounter.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 function's return value.
- See Also:
CounterFunction,CounterView,LongSizeStreamable
-
sync
default 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;
-
-