Class AsyncLocalAtomicLong

java.lang.Object
com.oracle.coherence.concurrent.atomic.AsyncLocalAtomicLong
All Implemented Interfaces:
AsyncAtomicLong

public class AsyncLocalAtomicLong extends Object implements AsyncAtomicLong
Local implementation of 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 Details

    • AsyncLocalAtomicLong

      protected AsyncLocalAtomicLong(AtomicLong value)
      Construct LocalAtomicLong instance.
      Parameters:
      value - wrapped value
  • Method Details

    • get

      public CompletableFuture<Long> get()
      Description copied from interface: AsyncAtomicLong
      Returns the current value.
      Specified by:
      get in interface AsyncAtomicLong
      Returns:
      the current value
    • set

      public CompletableFuture<Void> set(long lNewValue)
      Description copied from interface: AsyncAtomicLong
      Sets the value to newValue.
      Specified by:
      set in interface AsyncAtomicLong
      Parameters:
      lNewValue - the new value
      Returns:
      a CompletableFuture that can be used to determine whether the operation completed
    • getAndSet

      public CompletableFuture<Long> getAndSet(long lNewValue)
      Description copied from interface: AsyncAtomicLong
      Atomically sets the value to newValue and returns the old value.
      Specified by:
      getAndSet in interface AsyncAtomicLong
      Parameters:
      lNewValue - the new value
      Returns:
      the previous value
    • compareAndSet

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

      public CompletableFuture<Long> getAndIncrement()
      Description copied from interface: AsyncAtomicLong
      Atomically increments the current value.

      Equivalent to getAndAdd(1).

      Specified by:
      getAndIncrement in interface AsyncAtomicLong
      Returns:
      the previous value
    • getAndDecrement

      public CompletableFuture<Long> getAndDecrement()
      Description copied from interface: AsyncAtomicLong
      Atomically decrements the current value.

      Equivalent to getAndAdd(-1).

      Specified by:
      getAndDecrement in interface AsyncAtomicLong
      Returns:
      the previous value
    • getAndAdd

      public CompletableFuture<Long> getAndAdd(long lDelta)
      Description copied from interface: AsyncAtomicLong
      Atomically adds the given value to the current value.
      Specified by:
      getAndAdd in interface AsyncAtomicLong
      Parameters:
      lDelta - the value to add
      Returns:
      the previous value
    • incrementAndGet

      public CompletableFuture<Long> incrementAndGet()
      Description copied from interface: AsyncAtomicLong
      Atomically increments the current value.

      Equivalent to addAndGet(1).

      Specified by:
      incrementAndGet in interface AsyncAtomicLong
      Returns:
      the updated value
    • decrementAndGet

      public CompletableFuture<Long> decrementAndGet()
      Description copied from interface: AsyncAtomicLong
      Atomically decrements the current value.

      Equivalent to addAndGet(-1).

      Specified by:
      decrementAndGet in interface AsyncAtomicLong
      Returns:
      the updated value
    • addAndGet

      public CompletableFuture<Long> addAndGet(long lDelta)
      Description copied from interface: AsyncAtomicLong
      Atomically adds the given value to the current value.
      Specified by:
      addAndGet in interface AsyncAtomicLong
      Parameters:
      lDelta - the value to add
      Returns:
      the updated value
    • getAndUpdate

      public CompletableFuture<Long> getAndUpdate(Remote.LongUnaryOperator updateFunction)
      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 interface AsyncAtomicLong
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the previous value
    • getAndUpdate

      public CompletableFuture<Long> getAndUpdate(LongUnaryOperator updateFunction)
      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 interface AsyncAtomicLong
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the previous value
    • updateAndGet

      public CompletableFuture<Long> updateAndGet(Remote.LongUnaryOperator updateFunction)
      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 interface AsyncAtomicLong
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the updated value
    • updateAndGet

      public CompletableFuture<Long> updateAndGet(LongUnaryOperator updateFunction)
      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 interface AsyncAtomicLong
      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 interface AsyncAtomicLong
      Parameters:
      lUpdate - the update value
      accumulatorFunction - 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 interface AsyncAtomicLong
      Parameters:
      lUpdate - the update value
      accumulatorFunction - 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 interface AsyncAtomicLong
      Parameters:
      lUpdate - the update value
      accumulatorFunction - 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 interface AsyncAtomicLong
      Parameters:
      lUpdate - the update value
      accumulatorFunction - a side-effect-free function of two arguments
      Returns:
      the updated value
    • compareAndExchange

      public CompletableFuture<Long> compareAndExchange(long lExpectedValue, long lNewValue)
      Description copied from interface: AsyncAtomicLong
      Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue.
      Specified by:
      compareAndExchange in interface AsyncAtomicLong
      Parameters:
      lExpectedValue - the expected value
      lNewValue - the new value
      Returns:
      the witness value, which will be the same as the expected value if successful
    • intValue

      public CompletableFuture<Integer> intValue()
      Description copied from interface: AsyncAtomicLong
      Returns the current value of this DistributedAtomicLong as an int after a narrowing primitive conversion.
      Specified by:
      intValue in interface AsyncAtomicLong
      Returns:
      the current value of this DistributedAtomicLong as an int after a narrowing primitive conversion
    • longValue

      public CompletableFuture<Long> longValue()
      Description copied from interface: AsyncAtomicLong
      Returns the current value of this DistributedAtomicLong as a long. Equivalent to AsyncAtomicLong.get().
      Specified by:
      longValue in interface AsyncAtomicLong
      Returns:
      the current value of this DistributedAtomicLong as a long
    • floatValue

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

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

      public CompletableFuture<Byte> byteValue()
      Description copied from interface: AsyncAtomicLong
      Returns the value of the specified number as a byte.

      This implementation returns the result of AsyncAtomicLong.intValue() cast to a byte.

      Specified by:
      byteValue in interface AsyncAtomicLong
      Returns:
      the numeric value represented by this object after conversion to type byte.
    • shortValue

      public CompletableFuture<Short> shortValue()
      Description copied from interface: AsyncAtomicLong
      Returns the value of the specified number as a short.

      This implementation returns the result of AsyncAtomicLong.intValue() cast to a short.

      Specified by:
      shortValue in interface AsyncAtomicLong
      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