Interface AsyncAtomicBoolean

All Known Implementing Classes:
AsyncLocalAtomicBoolean, AsyncRemoteAtomicBoolean

public interface AsyncAtomicBoolean
A boolean value that may be updated atomically.

Unlike AtomicBoolean, each method from this interface is non-blocking, which allows asynchronous invocation and consumption of the return value via CompletableFuture API. This is particularly useful when using remote implementation, because of relatively high latency associated with an inevitable network call, but we do provide a local implementation as well.

An AsyncAtomicBoolean is used in applications such as atomically updated flags, and cannot be used as a replacement for a Boolean.

Since:
21.12
Author:
Aleks Seovic 2020.12.07
  • Method Details

    • get

      Returns the current value.
      Returns:
      the current value
    • set

      CompletableFuture<Void> set(boolean fNewValue)
      Sets the value to newValue.
      Parameters:
      fNewValue - the new value
      Returns:
      a CompletableFuture that can be used to determine whether the operation completed
    • getAndSet

      CompletableFuture<Boolean> getAndSet(boolean fNewValue)
      Atomically sets the value to newValue and returns the old value.
      Parameters:
      fNewValue - the new value
      Returns:
      the previous value
    • compareAndSet

      CompletableFuture<Boolean> compareAndSet(boolean fExpectedValue, boolean fNewValue)
      Atomically sets the value to newValue if the current value == expectedValue.
      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

      CompletableFuture<Boolean> compareAndExchange(boolean fExpectedValue, boolean fNewValue)
      Atomically sets the value to newValue if the current value, referred to as the witness value, == expectedValue.
      Parameters:
      fExpectedValue - the expected value
      fNewValue - the new value
      Returns:
      the witness value, which will be the same as the expected value if successful