Class RemoteAtomicBoolean

  • All Implemented Interfaces:
    AtomicBoolean

    public class RemoteAtomicBoolean
    extends Object
    implements AtomicBoolean
    The remote implementation of AtomicBoolean, 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 AsyncAtomicBoolean implementation instead.

    Since:
    21.06
    Author:
    Aleks Seovic 2020.12.07
    • Constructor Detail

      • RemoteAtomicBoolean

        protected RemoteAtomicBoolean​(NamedMap<String,​AtomicBoolean> mapAtomic,
                                      String sName)
        Construct RemoteAtomicBoolean instance.
        Parameters:
        mapAtomic - the map that holds this atomic value
        sName - the name of this atomic value
    • Method Detail

      • get

        public boolean get()
        Description copied from interface: AtomicBoolean
        Returns the current value.
        Specified by:
        get in interface AtomicBoolean
        Returns:
        the current value
      • set

        public void set​(boolean fNewValue)
        Description copied from interface: AtomicBoolean
        Sets the value to newValue.
        Specified by:
        set in interface AtomicBoolean
        Parameters:
        fNewValue - the new value
      • getAndSet

        public boolean getAndSet​(boolean fNewValue)
        Description copied from interface: AtomicBoolean
        Atomically sets the value to newValue and returns the old value.
        Specified by:
        getAndSet in interface AtomicBoolean
        Parameters:
        fNewValue - the new value
        Returns:
        the previous value
      • compareAndSet

        public boolean compareAndSet​(boolean fExpectedValue,
                                     boolean fNewValue)
        Description copied from interface: AtomicBoolean
        Atomically sets the value to newValue if the current value == expectedValue.
        Specified by:
        compareAndSet in interface AtomicBoolean
        Parameters:
        fExpectedValue - the expected value
        fNewValue - the new value
        Returns:
        true if successful. False return indicates that the actual value was not equal to the expected value.
      • compareAndExchange

        public boolean compareAndExchange​(boolean fExpectedValue,
                                          boolean fNewValue)
        Description copied from interface: AtomicBoolean
        Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue.
        Specified by:
        compareAndExchange in interface AtomicBoolean
        Parameters:
        fExpectedValue - the expected value
        fNewValue - 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<AtomicBoolean,​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<AtomicBoolean,​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