Package org.onosproject.store.primitives
Class DefaultAtomicCounter
- java.lang.Object
-
- org.onosproject.store.service.Synchronous<AsyncAtomicCounter>
-
- org.onosproject.store.primitives.DefaultAtomicCounter
-
- All Implemented Interfaces:
AtomicCounter,DistributedPrimitive
public class DefaultAtomicCounter extends Synchronous<AsyncAtomicCounter> implements AtomicCounter
Default implementation for aAtomicCounterbacked by aAsyncAtomicCounter.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitive
DistributedPrimitive.Status, DistributedPrimitive.Type
-
-
Field Summary
-
Fields inherited from interface org.onosproject.store.service.DistributedPrimitive
DEFAULT_OPERATION_TIMEOUT_MILLIS
-
-
Constructor Summary
Constructors Constructor Description DefaultAtomicCounter(AsyncAtomicCounter asyncCounter, long operationTimeoutMillis)
-
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.booleancompareAndSet(long expectedValue, long updateValue)Atomically sets the given counter to the updated value if the current value is the expected value, otherwise no change occurs.longget()Returns the current value of the counter without modifying it.longgetAndAdd(long delta)Atomically adds the given value to the current value.longgetAndIncrement()Atomically increment by one the current value.longincrementAndGet()Atomically increment by one the current value.voidset(long value)Atomically sets the given value to the current value.-
Methods inherited from class org.onosproject.store.service.Synchronous
destroy, name, primitiveType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.onosproject.store.service.AtomicCounter
primitiveType
-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Constructor Detail
-
DefaultAtomicCounter
public DefaultAtomicCounter(AsyncAtomicCounter asyncCounter, long operationTimeoutMillis)
-
-
Method Detail
-
incrementAndGet
public long incrementAndGet()
Description copied from interface:AtomicCounterAtomically increment by one the current value.- Specified by:
incrementAndGetin interfaceAtomicCounter- Returns:
- updated value
-
getAndIncrement
public long getAndIncrement()
Description copied from interface:AtomicCounterAtomically increment by one the current value.- Specified by:
getAndIncrementin interfaceAtomicCounter- Returns:
- previous value
-
getAndAdd
public long getAndAdd(long delta)
Description copied from interface:AtomicCounterAtomically adds the given value to the current value.- Specified by:
getAndAddin interfaceAtomicCounter- Parameters:
delta- the value to add- Returns:
- previous value
-
addAndGet
public long addAndGet(long delta)
Description copied from interface:AtomicCounterAtomically adds the given value to the current value.- Specified by:
addAndGetin interfaceAtomicCounter- Parameters:
delta- the value to add- Returns:
- updated value
-
set
public void set(long value)
Description copied from interface:AtomicCounterAtomically sets the given value to the current value.- Specified by:
setin interfaceAtomicCounter- Parameters:
value- the value to set
-
compareAndSet
public boolean compareAndSet(long expectedValue, long updateValue)Description copied from interface:AtomicCounterAtomically sets the given counter to the updated value if the current value is the expected value, otherwise no change occurs.- Specified by:
compareAndSetin interfaceAtomicCounter- Parameters:
expectedValue- the expected current value of the counterupdateValue- the new value to be set- Returns:
- true if the update occurred and the expected value was equal to the current value, false otherwise
-
get
public long get()
Description copied from interface:AtomicCounterReturns the current value of the counter without modifying it.- Specified by:
getin interfaceAtomicCounter- Returns:
- current value
-
-