Package org.jgroups.protocols
Class COUNTER.SyncCounterImpl
- java.lang.Object
-
- org.jgroups.protocols.COUNTER.SyncCounterImpl
-
- All Implemented Interfaces:
Counter,SyncCounter
- Enclosing class:
- COUNTER
private static class COUNTER.SyncCounterImpl extends java.lang.Object implements Counter
-
-
Field Summary
Fields Modifier and Type Field Description private AsyncCountercounter
-
Constructor Summary
Constructors Modifier Constructor Description privateSyncCounterImpl(AsyncCounter counter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddAndGet(long delta)Atomically adds the given value to the current value.AsyncCounterasync()longcompareAndSwap(long expect, long update)Atomically updates the counter using a compare-and-swap operation.longget()Gets the current value of the counterjava.lang.StringgetName()voidset(long new_value)Sets the counter to a new valuejava.lang.StringtoString()<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, wait
-
Methods inherited from interface org.jgroups.blocks.atomic.SyncCounter
compareAndSet, decrementAndGet, incrementAndGet
-
-
-
-
Field Detail
-
counter
private final AsyncCounter counter
-
-
Constructor Detail
-
SyncCounterImpl
private SyncCounterImpl(AsyncCounter counter)
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceSyncCounter
-
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
public <T extends Streamable> T update(CounterFunction<T> updateFunction)
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:
CounterFunction,CounterView,LongSizeStreamable
-
async
public AsyncCounter async()
- Specified by:
asyncin interfaceCounter- Specified by:
asyncin interfaceSyncCounter- Returns:
- an asynchronous wrapper around this instance.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-