Class AsyncLocalAtomicReference<V>
- java.lang.Object
-
- com.oracle.coherence.concurrent.atomic.AsyncLocalAtomicReference<V>
-
- Type Parameters:
V- the type of object referred to by this reference
- All Implemented Interfaces:
AsyncAtomicReference<V>
public class AsyncLocalAtomicReference<V> extends Object implements AsyncAtomicReference<V>
Local implementation ofAsyncAtomicReferenceinterface, that simply wrapsjava.util.concurrent.atomic.AtomicReferenceinstance and returns an already completed future from each method.- Author:
- Aleks Seovic 2020.12.08
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAsyncLocalAtomicReference(AtomicReference<V> value)ConstructLocalAtomicReference<V>instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<V>accumulateAndGet(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.CompletableFuture<V>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.CompletableFuture<V>compareAndExchange(V expectedValue, V newValue)Atomically sets the value tonewValueif the current value, referred to as the witness value, is equal to theexpectedValue.CompletableFuture<Boolean>compareAndSet(V expectedValue, V newValue)Atomically sets the value tonewValueif the current value is equal to theexpectedValue.CompletableFuture<V>get()Returns the current value.CompletableFuture<V>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.CompletableFuture<V>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.CompletableFuture<V>getAndSet(V newValue)Atomically sets the value tonewValueand returns the old value.CompletableFuture<V>getAndUpdate(Remote.UnaryOperator<V> updateFunction)Atomically updates the current value with the results of applying the given function, returning the previous value.CompletableFuture<V>getAndUpdate(UnaryOperator<V> updateFunction)Atomically updates the current value with the results of applying the given function, returning the previous value.CompletableFuture<Void>set(V newValue)Sets the value tonewValue.StringtoString()Returns the String representation of the current value.CompletableFuture<V>updateAndGet(Remote.UnaryOperator<V> updateFunction)Atomically updates the current value with the results of applying the given function, returning the updated value.CompletableFuture<V>updateAndGet(UnaryOperator<V> updateFunction)Atomically updates the current value with the results of applying the given function, returning the updated value.
-
-
-
Constructor Detail
-
AsyncLocalAtomicReference
protected AsyncLocalAtomicReference(AtomicReference<V> value)
ConstructLocalAtomicReference<V>instance.- Parameters:
value- wrapped value
-
-
Method Detail
-
get
public CompletableFuture<V> get()
Description copied from interface:AsyncAtomicReferenceReturns the current value.- Specified by:
getin interfaceAsyncAtomicReference<V>- Returns:
- the current value
-
set
public CompletableFuture<Void> set(V newValue)
Description copied from interface:AsyncAtomicReferenceSets the value tonewValue.- Specified by:
setin interfaceAsyncAtomicReference<V>- Parameters:
newValue- the new value- Returns:
- a
CompletableFuturethat can be used to determine whether the operation completed
-
getAndSet
public CompletableFuture<V> getAndSet(V newValue)
Description copied from interface:AsyncAtomicReferenceAtomically sets the value tonewValueand returns the old value.- Specified by:
getAndSetin interfaceAsyncAtomicReference<V>- Parameters:
newValue- the new value- Returns:
- the previous value
-
compareAndSet
public CompletableFuture<Boolean> compareAndSet(V expectedValue, V newValue)
Description copied from interface:AsyncAtomicReferenceAtomically sets the value tonewValueif the current value is equal to theexpectedValue.- Specified by:
compareAndSetin interfaceAsyncAtomicReference<V>- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
trueif successful. False return indicates that the actual value was not equal to the expected value.
-
getAndUpdate
public CompletableFuture<V> getAndUpdate(Remote.UnaryOperator<V> updateFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
getAndUpdatein interfaceAsyncAtomicReference<V>- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
public CompletableFuture<V> getAndUpdate(UnaryOperator<V> updateFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
getAndUpdatein interfaceAsyncAtomicReference<V>- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
public CompletableFuture<V> updateAndGet(Remote.UnaryOperator<V> updateFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
updateAndGetin interfaceAsyncAtomicReference<V>- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
public CompletableFuture<V> updateAndGet(UnaryOperator<V> updateFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
updateAndGetin interfaceAsyncAtomicReference<V>- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
public CompletableFuture<V> getAndAccumulate(V x, Remote.BinaryOperator<V> accumulatorFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
getAndAccumulatein interfaceAsyncAtomicReference<V>- Parameters:
x- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
public CompletableFuture<V> getAndAccumulate(V x, BinaryOperator<V> accumulatorFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
getAndAccumulatein interfaceAsyncAtomicReference<V>- Parameters:
x- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
public CompletableFuture<V> accumulateAndGet(V x, Remote.BinaryOperator<V> accumulatorFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
accumulateAndGetin interfaceAsyncAtomicReference<V>- Parameters:
x- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
public CompletableFuture<V> accumulateAndGet(V x, BinaryOperator<V> accumulatorFunction)
Description copied from interface:AsyncAtomicReferenceAtomically 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:
accumulateAndGetin interfaceAsyncAtomicReference<V>- Parameters:
x- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
public CompletableFuture<V> compareAndExchange(V expectedValue, V newValue)
Description copied from interface:AsyncAtomicReferenceAtomically sets the value tonewValueif the current value, referred to as the witness value, is equal to theexpectedValue.- Specified by:
compareAndExchangein 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
-
-