Package org.onosproject.store.service
Interface AtomicValue<V>
-
- Type Parameters:
V
- value type
- All Superinterfaces:
DistributedPrimitive
- All Known Implementing Classes:
DefaultAtomicValue
public interface AtomicValue<V> extends DistributedPrimitive
Distributed version of java.util.concurrent.atomic.AtomicReference.
-
-
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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default 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.default DistributedPrimitive.Type
primitiveType()
Returns the type of primitive.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 interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Method Detail
-
primitiveType
default DistributedPrimitive.Type primitiveType()
Description copied from interface:DistributedPrimitive
Returns the type of primitive.- Specified by:
primitiveType
in interfaceDistributedPrimitive
- Returns:
- primitive type
-
compareAndSet
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.IMPORTANT: Equality is based on the equality of the serialized byte[] representations.
- 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
V get()
Gets the current value.- Returns:
- current value
-
getAndSet
V getAndSet(V value)
Atomically sets to the given value and returns the old value.- Parameters:
value
- the new value- Returns:
- previous value
-
set
void set(V value)
Sets to the given value.- Parameters:
value
- new value
-
addListener
void addListener(AtomicValueEventListener<V> listener)
Registers the specified listener to be notified whenever the atomic value is updated.- Parameters:
listener
- listener to notify about events
-
removeListener
void removeListener(AtomicValueEventListener<V> listener)
Unregisters the specified listener such that it will no longer receive atomic value update notifications.- Parameters:
listener
- listener to unregister
-
-