Interface SyncCounter

  • All Known Subinterfaces:
    Counter
    All Known Implementing Classes:
    COUNTER.SyncCounterImpl

    public interface SyncCounter
    A synchronous counter interface
    Since:
    5.2
    • Method Summary

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

      • getName

        java.lang.String getName()
      • get

        long get()
        Gets the current value of the counter
        Returns:
        The current value
      • set

        void set​(long new_value)
        Sets the counter to a new value
        Parameters:
        new_value - The new value
      • compareAndSet

        default boolean compareAndSet​(long expect,
                                      long update)
        Atomically updates the counter using a CAS operation
        Parameters:
        expect - The expected value of the counter
        update - The new value of the counter
        Returns:
        True if the counter could be updated, false otherwise
      • compareAndSwap

        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:
        The previous value of the counter
      • incrementAndGet

        default long incrementAndGet()
        Atomically increments the counter and returns the new value
        Returns:
        The new value
      • decrementAndGet

        default long decrementAndGet()
        Atomically decrements the counter and returns the new value
        Returns:
        The new value
      • addAndGet

        long addAndGet​(long delta)
        Atomically adds the given value to the current value.
        Parameters:
        delta - the value to add
        Returns:
        the updated value
      • async

        AsyncCounter async()
        Returns:
        an asynchronous wrapper around this instance.