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 aAtomicValue
backed 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 void
addListener(AtomicValueEventListener<V> listener)
Registers the specified listener to be notified whenever the atomic value is updated.boolean
compareAndSet(V expect, V update)
Atomically sets the value to the given updated value if the current value is equal to the expected value.V
get()
Gets the current value.V
getAndSet(V value)
Atomically sets to the given value and returns the old value.void
removeListener(AtomicValueEventListener<V> listener)
Unregisters the specified listener such that it will no longer receive atomic value update notifications.void
set(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:AtomicValue
Atomically 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:
compareAndSet
in 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:AtomicValue
Gets the current value.- Specified by:
get
in interfaceAtomicValue<V>
- Returns:
- current value
-
getAndSet
public V getAndSet(V value)
Description copied from interface:AtomicValue
Atomically sets to the given value and returns the old value.- Specified by:
getAndSet
in interfaceAtomicValue<V>
- Parameters:
value
- the new value- Returns:
- previous value
-
set
public void set(V value)
Description copied from interface:AtomicValue
Sets to the given value.- Specified by:
set
in interfaceAtomicValue<V>
- Parameters:
value
- new value
-
addListener
public void addListener(AtomicValueEventListener<V> listener)
Description copied from interface:AtomicValue
Registers the specified listener to be notified whenever the atomic value is updated.- Specified by:
addListener
in interfaceAtomicValue<V>
- Parameters:
listener
- listener to notify about events
-
removeListener
public void removeListener(AtomicValueEventListener<V> listener)
Description copied from interface:AtomicValue
Unregisters the specified listener such that it will no longer receive atomic value update notifications.- Specified by:
removeListener
in interfaceAtomicValue<V>
- Parameters:
listener
- listener to unregister
-
-