Interface DistributedAtomicNumber<T>

All Known Implementing Classes:
DistributedAtomicInteger, DistributedAtomicLong

public interface DistributedAtomicNumber<T>
  • Method Summary

    Modifier and Type
    Method
    Description
    add(T delta)
    Add delta to the current value and return the new value information.
    compareAndSet(T expectedValue, T newValue)
    Atomically sets the value to the given updated value if the current value == the expected value.
    Subtract 1 from the current value and return the new value information.
    void
    forceSet(T newValue)
    Forcibly sets the value of the counter without any guarantees of atomicity.
    get()
    Returns the current value of the counter.
    Add 1 to the current value and return the new value information.
    boolean
    initialize(T value)
    Atomic values are initially set to the equivalent of NULL in a database.
    subtract(T delta)
    Subtract delta from the current value and return the new value information.
    trySet(T newValue)
    Attempt to atomically set the value to the given value.
  • Method Details

    • get

      AtomicValue<T> get() throws Exception
      Returns the current value of the counter. NOTE: if the value has never been set, 0 is returned.
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors
    • compareAndSet

      AtomicValue<T> compareAndSet(T expectedValue, T newValue) throws Exception
      Atomically sets the value to the given updated value if the current value == the expected value. Remember to always check AtomicValue.succeeded().
      Parameters:
      expectedValue - the expected value
      newValue - the new value for the counter
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors
    • trySet

      AtomicValue<T> trySet(T newValue) throws Exception
      Attempt to atomically set the value to the given value. Remember to always check AtomicValue.succeeded().
      Parameters:
      newValue - the value to set
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors
    • initialize

      boolean initialize(T value) throws Exception
      Atomic values are initially set to the equivalent of NULL in a database. Use this method to initialize the value. The value will be set if and only iff the node does not exist.
      Parameters:
      value - the initial value to set
      Returns:
      true if the value was set, false if the node already existed
      Throws:
      Exception - ZooKeeper errors
    • forceSet

      void forceSet(T newValue) throws Exception
      Forcibly sets the value of the counter without any guarantees of atomicity.
      Parameters:
      newValue - the new value
      Throws:
      Exception - ZooKeeper errors
    • increment

      AtomicValue<T> increment() throws Exception
      Add 1 to the current value and return the new value information. Remember to always check AtomicValue.succeeded().
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors
    • decrement

      AtomicValue<T> decrement() throws Exception
      Subtract 1 from the current value and return the new value information. Remember to always check AtomicValue.succeeded().
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors
    • add

      AtomicValue<T> add(T delta) throws Exception
      Add delta to the current value and return the new value information. Remember to always check AtomicValue.succeeded().
      Parameters:
      delta - amount to add
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors
    • subtract

      AtomicValue<T> subtract(T delta) throws Exception
      Subtract delta from the current value and return the new value information. Remember to always check AtomicValue.succeeded().
      Parameters:
      delta - amount to subtract
      Returns:
      value info
      Throws:
      Exception - ZooKeeper errors