Class AsyncLocalAtomicInteger

  • All Implemented Interfaces:
    AsyncAtomicInteger

    public class AsyncLocalAtomicInteger
    extends Object
    implements AsyncAtomicInteger
    Local implementation of 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 Detail

      • AsyncLocalAtomicInteger

        protected AsyncLocalAtomicInteger​(AtomicInteger value)
        Construct LocalAtomicInteger instance.
        Parameters:
        value - wrapped value
    • Method Detail

      • compareAndSet

        public CompletableFuture<Boolean> compareAndSet​(int nExpectedValue,
                                                        int nNewValue)
        Description copied from interface: AsyncAtomicInteger
        Atomically sets the value to newValue if the current value == expectedValue.
        Specified by:
        compareAndSet in interface AsyncAtomicInteger
        Parameters:
        nExpectedValue - the expected value
        nNewValue - the new value
        Returns:
        true if successful. False return indicates that the actual value was not equal to the expected value.
      • getAndUpdate

        public CompletableFuture<Integer> getAndUpdate​(Remote.IntUnaryOperator updateFunction)
        Description copied from interface: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the previous value
      • getAndUpdate

        public CompletableFuture<Integer> getAndUpdate​(IntUnaryOperator updateFunction)
        Description copied from interface: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the previous value
      • updateAndGet

        public CompletableFuture<Integer> updateAndGet​(Remote.IntUnaryOperator updateFunction)
        Description copied from interface: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the updated value
      • updateAndGet

        public CompletableFuture<Integer> updateAndGet​(IntUnaryOperator updateFunction)
        Description copied from interface: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        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: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        x - the update value
        accumulatorFunction - 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: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        nUpdate - the update value
        accumulatorFunction - 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: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        nUpdate - the update value
        accumulatorFunction - 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: AsyncAtomicInteger
        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 interface AsyncAtomicInteger
        Parameters:
        nUpdate - the update value
        accumulatorFunction - a side-effect-free function of two arguments
        Returns:
        the updated value
      • compareAndExchange

        public CompletableFuture<Integer> compareAndExchange​(int nExpectedValue,
                                                             int nNewValue)
        Description copied from interface: AsyncAtomicInteger
        Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue.
        Specified by:
        compareAndExchange in interface AsyncAtomicInteger
        Parameters:
        nExpectedValue - the expected value
        nNewValue - the new value
        Returns:
        the witness value, which will be the same as the expected value if successful
      • longValue

        public CompletableFuture<Long> longValue()
        Description copied from interface: AsyncAtomicInteger
        Returns the current value of this AsyncAtomicInteger as a long after a widening primitive conversion.
        Specified by:
        longValue in interface AsyncAtomicInteger
        Returns:
        the numeric value represented by this object after conversion to type long
      • floatValue

        public CompletableFuture<Float> floatValue()
        Description copied from interface: AsyncAtomicInteger
        Returns the current value of this AsyncAtomicInteger as a float after a widening primitive conversion.
        Specified by:
        floatValue in interface AsyncAtomicInteger
        Returns:
        the numeric value represented by this object after conversion to type float
      • doubleValue

        public CompletableFuture<Double> doubleValue()
        Description copied from interface: AsyncAtomicInteger
        Returns the current value of this AsyncAtomicInteger as a double after a widening primitive conversion.
        Specified by:
        doubleValue in interface AsyncAtomicInteger
        Returns:
        the numeric value represented by this object after conversion to type double
      • byteValue

        public CompletableFuture<Byte> byteValue()
        Description copied from interface: AsyncAtomicInteger
        Returns the current value of this AsyncAtomicInteger as a byte after a narrowing primitive conversion.
        Specified by:
        byteValue in interface AsyncAtomicInteger
        Returns:
        the numeric value represented by this object after conversion to type byte
      • shortValue

        public CompletableFuture<Short> shortValue()
        Description copied from interface: AsyncAtomicInteger
        Returns the current value of this AsyncAtomicInteger as a short after a narrowing primitive conversion.
        Specified by:
        shortValue in interface AsyncAtomicInteger
        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.
        Overrides:
        toString in class Object
        Returns:
        the String representation of the current value