Package org.jgroups.protocols
Class COUNTER.SyncCounterImpl
java.lang.Object
org.jgroups.protocols.COUNTER.SyncCounterImpl
- All Implemented Interfaces:
BaseCounter,Counter,SyncCounter
- Enclosing class:
COUNTER
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongaddAndGet(long delta) Atomically adds the given value to the current value.async()Returns anAsyncCounterwrapper for this instance.longcompareAndSwap(long expect, long update) Atomically updates the counter using a compare-and-swap operation.longget()Gets the current value of the countergetName()voidset(long new_value) Sets the counter to a new valuetoString()<T extends Streamable>
Tupdate(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.SyncCounter
compareAndSet, decrementAndGet, incrementAndGet, sync
-
Field Details
-
counter
-
-
Constructor Details
-
SyncCounterImpl
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceBaseCounter- Returns:
- The counter's name.
-
get
public long get()Description copied from interface:SyncCounterGets the current value of the counter- Specified by:
getin interfaceSyncCounter- Returns:
- The current value
-
set
public void set(long new_value) Description copied from interface:SyncCounterSets the counter to a new value- Specified by:
setin interfaceSyncCounter- Parameters:
new_value- The new value
-
compareAndSwap
public long compareAndSwap(long expect, long update) Description copied from interface:SyncCounterAtomically updates the counter using a compare-and-swap operation.- Specified by:
compareAndSwapin interfaceCounter- Specified by:
compareAndSwapin interfaceSyncCounter- Parameters:
expect- The expected value of the counterupdate- The new value of the counter- Returns:
- The previous value of the counter
-
addAndGet
public long addAndGet(long delta) Description copied from interface:SyncCounterAtomically adds the given value to the current value.- Specified by:
addAndGetin interfaceSyncCounter- Parameters:
delta- the value to add- Returns:
- the updated value
-
update
Description copied from interface:SyncCounterAtomically 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.- Specified by:
updatein interfaceSyncCounter- Type Parameters:
T- The return value type.- Parameters:
updateFunction- The updateCounterFunction.- Returns:
- The function's return value.
- See Also:
-
async
Description copied from interface:BaseCounterReturns anAsyncCounterwrapper for this instance. If this counter is already asynchronous, then this counter instance is returned (no-op)- Specified by:
asyncin interfaceBaseCounter- Specified by:
asyncin interfaceCounter- Returns:
- The
AsyncCounterinstance.
-
toString
-