Interface Counter


public interface Counter
An asynchronous counter that can be used to across the cluster to maintain a consistent count.

Author:
Tim Fox
  • Method Summary

    Modifier and Type
    Method
    Description
    addAndGet(long value)
    Add the value to the counter atomically and return the new count
    compareAndSet(long expected, long value)
    Set the counter to the specified value only if the current value is the expectec value.
    Decrement the counter atomically and return the new count
    get()
    Get the current value of the counter
    getAndAdd(long value)
    Add the value to the counter atomically and return the value before the add
    Increment the counter atomically and return the value before the increment.
    Increment the counter atomically and return the new count
  • Method Details

    • get

      Future<Long> get()
      Get the current value of the counter
      Returns:
      a future notified with the value
    • incrementAndGet

      Future<Long> incrementAndGet()
      Increment the counter atomically and return the new count
      Returns:
      a future notified with the value
    • getAndIncrement

      Future<Long> getAndIncrement()
      Increment the counter atomically and return the value before the increment.
      Returns:
      a future notified with the value
    • decrementAndGet

      Future<Long> decrementAndGet()
      Decrement the counter atomically and return the new count
      Returns:
      a future notified with the value
    • addAndGet

      Future<Long> addAndGet(long value)
      Add the value to the counter atomically and return the new count
      Parameters:
      value - the value to add
      Returns:
      a future notified with the value
    • getAndAdd

      Future<Long> getAndAdd(long value)
      Add the value to the counter atomically and return the value before the add
      Parameters:
      value - the value to add
      Returns:
      a future notified with the value
    • compareAndSet

      Future<Boolean> compareAndSet(long expected, long value)
      Set the counter to the specified value only if the current value is the expectec value. This happens atomically.
      Parameters:
      expected - the expected value
      value - the new value
      Returns:
      a future notified with true on success