Interface AtomicReference<V>

  • Type Parameters:
    V - the type of object referred to by this reference
    All Known Implementing Classes:
    LocalAtomicReference, RemoteAtomicReference

    public interface AtomicReference<V>
    An object reference that may be updated atomically.
    Author:
    Aleks Seovic 2020.12.08
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  AtomicReference.Serializer<V>
      POF serializer implementation.
    • Method Summary

      All Methods Instance Methods Abstract 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.
      AsyncAtomicReference<V> async()
      Return non-blocking API for this atomic reference.
      V compareAndExchange​(V expectedValue, V newValue)
      Atomically sets the value to newValue 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 to newValue if the current value is equal to the expectedValue.
      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 to newValue 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 to newValue.
      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.
    • Method Detail

      • async

        AsyncAtomicReference<V> async()
        Return non-blocking API for this atomic reference.
        Returns:
        non-blocking API for this atomic reference
      • get

        V get()
        Returns the current value.
        Returns:
        the current value
      • set

        void set​(V newValue)
        Sets the value to newValue.
        Parameters:
        newValue - the new value
      • getAndSet

        V getAndSet​(V newValue)
        Atomically sets the value to newValue and returns the old value.
        Parameters:
        newValue - the new value
        Returns:
        the previous value
      • compareAndSet

        boolean compareAndSet​(V expectedValue,
                              V newValue)
        Atomically sets the value to newValue if the current value is equal to the expectedValue.
        Parameters:
        expectedValue - the expected value
        newValue - the new value
        Returns:
        true if successful. False return indicates that the actual value was not equal to the expected value.
      • getAndUpdate

        V getAndUpdate​(Remote.UnaryOperator<V> updateFunction)
        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.
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the previous value
      • getAndUpdate

        V getAndUpdate​(UnaryOperator<V> updateFunction)
        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.
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the previous value
      • updateAndGet

        V updateAndGet​(Remote.UnaryOperator<V> updateFunction)
        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.
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the updated value
      • updateAndGet

        V updateAndGet​(UnaryOperator<V> updateFunction)
        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.
        Parameters:
        updateFunction - a side-effect-free function
        Returns:
        the updated value
      • getAndAccumulate

        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.

        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.

        Parameters:
        x - the update value
        accumulatorFunction - a side-effect-free function of two arguments
        Returns:
        the previous value
      • getAndAccumulate

        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.

        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.

        Parameters:
        x - the update value
        accumulatorFunction - a side-effect-free function of two arguments
        Returns:
        the previous value
      • accumulateAndGet

        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.

        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.

        Parameters:
        x - the update value
        accumulatorFunction - a side-effect-free function of two arguments
        Returns:
        the updated value
      • accumulateAndGet

        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.

        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.

        Parameters:
        x - the update value
        accumulatorFunction - a side-effect-free function of two arguments
        Returns:
        the updated value
      • compareAndExchange

        V compareAndExchange​(V expectedValue,
                             V newValue)
        Atomically sets the value to newValue if the current value, referred to as the witness value, is equal to the == expectedValue.
        Parameters:
        expectedValue - the expected value
        newValue - the new value
        Returns:
        the witness value, which will be the same as the expected value if successful