Class AsyncRemoteAtomicReference<V>
- Type Parameters:
V
- the type of object referred to by this reference
- All Implemented Interfaces:
AsyncAtomicReference<V>
AsyncAtomicReference
, backed by a
Coherence NamedMap
entry.
Every method in this class is guaranteed to execute effectively-once, and provides
cluster-wide atomicity guarantees for the backing atomic value. However,
keep in mind that this comes at a significant cost -- each method invocation
results in a network call to a remote owner of the backing atomic value,
which means that each operation has significantly higher latency than a
corresponding local
implementation.
- Since:
- 21.12
- Author:
- Aleks Seovic 2020.12.08
-
Constructor Summary
ModifierConstructorDescriptionprotected
AsyncRemoteAtomicReference
(AsyncNamedMap<String, AtomicReference<V>> mapAtomic, String sName) Constructs a newAsyncRemoteAtomicReference
. -
Method Summary
Modifier and TypeMethodDescriptionaccumulateAndGet
(V x, Remote.BinaryOperator<V> accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.accumulateAndGet
(V x, BinaryOperator<V> accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.compareAndExchange
(V expectedValue, V newValue) Atomically sets the value tonewValue
if the current value, referred to as the witness value, is equal to theexpectedValue
.compareAndSet
(V expectedValue, V newValue) Atomically sets the value tonewValue
if the current value is equal to theexpectedValue
.get()
Returns the current value.getAndAccumulate
(V x, Remote.BinaryOperator<V> accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.getAndAccumulate
(V x, BinaryOperator<V> accumulatorFunction) Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.Atomically sets the value tonewValue
and returns the old value.getAndUpdate
(Remote.UnaryOperator<V> updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.getAndUpdate
(UnaryOperator<V> updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.protected <R> CompletableFuture
<R> invoke
(Remote.Function<AtomicReference<V>, R> function) Apply specified function against the remote object and return the result.protected <R> CompletableFuture
<R> invoke
(Remote.Function<AtomicReference<V>, R> function, boolean fMutate) Apply specified function against the remote object and return the result.Sets the value tonewValue
.toString()
Returns the String representation of the current value.updateAndGet
(Remote.UnaryOperator<V> updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.updateAndGet
(UnaryOperator<V> updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.
-
Constructor Details
-
AsyncRemoteAtomicReference
protected AsyncRemoteAtomicReference(AsyncNamedMap<String, AtomicReference<V>> mapAtomic, String sName) Constructs a newAsyncRemoteAtomicReference
.- Parameters:
mapAtomic
- the map that holds this atomic valuesName
- the name of this atomic value
-
-
Method Details
-
get
Description copied from interface:AsyncAtomicReference
Returns the current value.- Specified by:
get
in interfaceAsyncAtomicReference<V>
- Returns:
- the current value
-
set
Description copied from interface:AsyncAtomicReference
Sets the value tonewValue
.- Specified by:
set
in interfaceAsyncAtomicReference<V>
- Parameters:
newValue
- the new value- Returns:
- a
CompletableFuture
that can be used to determine whether the operation completed
-
getAndSet
Description copied from interface:AsyncAtomicReference
Atomically sets the value tonewValue
and returns the old value.- Specified by:
getAndSet
in interfaceAsyncAtomicReference<V>
- Parameters:
newValue
- the new value- Returns:
- the previous value
-
compareAndSet
Description copied from interface:AsyncAtomicReference
Atomically sets the value tonewValue
if the current value is equal to theexpectedValue
.- Specified by:
compareAndSet
in interfaceAsyncAtomicReference<V>
- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
true
if successful. False return indicates that the actual value was not equal to the expected value.
-
getAndUpdate
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Specified by:
getAndUpdate
in interfaceAsyncAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Specified by:
getAndUpdate
in interfaceAsyncAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Specified by:
updateAndGet
in interfaceAsyncAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Specified by:
updateAndGet
in interfaceAsyncAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.The function should beside-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Specified by:
getAndAccumulate
in interfaceAsyncAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function to the current and given values, returning the previous value.The function should beside-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Specified by:
getAndAccumulate
in interfaceAsyncAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Specified by:
accumulateAndGet
in interfaceAsyncAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
Description copied from interface:AsyncAtomicReference
Atomically updates the current value with the results of applying the given function to the current and given values, returning the updated value.The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.
- Specified by:
accumulateAndGet
in interfaceAsyncAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
Description copied from interface:AsyncAtomicReference
Atomically sets the value tonewValue
if the current value, referred to as the witness value, is equal to theexpectedValue
.- Specified by:
compareAndExchange
in interfaceAsyncAtomicReference<V>
- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
toString
Returns the String representation of the current value. -
invoke
Apply specified function against the remote object and return the result.Any changes the function makes to the remote object will be preserved.
- Type Parameters:
R
- the type of the result- Parameters:
function
- the function to apply- Returns:
- the result of the function applied to a remote object
-
invoke
protected <R> CompletableFuture<R> invoke(Remote.Function<AtomicReference<V>, R> function, boolean fMutate) Apply specified function against the remote object and return the result.If the
fMutate
argument istrue
, any changes to the remote object will be preserved.- Type Parameters:
R
- the type of the result- Parameters:
function
- the function to applyfMutate
- flag specifying whether the function mutates the object- Returns:
- the result of the function applied to a remote object
-