Interface AsyncCounter

  • All Known Implementing Classes:
    COUNTER.CounterImpl

    public interface AsyncCounter
    An asynchronous counter interface.
    Since:
    5.2
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletionStage<java.lang.Long> addAndGet​(long delta)
      Atomically adds the given value to the current value.
      default java.util.concurrent.CompletionStage<java.lang.Boolean> compareAndSet​(long expect, long update)
      Atomically updates the counter using a compare-and-set operation.
      java.util.concurrent.CompletionStage<java.lang.Long> compareAndSwap​(long expect, long update)
      Atomically updates the counter using a compare-and-swap operation.
      default java.util.concurrent.CompletionStage<java.lang.Long> decrementAndGet()
      Atomically decrements the counter and returns the new value
      default java.util.concurrent.CompletionStage<java.lang.Long> get()
      Gets the current value of the counter.
      java.lang.String getName()  
      default java.util.concurrent.CompletionStage<java.lang.Long> incrementAndGet()
      Atomically increments the counter and returns the new value
      java.util.concurrent.CompletionStage<java.lang.Void> set​(long new_value)
      Sets the counter to a new value.
      SyncCounter sync()  
      default <T extends Streamable>
      java.util.concurrent.CompletionStage<T>
      update​(CounterFunction<T> updateFunction)
      Atomically updates the counter's value.
    • Method Detail

      • getName

        java.lang.String getName()
        Returns:
        The counter's name.
      • get

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

        java.util.concurrent.CompletionStage<java.lang.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 java.util.concurrent.CompletionStage<java.lang.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 {@link false} otherwise.
      • compareAndSwap

        java.util.concurrent.CompletionStage<java.lang.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 java.util.concurrent.CompletionStage<java.lang.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 java.util.concurrent.CompletionStage<java.lang.Long> decrementAndGet()
        Atomically decrements the counter and returns the new value
        Returns:
        A CompletionStage that is completed with the new counter's value.
      • addAndGet

        java.util.concurrent.CompletionStage<java.lang.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.
      • sync

        SyncCounter sync()
        Returns:
        a synchronous wrapper around this instance.