Package org.onosproject.store.primitives
Class DefaultAtomicValue<V>
- java.lang.Object
-
- org.onosproject.store.service.Synchronous<AsyncAtomicValue<V>>
-
- org.onosproject.store.primitives.DefaultAtomicValue<V>
-
- Type Parameters:
V- value type
- All Implemented Interfaces:
AtomicValue<V>,DistributedPrimitive
public class DefaultAtomicValue<V> extends Synchronous<AsyncAtomicValue<V>> implements AtomicValue<V>
Default implementation for aAtomicValuebacked by aAsyncAtomicValue.
-
-
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 DefaultAtomicValue(AsyncAtomicValue<V> asyncValue, long operationTimeoutMillis)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(AtomicValueEventListener<V> listener)Registers the specified listener to be notified whenever the atomic value is updated.booleancompareAndSet(V expect, V update)Atomically sets the value to the given updated value if the current value is equal to the expected value.Vget()Gets the current value.VgetAndSet(V value)Atomically sets to the given value and returns the old value.voidremoveListener(AtomicValueEventListener<V> listener)Unregisters the specified listener such that it will no longer receive atomic value update notifications.voidset(V value)Sets to the given 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.AtomicValue
primitiveType
-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Constructor Detail
-
DefaultAtomicValue
public DefaultAtomicValue(AsyncAtomicValue<V> asyncValue, long operationTimeoutMillis)
-
-
Method Detail
-
compareAndSet
public boolean compareAndSet(V expect, V update)
Description copied from interface:AtomicValueAtomically sets the value to the given updated value if the current value is equal to the expected value.IMPORTANT: Equality is based on the equality of the serialized byte[] representations.
- Specified by:
compareAndSetin interfaceAtomicValue<V>- Parameters:
expect- the expected valueupdate- the new value- Returns:
- true if successful. false return indicates that the actual value was not equal to the expected value.
-
get
public V get()
Description copied from interface:AtomicValueGets the current value.- Specified by:
getin interfaceAtomicValue<V>- Returns:
- current value
-
getAndSet
public V getAndSet(V value)
Description copied from interface:AtomicValueAtomically sets to the given value and returns the old value.- Specified by:
getAndSetin interfaceAtomicValue<V>- Parameters:
value- the new value- Returns:
- previous value
-
set
public void set(V value)
Description copied from interface:AtomicValueSets to the given value.- Specified by:
setin interfaceAtomicValue<V>- Parameters:
value- new value
-
addListener
public void addListener(AtomicValueEventListener<V> listener)
Description copied from interface:AtomicValueRegisters the specified listener to be notified whenever the atomic value is updated.- Specified by:
addListenerin interfaceAtomicValue<V>- Parameters:
listener- listener to notify about events
-
removeListener
public void removeListener(AtomicValueEventListener<V> listener)
Description copied from interface:AtomicValueUnregisters the specified listener such that it will no longer receive atomic value update notifications.- Specified by:
removeListenerin interfaceAtomicValue<V>- Parameters:
listener- listener to unregister
-
-