V
- value typepublic class DefaultAtomicValue<V> extends Synchronous<AsyncAtomicValue<V>> implements AtomicValue<V>
AtomicValue
backed by a AsyncAtomicValue
.DistributedPrimitive.Status, DistributedPrimitive.Type
DEFAULT_OPERATION_TIMEOUT_MILLIS, DEFAULT_OPERTATION_TIMEOUT_MILLIS
Constructor and Description |
---|
DefaultAtomicValue(AsyncAtomicValue<V> asyncValue,
long operationTimeoutMillis) |
Modifier and Type | Method and 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.
|
destroy, name, primitiveType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
primitiveType
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
public DefaultAtomicValue(AsyncAtomicValue<V> asyncValue, long operationTimeoutMillis)
public boolean compareAndSet(V expect, V update)
AtomicValue
IMPORTANT: Equality is based on the equality of the serialized byte[] representations.
compareAndSet
in interface AtomicValue<V>
expect
- the expected valueupdate
- the new valuepublic V get()
AtomicValue
get
in interface AtomicValue<V>
public V getAndSet(V value)
AtomicValue
getAndSet
in interface AtomicValue<V>
value
- the new valuepublic void set(V value)
AtomicValue
set
in interface AtomicValue<V>
value
- new valuepublic void addListener(AtomicValueEventListener<V> listener)
AtomicValue
addListener
in interface AtomicValue<V>
listener
- listener to notify about eventspublic void removeListener(AtomicValueEventListener<V> listener)
AtomicValue
removeListener
in interface AtomicValue<V>
listener
- listener to unregister