Class AsyncLocalAtomicLong
- All Implemented Interfaces:
AsyncAtomicLong
AsyncAtomicLong
interface,
that simply wraps java.util.concurrent.atomic.AtomicLong
instance and returns an already completed future from each method.- Author:
- Aleks Seovic 2020.12.03
-
Constructor Summary
ModifierConstructorDescriptionprotected
AsyncLocalAtomicLong
(AtomicLong value) ConstructLocalAtomicLong
instance. -
Method Summary
Modifier and TypeMethodDescriptionaccumulateAndGet
(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.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.addAndGet
(long lDelta) Atomically adds the given value to the current value.Returns the value of the specified number as abyte
.compareAndExchange
(long lExpectedValue, long lNewValue) Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.compareAndSet
(long lExpectedValue, long lNewValue) Atomically sets the value tonewValue
if the current value== expectedValue
.Atomically decrements the current value.Returns the current value of thisDistributedAtomicLong
as adouble
after a widening primitive conversion.Returns the current value of thisDistributedAtomicLong
as afloat
after a widening primitive conversion.get()
Returns the current value.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.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.getAndAdd
(long lDelta) Atomically adds the given value to the current value.Atomically decrements the current value.Atomically increments the current value.getAndSet
(long lNewValue) Atomically sets the value tonewValue
and returns the old value.getAndUpdate
(Remote.LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.getAndUpdate
(LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.Atomically increments the current value.intValue()
Returns the current value of thisDistributedAtomicLong
as anint
after a narrowing primitive conversion.Returns the current value of thisDistributedAtomicLong
as along
.set
(long lNewValue) Sets the value tonewValue
.Returns the value of the specified number as ashort
.toString()
Returns the String representation of the current value.updateAndGet
(Remote.LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.updateAndGet
(LongUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.
-
Constructor Details
-
AsyncLocalAtomicLong
ConstructLocalAtomicLong
instance.- Parameters:
value
- wrapped value
-
-
Method Details
-
get
Description copied from interface:AsyncAtomicLong
Returns the current value.- Specified by:
get
in interfaceAsyncAtomicLong
- Returns:
- the current value
-
set
Description copied from interface:AsyncAtomicLong
Sets the value tonewValue
.- Specified by:
set
in interfaceAsyncAtomicLong
- Parameters:
lNewValue
- the new value- Returns:
- a
CompletableFuture
that can be used to determine whether the operation completed
-
getAndSet
Description copied from interface:AsyncAtomicLong
Atomically sets the value tonewValue
and returns the old value.- Specified by:
getAndSet
in interfaceAsyncAtomicLong
- Parameters:
lNewValue
- the new value- Returns:
- the previous value
-
compareAndSet
Description copied from interface:AsyncAtomicLong
Atomically sets the value tonewValue
if the current value== expectedValue
.- Specified by:
compareAndSet
in interfaceAsyncAtomicLong
- Parameters:
lExpectedValue
- the expected valuelNewValue
- the new value- Returns:
true
if successful. False return indicates that the actual value was not equal to the expected value.
-
getAndIncrement
Description copied from interface:AsyncAtomicLong
Atomically increments the current value.Equivalent to
getAndAdd(1)
.- Specified by:
getAndIncrement
in interfaceAsyncAtomicLong
- Returns:
- the previous value
-
getAndDecrement
Description copied from interface:AsyncAtomicLong
Atomically decrements the current value.Equivalent to
getAndAdd(-1)
.- Specified by:
getAndDecrement
in interfaceAsyncAtomicLong
- Returns:
- the previous value
-
getAndAdd
Description copied from interface:AsyncAtomicLong
Atomically adds the given value to the current value.- Specified by:
getAndAdd
in interfaceAsyncAtomicLong
- Parameters:
lDelta
- the value to add- Returns:
- the previous value
-
incrementAndGet
Description copied from interface:AsyncAtomicLong
Atomically increments the current value.Equivalent to
addAndGet(1)
.- Specified by:
incrementAndGet
in interfaceAsyncAtomicLong
- Returns:
- the updated value
-
decrementAndGet
Description copied from interface:AsyncAtomicLong
Atomically decrements the current value.Equivalent to
addAndGet(-1)
.- Specified by:
decrementAndGet
in interfaceAsyncAtomicLong
- Returns:
- the updated value
-
addAndGet
Description copied from interface:AsyncAtomicLong
Atomically adds the given value to the current value.- Specified by:
addAndGet
in interfaceAsyncAtomicLong
- Parameters:
lDelta
- the value to add- Returns:
- the updated value
-
getAndUpdate
Description copied from interface:AsyncAtomicLong
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 interfaceAsyncAtomicLong
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
getAndUpdate
Description copied from interface:AsyncAtomicLong
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 interfaceAsyncAtomicLong
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the previous value
-
updateAndGet
Description copied from interface:AsyncAtomicLong
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 interfaceAsyncAtomicLong
- Parameters:
updateFunction
- a side-effect-free function- Returns:
- the updated value
-
updateAndGet
Description copied from interface:AsyncAtomicLong
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 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:AsyncAtomicLong
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 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:AsyncAtomicLong
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 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:AsyncAtomicLong
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 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:AsyncAtomicLong
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 interfaceAsyncAtomicLong
- Parameters:
lUpdate
- the update valueaccumulatorFunction
- a side-effect-free function of two arguments- Returns:
- the updated value
-
compareAndExchange
Description copied from interface:AsyncAtomicLong
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.- Specified by:
compareAndExchange
in 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
Description copied from interface:AsyncAtomicLong
Returns the current value of thisDistributedAtomicLong
as anint
after a narrowing primitive conversion.- Specified by:
intValue
in interfaceAsyncAtomicLong
- Returns:
- the current value of this
DistributedAtomicLong
as anint
after a narrowing primitive conversion
-
longValue
Description copied from interface:AsyncAtomicLong
Returns the current value of thisDistributedAtomicLong
as along
. Equivalent toAsyncAtomicLong.get()
.- Specified by:
longValue
in interfaceAsyncAtomicLong
- Returns:
- the current value of this
DistributedAtomicLong
as along
-
floatValue
Description copied from interface:AsyncAtomicLong
Returns the current value of thisDistributedAtomicLong
as afloat
after a widening primitive conversion.- Specified by:
floatValue
in interfaceAsyncAtomicLong
- Returns:
- the current value of this
DistributedAtomicLong
as afloat
after a widening primitive conversion.
-
doubleValue
Description copied from interface:AsyncAtomicLong
Returns the current value of thisDistributedAtomicLong
as adouble
after a widening primitive conversion.- Specified by:
doubleValue
in interfaceAsyncAtomicLong
- Returns:
- the current value of this
DistributedAtomicLong
as adouble
after a widening primitive conversion
-
byteValue
Description copied from interface:AsyncAtomicLong
Returns the value of the specified number as abyte
.This implementation returns the result of
AsyncAtomicLong.intValue()
cast to abyte
.- Specified by:
byteValue
in interfaceAsyncAtomicLong
- Returns:
- the numeric value represented by this object after conversion
to type
byte
.
-
shortValue
Description copied from interface:AsyncAtomicLong
Returns the value of the specified number as ashort
.This implementation returns the result of
AsyncAtomicLong.intValue()
cast to ashort
.- Specified by:
shortValue
in interfaceAsyncAtomicLong
- Returns:
- the numeric value represented by this object after conversion
to type
short
.
-
toString
Returns the String representation of the current value.
-