Interface AsyncCounter

All Superinterfaces:
BaseCounter
All Known Implementing Classes:
COUNTER.CounterImpl

public interface AsyncCounter extends BaseCounter
An asynchronous counter interface.
Since:
5.2
  • Method Details

    • get

      default CompletionStage<Long> get()
      Gets the current value of the counter.
      Returns:
      A CompletionStage that is completed with the counter's value.
    • set

      CompletionStage<Void> set(long new_value)
      Sets the counter to a new value.
      Returns:
      A CompletionStage that is completed with the counter's value is updated.
    • compareAndSet

      default CompletionStage<Boolean> compareAndSet(long expect, long update)
      Atomically updates the counter using a compare-and-set operation.
      Parameters:
      expect - The expected value of the counter
      update - The new value of the counter
      Returns:
      A CompletionStage that is completed with true if the counter is updated and false otherwise.
    • compareAndSwap

      CompletionStage<Long> compareAndSwap(long expect, long update)
      Atomically updates the counter using a compare-and-swap operation.
      Parameters:
      expect - The expected value of the counter
      update - The new value of the counter
      Returns:
      A CompletionStage that is completed with the current counter's value.
    • incrementAndGet

      default CompletionStage<Long> incrementAndGet()
      Atomically increments the counter and returns the new value
      Returns:
      A CompletionStage that is completed with the new counter's value.
    • decrementAndGet

      default CompletionStage<Long> decrementAndGet()
      Atomically decrements the counter and returns the new value
      Returns:
      A CompletionStage that is completed with the new counter's value.
    • addAndGet

      CompletionStage<Long> addAndGet(long delta)
      Atomically adds the given value to the current value.
      Parameters:
      delta - the value to add
      Returns:
      A CompletionStage that is completed with the updated counter's value.
    • update

      default <T extends Streamable> CompletionStage<T> update(CounterFunction<T> updateFunction)
      Atomically updates the counter's value.

      Both CounterFunction and return value must implement Streamable to be sent over the network. The function should not block thread since it can cause deadlocks neither invoke any operation over the AsyncCounter.

      The CounterView is a copy of the counter's value and the last CounterView.set(long) will be applied to the counter.

      Type Parameters:
      T - The return value type.
      Parameters:
      updateFunction - The update CounterFunction.
      Returns:
      The CompletionStage which will be completed with the CounterFunction return value.
      See Also:
    • async

      default AsyncCounter async()
      Description copied from interface: BaseCounter
      Returns an AsyncCounter wrapper for this instance. If this counter is already asynchronous, then this counter instance is returned (no-op)
      Specified by:
      async in interface BaseCounter
      Returns:
      The AsyncCounter instance.