Class COUNTER.SyncCounterImpl

java.lang.Object
org.jgroups.protocols.COUNTER.SyncCounterImpl
All Implemented Interfaces:
BaseCounter, Counter, SyncCounter
Enclosing class:
COUNTER

private static class COUNTER.SyncCounterImpl extends Object implements Counter
  • Field Details

  • Constructor Details

    • SyncCounterImpl

      private SyncCounterImpl(AsyncCounter counter)
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface BaseCounter
      Returns:
      The counter's name.
    • get

      public long get()
      Description copied from interface: SyncCounter
      Gets the current value of the counter
      Specified by:
      get in interface SyncCounter
      Returns:
      The current value
    • set

      public void set(long new_value)
      Description copied from interface: SyncCounter
      Sets the counter to a new value
      Specified by:
      set in interface SyncCounter
      Parameters:
      new_value - The new value
    • compareAndSwap

      public long compareAndSwap(long expect, long update)
      Description copied from interface: SyncCounter
      Atomically updates the counter using a compare-and-swap operation.
      Specified by:
      compareAndSwap in interface Counter
      Specified by:
      compareAndSwap in interface SyncCounter
      Parameters:
      expect - The expected value of the counter
      update - The new value of the counter
      Returns:
      The previous value of the counter
    • addAndGet

      public long addAndGet(long delta)
      Description copied from interface: SyncCounter
      Atomically adds the given value to the current value.
      Specified by:
      addAndGet in interface SyncCounter
      Parameters:
      delta - the value to add
      Returns:
      the updated value
    • update

      public <T extends Streamable> T update(CounterFunction<T> updateFunction)
      Description copied from interface: SyncCounter
      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.

      Specified by:
      update in interface SyncCounter
      Type Parameters:
      T - The return value type.
      Parameters:
      updateFunction - The update CounterFunction.
      Returns:
      The function's return value.
      See Also:
    • async

      public AsyncCounter async()
      Description copied from interface: BaseCounter
      Returns an AsyncCounter wrapper for this instance. If this counter is already asynchronous, then this counter instance is returned (no-op)
      Specified by:
      async in interface BaseCounter
      Specified by:
      async in interface Counter
      Returns:
      The AsyncCounter instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object