Class RemoteAtomicInteger
- java.lang.Object
-
- java.lang.Number
-
- com.oracle.coherence.concurrent.atomic.RemoteAtomicInteger
-
- All Implemented Interfaces:
AtomicInteger
,Serializable
public class RemoteAtomicInteger extends Number implements AtomicInteger
The remote implementation ofAtomicInteger
, backed by a CoherenceNamedMap
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.To somewhat reduce that performance penalty, consider using non-blocking
AsyncAtomicInteger
implementation instead.- Since:
- 21.06
- Author:
- Aleks Seovic 2020.12.03
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.oracle.coherence.concurrent.atomic.AtomicInteger
AtomicInteger.Serializer
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RemoteAtomicInteger(NamedMap<String,AtomicInteger> mapAtomic, String sName)
ConstructRemoteAtomicInteger
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
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.int
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.int
addAndGet(int nDelta)
Atomically adds the given value to the current value.AsyncRemoteAtomicInteger
async()
Return non-blocking API for this atomic value.int
compareAndExchange(int nExpectedValue, int nNewValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.boolean
compareAndSet(int nExpectedValue, int nNewValue)
Atomically sets the value tonewValue
if the current value== expectedValue
.int
decrementAndGet()
Atomically decrements the current value.double
doubleValue()
Returns the current value of thisAtomicInteger
as adouble
after a widening primitive conversion.float
floatValue()
Returns the current value of thisAtomicInteger
as afloat
after a widening primitive conversion.int
get()
Returns the current value.int
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.int
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.int
getAndAdd(int nDelta)
Atomically adds the given value to the current value.int
getAndDecrement()
Atomically decrements the current value.int
getAndIncrement()
Atomically increments the current value.int
getAndSet(int nNewValue)
Atomically sets the value tonewValue
and returns the old value.int
getAndUpdate(Remote.IntUnaryOperator updateFunction)
Atomically updates the current value with the results of applying the given function, returning the previous value.int
getAndUpdate(IntUnaryOperator updateFunction)
Atomically updates the current value with the results of applying the given function, returning the previous value.int
incrementAndGet()
Atomically increments the current value.int
intValue()
Returns the current value of thisAtomicInteger
as anint
.protected <R> R
invoke(Remote.Function<AtomicInteger,R> function)
Apply specified function against the remote object and return the result.protected <R> R
invoke(Remote.Function<AtomicInteger,R> function, boolean fMutate)
Apply specified function against the remote object and return the result.long
longValue()
Returns the current value of thisAtomicInteger
as along
after a widening primitive conversion.void
set(int nNewValue)
Sets the value tonewValue
.String
toString()
Returns the String representation of the current value.int
updateAndGet(Remote.IntUnaryOperator updateFunction)
Atomically updates the current value with the results of applying the given function, returning the updated value.int
updateAndGet(IntUnaryOperator updateFunction)
Atomically updates the current value with the results of applying the given function, returning the updated value.-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.oracle.coherence.concurrent.atomic.AtomicInteger
byteValue, shortValue
-
-
-
-
Constructor Detail
-
RemoteAtomicInteger
protected RemoteAtomicInteger(NamedMap<String,AtomicInteger> mapAtomic, String sName)
ConstructRemoteAtomicInteger
instance.- Parameters:
mapAtomic
- the map that holds this atomic valuesName
- the name of this atomic value
-
-
Method Detail
-
async
public AsyncRemoteAtomicInteger async()
Description copied from interface:AtomicInteger
Return non-blocking API for this atomic value.- Specified by:
async
in interfaceAtomicInteger
- Returns:
- non-blocking API for this atomic value
-
get
public int get()
Description copied from interface:AtomicInteger
Returns the current value.- Specified by:
get
in interfaceAtomicInteger
- Returns:
- the current value
-
set
public void set(int nNewValue)
Description copied from interface:AtomicInteger
Sets the value tonewValue
.- Specified by:
set
in interfaceAtomicInteger
- Parameters:
nNewValue
- the new value
-
getAndSet
public int getAndSet(int nNewValue)
Description copied from interface:AtomicInteger
Atomically sets the value tonewValue
and returns the old value.- Specified by:
getAndSet
in interfaceAtomicInteger
- Parameters:
nNewValue
- the new value- Returns:
- the previous value
-
compareAndSet
public boolean compareAndSet(int nExpectedValue, int nNewValue)
Description copied from interface:AtomicInteger
Atomically sets the value tonewValue
if the current value== expectedValue
.- Specified by:
compareAndSet
in interfaceAtomicInteger
- Parameters:
nExpectedValue
- the expected valuenNewValue
- the new value- Returns:
true
if successful. False return indicates that the actual value was not equal to the expected value.
-
getAndIncrement
public int getAndIncrement()
Description copied from interface:AtomicInteger
Atomically increments the current value.Equivalent to
getAndAdd(1)
.- Specified by:
getAndIncrement
in interfaceAtomicInteger
- Returns:
- the previous value
-
getAndDecrement
public int getAndDecrement()
Description copied from interface:AtomicInteger
Atomically decrements the current value.Equivalent to
getAndAdd(-1)
.- Specified by:
getAndDecrement
in interfaceAtomicInteger
- Returns:
- the previous value
-
getAndAdd
public int getAndAdd(int nDelta)
Description copied from interface:AtomicInteger
Atomically adds the given value to the current value.- Specified by:
getAndAdd
in interfaceAtomicInteger
- Parameters:
nDelta
- the value to add- Returns:
- the previous value
-
incrementAndGet
public int incrementAndGet()
Description copied from interface:AtomicInteger
Atomically increments the current value.Equivalent to
addAndGet(1)
.- Specified by:
incrementAndGet
in interfaceAtomicInteger
- Returns:
- the updated value
-
decrementAndGet
public int decrementAndGet()
Description copied from interface:AtomicInteger
Atomically decrements the current value.Equivalent to
addAndGet(-1)
.- Specified by:
decrementAndGet
in interfaceAtomicInteger
- Returns:
- the updated value
-
addAndGet
public int addAndGet(int nDelta)
Description copied from interface:AtomicInteger
Atomically adds the given value to the current value.- Specified by:
addAndGet
in interfaceAtomicInteger
- Parameters:
nDelta
- the value to add- Returns:
- the updated value
-
getAndUpdate
public int getAndUpdate(Remote.IntUnaryOperator updateFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
public int getAndUpdate(IntUnaryOperator updateFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
public int updateAndGet(Remote.IntUnaryOperator updateFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
public int updateAndGet(IntUnaryOperator updateFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
public int getAndAccumulate(int nUpdate, Remote.IntBinaryOperator accumulatorFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
nUpdate
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
public int getAndAccumulate(int nUpdate, IntBinaryOperator accumulatorFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
nUpdate
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
public int accumulateAndGet(int nUpdate, Remote.IntBinaryOperator accumulatorFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
nUpdate
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
public int accumulateAndGet(int nUpdate, IntBinaryOperator accumulatorFunction)
Description copied from interface:AtomicInteger
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 interfaceAtomicInteger
- Parameters:
nUpdate
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
public int compareAndExchange(int nExpectedValue, int nNewValue)
Description copied from interface:AtomicInteger
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.- Specified by:
compareAndExchange
in interfaceAtomicInteger
- 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 int intValue()
Description copied from interface:AtomicInteger
Returns the current value of thisAtomicInteger
as anint
.- Specified by:
intValue
in interfaceAtomicInteger
- Specified by:
intValue
in classNumber
- Returns:
- the numeric value represented by this object
-
longValue
public long longValue()
Description copied from interface:AtomicInteger
Returns the current value of thisAtomicInteger
as along
after a widening primitive conversion.- Specified by:
longValue
in interfaceAtomicInteger
- Specified by:
longValue
in classNumber
- Returns:
- the numeric value represented by this object after conversion
to type
long
-
floatValue
public float floatValue()
Description copied from interface:AtomicInteger
Returns the current value of thisAtomicInteger
as afloat
after a widening primitive conversion.- Specified by:
floatValue
in interfaceAtomicInteger
- Specified by:
floatValue
in classNumber
- Returns:
- the numeric value represented by this object after conversion
to type
float
-
doubleValue
public double doubleValue()
Description copied from interface:AtomicInteger
Returns the current value of thisAtomicInteger
as adouble
after a widening primitive conversion.- Specified by:
doubleValue
in interfaceAtomicInteger
- Specified by:
doubleValue
in classNumber
- Returns:
- the numeric value represented by this object after conversion
to type
double
-
toString
public String toString()
Returns the String representation of the current value.
-
invoke
protected <R> 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> R invoke(Remote.Function<AtomicInteger,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
-
-