Class AsyncRemoteAtomicInteger
- java.lang.Object
-
- com.oracle.coherence.concurrent.atomic.AsyncRemoteAtomicInteger
-
- All Implemented Interfaces:
AsyncAtomicInteger
public class AsyncRemoteAtomicInteger extends Object implements AsyncAtomicInteger
The remote implementation ofAsyncAtomicInteger, backed by a CoherenceNamedMapentry.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
localimplementation.- Since:
- 21.12
- Author:
- Aleks Seovic 2020.12.07
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAsyncRemoteAtomicInteger(AsyncNamedMap<String,AtomicInteger> mapAtomic, String sName)Constructs a newAsyncRemoteAtomicInteger.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Integer>accumulateAndGet(int nUpdate, Remote.IntBinaryOperator 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<Integer>accumulateAndGet(int nUpdate, IntBinaryOperator 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<Integer>addAndGet(int nDelta)Atomically adds the given value to the current value.CompletableFuture<Byte>byteValue()Returns the current value of thisAsyncAtomicIntegeras abyteafter a narrowing primitive conversion.CompletableFuture<Integer>compareAndExchange(int nExpectedValue, int nNewValue)Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.CompletableFuture<Boolean>compareAndSet(int nExpectedValue, int nNewValue)Atomically sets the value tonewValueif the current value== expectedValue.CompletableFuture<Integer>decrementAndGet()Atomically decrements the current value.CompletableFuture<Double>doubleValue()Returns the current value of thisAsyncAtomicIntegeras adoubleafter a widening primitive conversion.CompletableFuture<Float>floatValue()Returns the current value of thisAsyncAtomicIntegeras afloatafter a widening primitive conversion.CompletableFuture<Integer>get()Returns the current value.CompletableFuture<Integer>getAndAccumulate(int nUpdate, Remote.IntBinaryOperator 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<Integer>getAndAccumulate(int nUpdate, IntBinaryOperator 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<Integer>getAndAdd(int nDelta)Atomically adds the given value to the current value.CompletableFuture<Integer>getAndDecrement()Atomically decrements the current value.CompletableFuture<Integer>getAndIncrement()Atomically increments the current value.CompletableFuture<Integer>getAndSet(int nNewValue)Atomically sets the value tonewValueand returns the old value.CompletableFuture<Integer>getAndUpdate(Remote.IntUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the previous value.CompletableFuture<Integer>getAndUpdate(IntUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the previous value.CompletableFuture<Integer>incrementAndGet()Atomically increments the current value.CompletableFuture<Integer>intValue()Returns the current value of thisAsyncAtomicIntegeras anint.protected <R> CompletableFuture<R>invoke(Remote.Function<AtomicInteger,R> function)Apply specified function against the remote object and return the result.protected <R> CompletableFuture<R>invoke(Remote.Function<AtomicInteger,R> function, boolean fMutate)Apply specified function against the remote object and return the result.CompletableFuture<Long>longValue()Returns the current value of thisAsyncAtomicIntegeras alongafter a widening primitive conversion.CompletableFuture<Void>set(int nNewValue)Sets the value tonewValue.CompletableFuture<Short>shortValue()Returns the current value of thisAsyncAtomicIntegeras ashortafter a narrowing primitive conversion.StringtoString()Returns the String representation of the current value.CompletableFuture<Integer>updateAndGet(Remote.IntUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the updated value.CompletableFuture<Integer>updateAndGet(IntUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the updated value.
-
-
-
Constructor Detail
-
AsyncRemoteAtomicInteger
protected AsyncRemoteAtomicInteger(AsyncNamedMap<String,AtomicInteger> mapAtomic, String sName)
Constructs a newAsyncRemoteAtomicInteger.- Parameters:
mapAtomic- the map that holds this atomic valuesName- the name of this atomic value
-
-
Method Detail
-
get
public CompletableFuture<Integer> get()
Description copied from interface:AsyncAtomicIntegerReturns the current value.- Specified by:
getin interfaceAsyncAtomicInteger- Returns:
- the current value
-
set
public CompletableFuture<Void> set(int nNewValue)
Description copied from interface:AsyncAtomicIntegerSets the value tonewValue.- Specified by:
setin interfaceAsyncAtomicInteger- Parameters:
nNewValue- the new value- Returns:
- a
CompletableFuturethat can be used to determine whether the operation completed
-
getAndSet
public CompletableFuture<Integer> getAndSet(int nNewValue)
Description copied from interface:AsyncAtomicIntegerAtomically sets the value tonewValueand returns the old value.- Specified by:
getAndSetin interfaceAsyncAtomicInteger- Parameters:
nNewValue- the new value- Returns:
- the previous value
-
compareAndSet
public CompletableFuture<Boolean> compareAndSet(int nExpectedValue, int nNewValue)
Description copied from interface:AsyncAtomicIntegerAtomically sets the value tonewValueif the current value== expectedValue.- Specified by:
compareAndSetin interfaceAsyncAtomicInteger- Parameters:
nExpectedValue- the expected valuenNewValue- the new value- Returns:
trueif successful. False return indicates that the actual value was not equal to the expected value.
-
getAndIncrement
public CompletableFuture<Integer> getAndIncrement()
Description copied from interface:AsyncAtomicIntegerAtomically increments the current value.Equivalent to
getAndAdd(1).- Specified by:
getAndIncrementin interfaceAsyncAtomicInteger- Returns:
- the previous value
-
getAndDecrement
public CompletableFuture<Integer> getAndDecrement()
Description copied from interface:AsyncAtomicIntegerAtomically decrements the current value.Equivalent to
getAndAdd(-1).- Specified by:
getAndDecrementin interfaceAsyncAtomicInteger- Returns:
- the previous value
-
getAndAdd
public CompletableFuture<Integer> getAndAdd(int nDelta)
Description copied from interface:AsyncAtomicIntegerAtomically adds the given value to the current value.- Specified by:
getAndAddin interfaceAsyncAtomicInteger- Parameters:
nDelta- the value to add- Returns:
- the previous value
-
incrementAndGet
public CompletableFuture<Integer> incrementAndGet()
Description copied from interface:AsyncAtomicIntegerAtomically increments the current value.Equivalent to
addAndGet(1).- Specified by:
incrementAndGetin interfaceAsyncAtomicInteger- Returns:
- the updated value
-
decrementAndGet
public CompletableFuture<Integer> decrementAndGet()
Description copied from interface:AsyncAtomicIntegerAtomically decrements the current value.Equivalent to
addAndGet(-1).- Specified by:
decrementAndGetin interfaceAsyncAtomicInteger- Returns:
- the updated value
-
addAndGet
public CompletableFuture<Integer> addAndGet(int nDelta)
Description copied from interface:AsyncAtomicIntegerAtomically adds the given value to the current value.- Specified by:
addAndGetin interfaceAsyncAtomicInteger- Parameters:
nDelta- the value to add- Returns:
- the updated value
-
getAndUpdate
public CompletableFuture<Integer> getAndUpdate(Remote.IntUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
public CompletableFuture<Integer> getAndUpdate(IntUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
public CompletableFuture<Integer> updateAndGet(Remote.IntUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
public CompletableFuture<Integer> updateAndGet(IntUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
public CompletableFuture<Integer> getAndAccumulate(int nUpdate, Remote.IntBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
nUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
public CompletableFuture<Integer> getAndAccumulate(int nUpdate, IntBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
nUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
public CompletableFuture<Integer> accumulateAndGet(int nUpdate, Remote.IntBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
nUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
public CompletableFuture<Integer> accumulateAndGet(int nUpdate, IntBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicIntegerAtomically 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 interfaceAsyncAtomicInteger- Parameters:
nUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
public CompletableFuture<Integer> compareAndExchange(int nExpectedValue, int nNewValue)
Description copied from interface:AsyncAtomicIntegerAtomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.- Specified by:
compareAndExchangein interfaceAsyncAtomicInteger- Parameters:
nExpectedValue- the expected valuenNewValue- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
intValue
public CompletableFuture<Integer> intValue()
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras anint.- Specified by:
intValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object
-
longValue
public CompletableFuture<Long> longValue()
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras alongafter a widening primitive conversion.- Specified by:
longValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object after conversion
to type
long
-
floatValue
public CompletableFuture<Float> floatValue()
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras afloatafter a widening primitive conversion.- Specified by:
floatValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object after conversion
to type
float
-
doubleValue
public CompletableFuture<Double> doubleValue()
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras adoubleafter a widening primitive conversion.- Specified by:
doubleValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object after conversion
to type
double
-
byteValue
public CompletableFuture<Byte> byteValue()
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras abyteafter a narrowing primitive conversion.- Specified by:
byteValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object after conversion
to type
byte
-
shortValue
public CompletableFuture<Short> shortValue()
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras ashortafter a narrowing primitive conversion.- Specified by:
shortValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object after conversion
to type
short
-
toString
public String toString()
Returns the String representation of the current value.
-
invoke
protected <R> CompletableFuture<R> invoke(Remote.Function<AtomicInteger,R> function)
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<AtomicInteger,R> function, boolean fMutate)
Apply specified function against the remote object and return the result.If the
fMutateargument 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
-
-