Interface SyncCounter

  • All Superinterfaces:
    BaseCounter
    All Known Subinterfaces:
    Counter

    public interface SyncCounter
    extends BaseCounter
    A synchronous counter interface
    Since:
    5.2
    Author:
    Bela Ban, Pedro Ruivo
    • 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.
      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
      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 SyncCounter sync()
      Returns a SyncCounter wrapper for this instance.
      default <T extends Streamable>
      T
      update​(CounterFunction<T> updateFunction)
      Atomically updates the counter's value.
    • Method Detail

      • 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
      • sync

        default SyncCounter sync()
        Description copied from interface: BaseCounter
        Returns a SyncCounter wrapper for this instance. If this counter is already synchronous, then this counter instance is returned (no-op)
        Specified by:
        sync in interface BaseCounter
        Returns:
        The SyncCounter instance;