Class AsyncRemoteAtomicBoolean

  • All Implemented Interfaces:
    AsyncAtomicBoolean

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

    Since:
    21.12
    Author:
    Aleks Seovic 2020.12.07
    • Constructor Detail

      • AsyncRemoteAtomicBoolean

        protected AsyncRemoteAtomicBoolean​(AsyncNamedMap<String,​AtomicBoolean> mapAtomic,
                                           String sName)
        Constructs a new AsyncRemoteAtomicBoolean.
        Parameters:
        mapAtomic - the map that holds this atomic value
        sName - the name of this atomic value
    • Method Detail

      • compareAndSet

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