Class AsyncRemoteAtomicLong
- java.lang.Object
-
- com.oracle.coherence.concurrent.atomic.AsyncRemoteAtomicLong
-
- All Implemented Interfaces:
AsyncAtomicLong
public class AsyncRemoteAtomicLong extends Object implements AsyncAtomicLong
The remote implementation ofAsyncAtomicLong, 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.03
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAsyncRemoteAtomicLong(AsyncNamedMap<String,AtomicLong> mapAtomic, String sName)Constructs a newAsyncRemoteAtomicLong.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Long>accumulateAndGet(long lUpdate, Remote.LongBinaryOperator 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<Long>accumulateAndGet(long lUpdate, LongBinaryOperator 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<Long>addAndGet(long lDelta)Atomically adds the given value to the current value.CompletableFuture<Byte>byteValue()Returns the value of the specified number as abyte.CompletableFuture<Long>compareAndExchange(long lExpectedValue, long lNewValue)Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.CompletableFuture<Boolean>compareAndSet(long lExpectedValue, long lNewValue)Atomically sets the value tonewValueif the current value== expectedValue.CompletableFuture<Long>decrementAndGet()Atomically decrements the current value.CompletableFuture<Double>doubleValue()Returns the current value of thisDistributedAtomicLongas adoubleafter a widening primitive conversion.CompletableFuture<Float>floatValue()Returns the current value of thisDistributedAtomicLongas afloatafter a widening primitive conversion.CompletableFuture<Long>get()Returns the current value.CompletableFuture<Long>getAndAccumulate(long lUpdate, Remote.LongBinaryOperator 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<Long>getAndAccumulate(long lUpdate, LongBinaryOperator 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<Long>getAndAdd(long lDelta)Atomically adds the given value to the current value.CompletableFuture<Long>getAndDecrement()Atomically decrements the current value.CompletableFuture<Long>getAndIncrement()Atomically increments the current value.CompletableFuture<Long>getAndSet(long lNewValue)Atomically sets the value tonewValueand returns the old value.CompletableFuture<Long>getAndUpdate(Remote.LongUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the previous value.CompletableFuture<Long>getAndUpdate(LongUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the previous value.CompletableFuture<Long>incrementAndGet()Atomically increments the current value.CompletableFuture<Integer>intValue()Returns the current value of thisDistributedAtomicLongas anintafter a narrowing primitive conversion.protected <R> CompletableFuture<R>invoke(Remote.Function<AtomicLong,R> function)Apply specified function against the remote object and return the result.protected <R> CompletableFuture<R>invoke(Remote.Function<AtomicLong,R> function, boolean fMutate)Apply specified function against the remote object and return the result.CompletableFuture<Long>longValue()Returns the current value of thisDistributedAtomicLongas along.CompletableFuture<Void>set(long lNewValue)Sets the value tonewValue.CompletableFuture<Short>shortValue()Returns the value of the specified number as ashort.StringtoString()Returns the String representation of the current value.CompletableFuture<Long>updateAndGet(Remote.LongUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the updated value.CompletableFuture<Long>updateAndGet(LongUnaryOperator updateFunction)Atomically updates the current value with the results of applying the given function, returning the updated value.
-
-
-
Constructor Detail
-
AsyncRemoteAtomicLong
protected AsyncRemoteAtomicLong(AsyncNamedMap<String,AtomicLong> mapAtomic, String sName)
Constructs a newAsyncRemoteAtomicLong.- Parameters:
mapAtomic- the map that holds this atomic valuesName- the name of this atomic value
-
-
Method Detail
-
get
public CompletableFuture<Long> get()
Description copied from interface:AsyncAtomicLongReturns the current value.- Specified by:
getin interfaceAsyncAtomicLong- Returns:
- the current value
-
set
public CompletableFuture<Void> set(long lNewValue)
Description copied from interface:AsyncAtomicLongSets the value tonewValue.- Specified by:
setin interfaceAsyncAtomicLong- Parameters:
lNewValue- the new value- Returns:
- a
CompletableFuturethat can be used to determine whether the operation completed
-
getAndSet
public CompletableFuture<Long> getAndSet(long lNewValue)
Description copied from interface:AsyncAtomicLongAtomically sets the value tonewValueand returns the old value.- Specified by:
getAndSetin interfaceAsyncAtomicLong- Parameters:
lNewValue- the new value- Returns:
- the previous value
-
compareAndSet
public CompletableFuture<Boolean> compareAndSet(long lExpectedValue, long lNewValue)
Description copied from interface:AsyncAtomicLongAtomically sets the value tonewValueif the current value== expectedValue.- Specified by:
compareAndSetin interfaceAsyncAtomicLong- Parameters:
lExpectedValue- the expected valuelNewValue- the new value- Returns:
trueif successful. False return indicates that the actual value was not equal to the expected value.
-
getAndIncrement
public CompletableFuture<Long> getAndIncrement()
Description copied from interface:AsyncAtomicLongAtomically increments the current value.Equivalent to
getAndAdd(1).- Specified by:
getAndIncrementin interfaceAsyncAtomicLong- Returns:
- the previous value
-
getAndDecrement
public CompletableFuture<Long> getAndDecrement()
Description copied from interface:AsyncAtomicLongAtomically decrements the current value.Equivalent to
getAndAdd(-1).- Specified by:
getAndDecrementin interfaceAsyncAtomicLong- Returns:
- the previous value
-
getAndAdd
public CompletableFuture<Long> getAndAdd(long lDelta)
Description copied from interface:AsyncAtomicLongAtomically adds the given value to the current value.- Specified by:
getAndAddin interfaceAsyncAtomicLong- Parameters:
lDelta- the value to add- Returns:
- the previous value
-
incrementAndGet
public CompletableFuture<Long> incrementAndGet()
Description copied from interface:AsyncAtomicLongAtomically increments the current value.Equivalent to
addAndGet(1).- Specified by:
incrementAndGetin interfaceAsyncAtomicLong- Returns:
- the updated value
-
decrementAndGet
public CompletableFuture<Long> decrementAndGet()
Description copied from interface:AsyncAtomicLongAtomically decrements the current value.Equivalent to
addAndGet(-1).- Specified by:
decrementAndGetin interfaceAsyncAtomicLong- Returns:
- the updated value
-
addAndGet
public CompletableFuture<Long> addAndGet(long lDelta)
Description copied from interface:AsyncAtomicLongAtomically adds the given value to the current value.- Specified by:
addAndGetin interfaceAsyncAtomicLong- Parameters:
lDelta- the value to add- Returns:
- the updated value
-
getAndUpdate
public CompletableFuture<Long> getAndUpdate(Remote.LongUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
public CompletableFuture<Long> getAndUpdate(LongUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
updateFunction- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
public CompletableFuture<Long> updateAndGet(Remote.LongUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
public CompletableFuture<Long> updateAndGet(LongUnaryOperator updateFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
updateFunction- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
public CompletableFuture<Long> getAndAccumulate(long lUpdate, Remote.LongBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
public CompletableFuture<Long> getAndAccumulate(long lUpdate, LongBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
public CompletableFuture<Long> accumulateAndGet(long lUpdate, Remote.LongBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
public CompletableFuture<Long> accumulateAndGet(long lUpdate, LongBinaryOperator accumulatorFunction)
Description copied from interface:AsyncAtomicLongAtomically 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 interfaceAsyncAtomicLong- Parameters:
lUpdate- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
public CompletableFuture<Long> compareAndExchange(long lExpectedValue, long lNewValue)
Description copied from interface:AsyncAtomicLongAtomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.- Specified by:
compareAndExchangein interfaceAsyncAtomicLong- Parameters:
lExpectedValue- the expected valuelNewValue- 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:AsyncAtomicLongReturns the current value of thisDistributedAtomicLongas anintafter a narrowing primitive conversion.- Specified by:
intValuein interfaceAsyncAtomicLong- Returns:
- the current value of this
DistributedAtomicLongas anintafter a narrowing primitive conversion
-
longValue
public CompletableFuture<Long> longValue()
Description copied from interface:AsyncAtomicLongReturns the current value of thisDistributedAtomicLongas along. Equivalent toAsyncAtomicLong.get().- Specified by:
longValuein interfaceAsyncAtomicLong- Returns:
- the current value of this
DistributedAtomicLongas along
-
floatValue
public CompletableFuture<Float> floatValue()
Description copied from interface:AsyncAtomicLongReturns the current value of thisDistributedAtomicLongas afloatafter a widening primitive conversion.- Specified by:
floatValuein interfaceAsyncAtomicLong- Returns:
- the current value of this
DistributedAtomicLongas afloatafter a widening primitive conversion.
-
doubleValue
public CompletableFuture<Double> doubleValue()
Description copied from interface:AsyncAtomicLongReturns the current value of thisDistributedAtomicLongas adoubleafter a widening primitive conversion.- Specified by:
doubleValuein interfaceAsyncAtomicLong- Returns:
- the current value of this
DistributedAtomicLongas adoubleafter a widening primitive conversion
-
byteValue
public CompletableFuture<Byte> byteValue()
Description copied from interface:AsyncAtomicLongReturns the value of the specified number as abyte.This implementation returns the result of
AsyncAtomicLong.intValue()cast to abyte.- Specified by:
byteValuein interfaceAsyncAtomicLong- Returns:
- the numeric value represented by this object after conversion
to type
byte.
-
shortValue
public CompletableFuture<Short> shortValue()
Description copied from interface:AsyncAtomicLongReturns the value of the specified number as ashort.This implementation returns the result of
AsyncAtomicLong.intValue()cast to ashort.- Specified by:
shortValuein interfaceAsyncAtomicLong- 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<AtomicLong,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<AtomicLong,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
-
-