Interface SyncCounter

All Superinterfaces:
BaseCounter
All Known Subinterfaces:
Counter
All Known Implementing Classes:
COUNTER.SyncCounterImpl

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

    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
    Atomically decrements the counter and returns the new value
    long
    get()
    Gets the current value of the counter
    default long
    Atomically increments the counter and returns the new value
    void
    set(long new_value)
    Sets the counter to a new value
    default SyncCounter
    Returns a SyncCounter wrapper for this instance.
    default <T extends Streamable>
    T
    update(CounterFunction<T> updateFunction)
    Atomically updates the counter's value.

    Methods inherited from interface org.jgroups.blocks.atomic.BaseCounter

    async, getName
  • Method Details

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

      default <T extends Streamable> 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 SyncCounter.

      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 function's return value.
      See Also:
    • 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;