Interface AsyncAtomicValue<V>

  • Type Parameters:
    V - value type
    All Superinterfaces:
    DistributedPrimitive

    public interface AsyncAtomicValue<V>
    extends DistributedPrimitive
    Distributed version of java.util.concurrent.atomic.AtomicReference.

    All methods of this interface return a future immediately after a successful invocation. The operation itself is executed asynchronous and the returned future will be completed when the operation finishes.

    • Method Detail

      • compareAndSet

        java.util.concurrent.CompletableFuture<java.lang.Boolean> compareAndSet​(V expect,
                                                                                V update)
        Atomically sets the value to the given updated value if the current value is equal to the expected value.

        IMPORTANT: Equality is based on the equality of the serialized {code byte[]} representations.

        Parameters:
        expect - the expected value
        update - the new value
        Returns:
        CompletableFuture that will be completed with true if update was successful. Otherwise future will be completed with a value of false
      • get

        java.util.concurrent.CompletableFuture<V> get()
        Gets the current value.
        Returns:
        CompletableFuture that will be completed with the value
      • getAndSet

        java.util.concurrent.CompletableFuture<V> getAndSet​(V value)
        Atomically sets to the given value and returns the old value.
        Parameters:
        value - the new value
        Returns:
        CompletableFuture that will be completed with the previous value
      • set

        java.util.concurrent.CompletableFuture<java.lang.Void> set​(V value)
        Sets to the given value.
        Parameters:
        value - value to set
        Returns:
        CompletableFuture that will be completed when the operation finishes
      • addListener

        java.util.concurrent.CompletableFuture<java.lang.Void> addListener​(AtomicValueEventListener<V> listener)
        Registers the specified listener to be notified whenever the atomic value is updated.
        Parameters:
        listener - listener to notify about events
        Returns:
        CompletableFuture that will be completed when the operation finishes
      • removeListener

        java.util.concurrent.CompletableFuture<java.lang.Void> removeListener​(AtomicValueEventListener<V> listener)
        Unregisters the specified listener such that it will no longer receive atomic value update notifications.
        Parameters:
        listener - listener to unregister
        Returns:
        CompletableFuture that will be completed when the operation finishes
      • asAtomicValue

        default AtomicValue<V> asAtomicValue​(long timeoutMillis)
        Returns a new AtomicValue that is backed by this instance.
        Parameters:
        timeoutMillis - timeout duration for the returned ConsistentMap operations
        Returns:
        new AtomicValue instance
      • asAtomicValue

        default AtomicValue<V> asAtomicValue()
        Returns a new AtomicValue that is backed by this instance and with a default operation timeout.
        Returns:
        new AtomicValue instance