Class AsyncLocalAtomicInteger
- All Implemented Interfaces:
AsyncAtomicInteger
AsyncAtomicInteger interface,
that simply wraps java.util.concurrent.atomic.AtomicInteger
instance and returns an already completed future from each method.- Since:
- 21.12
- Author:
- Aleks Seovic 2020.12.07
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructLocalAtomicIntegerinstance. -
Method Summary
Modifier and TypeMethodDescriptionaccumulateAndGet(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.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.addAndGet(int nDelta) Atomically adds the given value to the current value.Returns the current value of thisAsyncAtomicIntegeras abyteafter a narrowing primitive conversion.compareAndExchange(int nExpectedValue, int nNewValue) Atomically sets the value tonewValueif the current value, referred to as the witness value,== expectedValue.compareAndSet(int nExpectedValue, int nNewValue) Atomically sets the value tonewValueif the current value== expectedValue.Atomically decrements the current value.Returns the current value of thisAsyncAtomicIntegeras adoubleafter a widening primitive conversion.Returns the current value of thisAsyncAtomicIntegeras afloatafter a widening primitive conversion.get()Returns the current value.getAndAccumulate(int x, 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.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.getAndAdd(int nDelta) Atomically adds the given value to the current value.Atomically decrements the current value.Atomically increments the current value.getAndSet(int nNewValue) Atomically sets the value tonewValueand returns the old value.getAndUpdate(Remote.IntUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the previous value.getAndUpdate(IntUnaryOperator 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 thisAsyncAtomicIntegeras anint.Returns the current value of thisAsyncAtomicIntegeras alongafter a widening primitive conversion.set(int nNewValue) Sets the value tonewValue.Returns the current value of thisAsyncAtomicIntegeras ashortafter a narrowing primitive conversion.toString()Returns the String representation of the current value.updateAndGet(Remote.IntUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.updateAndGet(IntUnaryOperator updateFunction) Atomically updates the current value with the results of applying the given function, returning the updated value.
-
Constructor Details
-
AsyncLocalAtomicInteger
ConstructLocalAtomicIntegerinstance.- Parameters:
value- wrapped value
-
-
Method Details
-
get
Description copied from interface:AsyncAtomicIntegerReturns the current value.- Specified by:
getin interfaceAsyncAtomicInteger- Returns:
- the current value
-
set
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
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
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
Description copied from interface:AsyncAtomicIntegerAtomically increments the current value.Equivalent to
getAndAdd(1).- Specified by:
getAndIncrementin interfaceAsyncAtomicInteger- Returns:
- the previous value
-
getAndDecrement
Description copied from interface:AsyncAtomicIntegerAtomically decrements the current value.Equivalent to
getAndAdd(-1).- Specified by:
getAndDecrementin interfaceAsyncAtomicInteger- Returns:
- the previous value
-
getAndAdd
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
Description copied from interface:AsyncAtomicIntegerAtomically increments the current value.Equivalent to
addAndGet(1).- Specified by:
incrementAndGetin interfaceAsyncAtomicInteger- Returns:
- the updated value
-
decrementAndGet
Description copied from interface:AsyncAtomicIntegerAtomically decrements the current value.Equivalent to
addAndGet(-1).- Specified by:
decrementAndGetin interfaceAsyncAtomicInteger- Returns:
- the updated value
-
addAndGet
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
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
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
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
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 x, 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:
x- 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
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
Description copied from interface:AsyncAtomicIntegerReturns the current value of thisAsyncAtomicIntegeras anint.- Specified by:
intValuein interfaceAsyncAtomicInteger- Returns:
- the numeric value represented by this object
-
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
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
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
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
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
Returns the String representation of the current value.
-