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 aAtomicCounter
backed 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 long
addAndGet(long delta)
Atomically adds the given value to the current value.boolean
compareAndSet(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.long
get()
Returns the current value of the counter without modifying it.long
getAndAdd(long delta)
Atomically adds the given value to the current value.long
getAndIncrement()
Atomically increment by one the current value.long
incrementAndGet()
Atomically increment by one the current value.void
set(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:AtomicCounter
Atomically increment by one the current value.- Specified by:
incrementAndGet
in interfaceAtomicCounter
- Returns:
- updated value
-
getAndIncrement
public long getAndIncrement()
Description copied from interface:AtomicCounter
Atomically increment by one the current value.- Specified by:
getAndIncrement
in interfaceAtomicCounter
- Returns:
- previous value
-
getAndAdd
public long getAndAdd(long delta)
Description copied from interface:AtomicCounter
Atomically adds the given value to the current value.- Specified by:
getAndAdd
in interfaceAtomicCounter
- Parameters:
delta
- the value to add- Returns:
- previous value
-
addAndGet
public long addAndGet(long delta)
Description copied from interface:AtomicCounter
Atomically adds the given value to the current value.- Specified by:
addAndGet
in interfaceAtomicCounter
- Parameters:
delta
- the value to add- Returns:
- updated value
-
set
public void set(long value)
Description copied from interface:AtomicCounter
Atomically sets the given value to the current value.- Specified by:
set
in interfaceAtomicCounter
- Parameters:
value
- the value to set
-
compareAndSet
public boolean compareAndSet(long expectedValue, long updateValue)
Description copied from interface:AtomicCounter
Atomically sets the given counter to the updated value if the current value is the expected value, otherwise no change occurs.- Specified by:
compareAndSet
in 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:AtomicCounter
Returns the current value of the counter without modifying it.- Specified by:
get
in interfaceAtomicCounter
- Returns:
- current value
-
-