Class RemoteAtomicReference<V>

java.lang.Object
com.oracle.coherence.concurrent.atomic.RemoteAtomicReference<V>
Type Parameters:
V - the type of object referred to by this reference
All Implemented Interfaces:
AtomicReference<V>

public class RemoteAtomicReference<V> extends Object implements AtomicReference<V>
The remote implementation of AtomicReference, backed by a Coherence NamedMap entry.

Every method in this class is guaranteed to execute effectively-once, and provides cluster-wide atomicity guarantees for the backing atomic value. However, keep in mind that this comes at a significant cost -- each method invocation results in a network call to a remote owner of the backing atomic value, which means that each operation has significantly higher latency than a corresponding local implementation.

To somewhat reduce that performance penalty, consider using non-blocking AsyncAtomicReference implementation instead.

Since:
21.12
Author:
Aleks Seovic 2020.12.08
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.oracle.coherence.concurrent.atomic.AtomicReference

    AtomicReference.Serializer<V>
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Construct RemoteAtomicReference instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    Return non-blocking API for this atomic reference.
    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.
    get()
    Returns the current value.
    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.
    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.
    getAndSet(V newValue)
    Atomically sets the value to newValue and returns the old value.
    Atomically updates the current value with the results of applying the given function, returning the previous value.
    getAndUpdate(UnaryOperator<V> updateFunction)
    Atomically updates the current value with the results of applying the given function, returning the previous value.
    protected <R> R
    Apply specified function against the remote object and return the result.
    protected <R> R
    invoke(Remote.Function<AtomicReference<V>,R> function, boolean fMutate)
    Apply specified function against the remote object and return the result.
    void
    set(V newValue)
    Sets the value to newValue.
    Returns the String representation of the current value.
    Atomically updates the current value with the results of applying the given function, returning the updated value.
    updateAndGet(UnaryOperator<V> updateFunction)
    Atomically updates the current value with the results of applying the given function, returning the updated value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RemoteAtomicReference

      protected RemoteAtomicReference(NamedMap<String,AtomicReference<V>> mapAtomic, String sName)
      Construct RemoteAtomicReference instance.
      Parameters:
      mapAtomic - the map that holds this atomic value
      sName - the name of this atomic value
  • Method Details

    • async

      public AsyncRemoteAtomicReference<V> async()
      Description copied from interface: AtomicReference
      Return non-blocking API for this atomic reference.
      Specified by:
      async in interface AtomicReference<V>
      Returns:
      non-blocking API for this atomic reference
    • get

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

      public void set(V newValue)
      Description copied from interface: AtomicReference
      Sets the value to newValue.
      Specified by:
      set in interface AtomicReference<V>
      Parameters:
      newValue - the new value
    • getAndSet

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

      public boolean compareAndSet(V expectedValue, V newValue)
      Description copied from interface: AtomicReference
      Atomically sets the value to newValue if the current value is equal to the expectedValue.
      Specified by:
      compareAndSet in interface AtomicReference<V>
      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

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

      public V getAndUpdate(UnaryOperator<V> updateFunction)
      Description copied from interface: AtomicReference
      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 AtomicReference<V>
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the previous value
    • updateAndGet

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

      public V updateAndGet(UnaryOperator<V> updateFunction)
      Description copied from interface: AtomicReference
      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 AtomicReference<V>
      Parameters:
      updateFunction - a side-effect-free function
      Returns:
      the updated value
    • getAndAccumulate

      public V getAndAccumulate(V x, Remote.BinaryOperator<V> accumulatorFunction)
      Description copied from interface: AtomicReference
      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 AtomicReference<V>
      Parameters:
      x - the update value
      accumulatorFunction - a side-effect-free function of two arguments
      Returns:
      the previous value
    • getAndAccumulate

      public V getAndAccumulate(V x, BinaryOperator<V> accumulatorFunction)
      Description copied from interface: AtomicReference
      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 AtomicReference<V>
      Parameters:
      x - the update value
      accumulatorFunction - a side-effect-free function of two arguments
      Returns:
      the previous value
    • accumulateAndGet

      public V accumulateAndGet(V x, Remote.BinaryOperator<V> accumulatorFunction)
      Description copied from interface: AtomicReference
      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 AtomicReference<V>
      Parameters:
      x - the update value
      accumulatorFunction - a side-effect-free function of two arguments
      Returns:
      the updated value
    • accumulateAndGet

      public V accumulateAndGet(V x, BinaryOperator<V> accumulatorFunction)
      Description copied from interface: AtomicReference
      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 AtomicReference<V>
      Parameters:
      x - the update value
      accumulatorFunction - a side-effect-free function of two arguments
      Returns:
      the updated value
    • compareAndExchange

      public V compareAndExchange(V expectedValue, V newValue)
      Description copied from interface: AtomicReference
      Atomically sets the value to newValue if the current value, referred to as the witness value, is equal to the == expectedValue.
      Specified by:
      compareAndExchange in interface AtomicReference<V>
      Parameters:
      expectedValue - the expected value
      newValue - the new value
      Returns:
      the witness value, which will be the same as the expected value if successful
    • 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
    • invoke

      protected <R> R invoke(Remote.Function<AtomicReference<V>,R> function)
      Apply specified function against the remote object and return the result.

      Any changes the function makes to the remote object will be preserved.

      Type Parameters:
      R - the type of the result
      Parameters:
      function - the function to apply
      Returns:
      the result of the function applied to a remote object
    • invoke

      protected <R> R invoke(Remote.Function<AtomicReference<V>,R> function, boolean fMutate)
      Apply specified function against the remote object and return the result.

      If the fMutate argument is true, any changes to the remote object will be preserved.

      Type Parameters:
      R - the type of the result
      Parameters:
      function - the function to apply
      fMutate - flag specifying whether the function mutates the object
      Returns:
      the result of the function applied to a remote object