Class LoomConsistencySubsystem

java.lang.Object
com.loomcache.client.LoomConsistencySubsystem

public final class LoomConsistencySubsystem extends Object
Client-side Consistency Subsystem factory for creating CP primitives.

The CP (Consistency and Partition tolerance) Subsystem provides strongly consistent, fault-tolerant distributed primitives backed by the Raft consensus protocol.

Supported Primitives

Usage Example

LoomClient client = LoomClient.builder()
    .addSeed("127.0.0.1:5701")
    .build();
client.connect();

LoomConsistencySubsystem cp = client.consistencySubsystem();

// Linearizable lock with linearizable guarantees
LoomLinearizableLock lock = cp.getLock("resource-lock");
long fence = lock.lock();
try {
    // Critical section
} finally {
    lock.unlock();
}

// Atomic long for linearizable counters
LoomAtomicLong atomic = cp.getAtomicLong("metrics");
atomic.incrementAndGet();

// Atomic reference for linearizable compare-and-set state
LoomAtomicReference<String> ref = cp.getAtomicReference("leader-state", String.class);
ref.compareAndSet(null, "active");

// Countdown latch for cluster coordination
LoomLinearizableLatch latch = cp.getCountDownLatch("startup");
latch.trySetCount(3);

Thread Safety

This class is thread-safe. All returned proxies are thread-safe and can be shared across threads.
Since:
1.4
See Also:
  • Method Details

    • getLock

      public LoomLinearizableLock getLock(String name)
      Get a distributed linearizable lock proxy.

      The returned lock provides mutual exclusion across the cluster with support for fencing tokens to prevent split-brain anomalies. Lock ownership is tracked via requester IDs and fence tokens provide linearizable guarantees.

      Parameters:
      name - the name of the lock (must not be null)
      Returns:
      a linearizable lock proxy (never null)
      Throws:
      NullPointerException - if name is null
      LoomException - if the cluster is unavailable
      See Also:
    • getAtomicLong

      public LoomAtomicLong getAtomicLong(String name)
      Get a distributed atomic long proxy.

      The returned atomic long provides linearizable 64-bit integer operations across the cluster. Useful for distributed counters with stronger guarantees than eventually-consistent counters. Multiple threads may safely perform atomic operations concurrently.

      Parameters:
      name - the name of the atomic long (must not be null)
      Returns:
      an atomic long proxy (never null)
      Throws:
      NullPointerException - if name is null
      LoomException - if the cluster is unavailable
      See Also:
    • getAtomicReference

      public <T> LoomAtomicReference<T> getAtomicReference(String name, Class<T> type)
      Get a distributed atomic reference proxy.

      The returned atomic reference provides linearizable get, set, and compare-and-set operations across the cluster. Values must be serializable by the configured wire serializer and are type-checked on reads by the supplied class token.

      Type Parameters:
      T - the value type
      Parameters:
      name - the name of the atomic reference (must not be null)
      type - the expected value type (must not be null)
      Returns:
      an atomic reference proxy (never null)
      Throws:
      NullPointerException - if name or type is null
      LoomException - if the cluster is unavailable
      See Also:
    • getCountDownLatch

      public LoomLinearizableLatch getCountDownLatch(String name)
      Get a distributed countdown latch proxy.

      The returned latch provides linearizable count updates and waits across the cluster. Use LoomLinearizableLatch.trySetCount(long) to arm the latch before calling LoomLinearizableLatch.await(java.time.Duration) or LoomLinearizableLatch.countDown().

      Parameters:
      name - the name of the latch (must not be null)
      Returns:
      a countdown latch proxy (never null)
      Throws:
      NullPointerException - if name is null
      LoomException - if the cluster is unavailable
      See Also: