Class LocalAtomicReference<V>
- java.lang.Object
-
- com.oracle.coherence.concurrent.atomic.LocalAtomicReference<V>
-
- Type Parameters:
V
- the type of object referred to by this reference
- All Implemented Interfaces:
AtomicReference<V>
public class LocalAtomicReference<V> extends Object implements AtomicReference<V>
Local implementation ofAtomicReference
interface, that simply wrapsjava.util.concurrent.atomic.AtomicReference
instance.- Author:
- Aleks Seovic 2020.12.08
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.oracle.coherence.concurrent.atomic.AtomicReference
AtomicReference.Serializer<V>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LocalAtomicReference(AtomicReference<V> value)
ConstructLocalAtomicReference<V>
instance.protected
LocalAtomicReference(V value)
ConstructLocalAtomicReference<V>
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.AsyncLocalAtomicReference<V>
async()
Return non-blocking API for this atomic reference.V
compareAndExchange(V expectedValue, V newValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value, is equal to the== expectedValue
.boolean
compareAndSet(V expectedValue, V newValue)
Atomically sets the value tonewValue
if the current value is equal to theexpectedValue
.V
get()
Returns the current value.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.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.V
getAndSet(V newValue)
Atomically sets the value tonewValue
and returns the old value.V
getAndUpdate(Remote.UnaryOperator<V> updateFunction)
Atomically updates the current value with the results of applying the given function, returning the previous value.V
getAndUpdate(UnaryOperator<V> updateFunction)
Atomically updates the current value with the results of applying the given function, returning the previous value.void
set(V newValue)
Sets the value tonewValue
.String
toString()
V
updateAndGet(Remote.UnaryOperator<V> updateFunction)
Atomically updates the current value with the results of applying the given function, returning the updated value.V
updateAndGet(UnaryOperator<V> updateFunction)
Atomically updates the current value with the results of applying the given function, returning the updated value.
-
-
-
Constructor Detail
-
LocalAtomicReference
protected LocalAtomicReference(V value)
ConstructLocalAtomicReference<V>
instance.- Parameters:
value
- initial value
-
LocalAtomicReference
protected LocalAtomicReference(AtomicReference<V> value)
ConstructLocalAtomicReference<V>
instance.- Parameters:
value
- wrapped value
-
-
Method Detail
-
async
public AsyncLocalAtomicReference<V> async()
Description copied from interface:AtomicReference
Return non-blocking API for this atomic reference.- Specified by:
async
in interfaceAtomicReference<V>
- Returns:
- non-blocking API for this atomic reference
-
get
public V get()
Description copied from interface:AtomicReference
Returns the current value.- Specified by:
get
in interfaceAtomicReference<V>
- Returns:
- the current value
-
set
public void set(V newValue)
Description copied from interface:AtomicReference
Sets the value tonewValue
.- Specified by:
set
in interfaceAtomicReference<V>
- Parameters:
newValue
- the new value
-
getAndSet
public V getAndSet(V newValue)
Description copied from interface:AtomicReference
Atomically sets the value tonewValue
and returns the old value.- Specified by:
getAndSet
in interfaceAtomicReference<V>
- Parameters:
newValue
- the new value- Returns:
- the previous value
-
compareAndSet
public boolean compareAndSet(V expectedValue, V newValue)
Description copied from interface:AtomicReference
Atomically sets the value tonewValue
if the current value is equal to theexpectedValue
.- Specified by:
compareAndSet
in interfaceAtomicReference<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
public V getAndUpdate(Remote.UnaryOperator<V> updateFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
public V getAndUpdate(UnaryOperator<V> updateFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
public V updateAndGet(Remote.UnaryOperator<V> updateFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
public V updateAndGet(UnaryOperator<V> updateFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
getAndAccumulate
public V getAndAccumulate(V x, Remote.BinaryOperator<V> accumulatorFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the previous value
-
getAndAccumulate
public V getAndAccumulate(V x, BinaryOperator<V> accumulatorFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
public V accumulateAndGet(V x, Remote.BinaryOperator<V> accumulatorFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
accumulateAndGet
public V accumulateAndGet(V x, BinaryOperator<V> accumulatorFunction)
Description copied from interface:AtomicReference
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 interfaceAtomicReference<V>
- Parameters:
x
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
public V compareAndExchange(V expectedValue, V newValue)
Description copied from interface:AtomicReference
Atomically sets the value tonewValue
if the current value, referred to as the witness value, is equal to the== expectedValue
.- Specified by:
compareAndExchange
in interfaceAtomicReference<V>
- Parameters:
expectedValue
- the expected valuenewValue
- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
-