Interface AsyncStrongCounter


public interface AsyncStrongCounter
The strong consistent counter interface.

It provides atomic updates for the counter. All the operations are perform asynchronously and they complete the CompletionStage when completed.

Since:
14.0
  • Method Details

    • name

      String name()
      Returns:
      The counter name.
    • configuration

      Retrieves the counter's configuration.
      Returns:
      this counter's configuration.
    • container

      AsyncContainer container()
      Return the container of this counter
      Returns:
    • value

      It fetches the current value.

      It may go remotely to fetch the current value.

      Returns:
      The current value.
    • incrementAndGet

      default CompletionStage<Long> incrementAndGet()
      Atomically increments the counter and returns the new value.
      Returns:
      The new value.
    • decrementAndGet

      default CompletionStage<Long> decrementAndGet()
      Atomically decrements the counter and returns the new value
      Returns:
      The new value.
    • addAndGet

      CompletionStage<Long> addAndGet(long delta)
      Atomically adds the given value and return the new value.
      Parameters:
      delta - The non-zero value to add. It can be negative.
      Returns:
      The new value.
    • reset

      Resets the counter to its initial value.
    • listen

      Registers a Consumer<CounterEvent> to this counter.
      Parameters:
      listener - The listener to register.
      Returns:
      A AutoCloseable that allows to remove the listener via AutoCloseable.close().
    • compareAndSet

      default CompletionStage<Boolean> compareAndSet(long expect, long update)
      Atomically sets the value to the given updated value if the current value == the expected value.

      It is the same as return compareAndSwap(expect, update).thenApply(value -> value == expect);

      Parameters:
      expect - the expected value
      update - the new value
      Returns:
      true if successful, false otherwise.
    • compareAndSwap

      CompletionStage<Long> compareAndSwap(long expect, long update)
      Atomically sets the value to the given updated value if the current value == the expected value.

      The operation is successful if the return value is equals to the expected value.

      Parameters:
      expect - the expected value.
      update - the new value.
      Returns:
      the previous counter's value.