Class LoomAtomicLong

java.lang.Object
com.loomcache.client.LoomAtomicLong

public final class LoomAtomicLong extends Object
Client-side distributed atomic long proxy.

Provides atomic operations on a 64-bit long stored in the Consistency Subsystem. All operations are linearizable and atomic across the cluster.

Consistency Guarantees

LoomAtomicLong operations are linearizable. This means all operations appear to execute atomically in a total order, providing strong guarantees suitable for critical sections and consensus protocols.

Thread Safety

This class is thread-safe. Multiple threads may perform operations concurrently; the underlying Consistency Subsystem ensures atomicity and visibility.

Usage Example

LoomConsistencySubsystem cp = client.consistencySubsystem();
LoomAtomicLong atomic = cp.getAtomicLong("consensus-counter");

long next = atomic.incrementAndGet();      // 1
long val = atomic.get();                   // 1
atomic.set(0);                             // reset
boolean ok = atomic.compareAndSet(0, 100); // atomic CAS

atomic.getAndIncrement();
Since:
1.4
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    addAndGet(long delta)
    Atomically adds delta to the value and returns the new value.
    boolean
    compareAndSet(long expectedValue, long newValue)
    Atomically sets the value to an expected value if the current value equals expected.
    long
    Atomically decrements the value by 1 and returns the new value.
    long
    get()
    Gets the current value atomically.
    long
    getAndAdd(long delta)
    Atomically gets the current value and adds delta.
    long
    Atomically gets the current value and decrements by 1.
    long
    Atomically gets the current value and increments by 1.
    long
    Atomically increments the value by 1 and returns the new value.
    void
    set(long newValue)
    Sets the value atomically.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public long get()
      Gets the current value atomically.
      Returns:
      the current value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • set

      public void set(long newValue)
      Sets the value atomically.
      Parameters:
      newValue - the new value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • incrementAndGet

      public long incrementAndGet()
      Atomically increments the value by 1 and returns the new value.
      Returns:
      the incremented value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • decrementAndGet

      public long decrementAndGet()
      Atomically decrements the value by 1 and returns the new value.
      Returns:
      the decremented value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • getAndIncrement

      public long getAndIncrement()
      Atomically gets the current value and increments by 1.
      Returns:
      the previous value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • getAndDecrement

      public long getAndDecrement()
      Atomically gets the current value and decrements by 1.
      Returns:
      the previous value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • addAndGet

      public long addAndGet(long delta)
      Atomically adds delta to the value and returns the new value.
      Parameters:
      delta - the amount to add (may be negative)
      Returns:
      the new value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • getAndAdd

      public long getAndAdd(long delta)
      Atomically gets the current value and adds delta.
      Parameters:
      delta - the amount to add (may be negative)
      Returns:
      the previous value
      Throws:
      LoomException - if the operation fails or the cluster is unavailable
    • compareAndSet

      public boolean compareAndSet(long expectedValue, long newValue)
      Atomically sets the value to an expected value if the current value equals expected. This is a compare-and-set (CAS) operation.
      Parameters:
      expectedValue - the expected current value
      newValue - the new value to set if current equals expected
      Returns:
      true if the update succeeded; false otherwise
      Throws:
      LoomException - if the operation fails or the cluster is unavailable