Class LoomQueue<E>

java.lang.Object
com.loomcache.client.LoomQueue<E>

public final class LoomQueue<E> extends Object
Client-side handle to a distributed FIFO queue stored in the cluster.

Supports bounded and unbounded offer/poll/drain operations in both synchronous and asynchronous variants. Large bulk operations are split into server-sized chunks automatically. Obtain instances via LoomClient.getQueue or LoomCache.getQueue; handles are thread-safe.

  • Method Details

    • offer

      public boolean offer(E item)
    • poll

      public @Nullable E poll()
    • take

      public E take() throws InterruptedException
      Removes and returns the head element, blocking until one becomes available.

      LoomCache replicates queue mutations through Raft, and the deterministic apply path must never block, so this is implemented as a bounded client-side poll loop with exponential backoff rather than a server-side park. Semantically it matches a blocking take: it returns only once an element has been removed for this caller, or throws if the calling thread is interrupted. Each underlying poll is an ordinary replicated dequeue.

      Returns:
      the head element (never null)
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting
    • poll

      public @Nullable E poll(Duration timeout) throws InterruptedException
      Removes and returns the head element, blocking up to timeout for one to become available; returns null if the timeout elapses first.

      See take() for why this is a client-side backoff poll loop rather than a server-side wait.

      Parameters:
      timeout - maximum time to wait; must be non-null and non-negative
      Returns:
      the head element, or null if the timeout elapsed
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting
    • peek

      public @Nullable E peek()
    • size

      public int size()
    • offerAll

      public int offerAll(Collection<? extends E> items)
    • poll

      public List<E> poll(int count)
    • drain

      public List<E> drain()
    • drainTo

      public int drainTo(Collection<? super E> target, int maxElements)
    • drainTo

      public int drainTo(Collection<? super E> target)
    • offerAsync

      public CompletableFuture<Boolean> offerAsync(E item)
    • pollAsync

      public CompletableFuture<@Nullable E> pollAsync()
    • peekAsync

      public CompletableFuture<@Nullable E> peekAsync()
    • sizeAsync

      public CompletableFuture<Integer> sizeAsync()
    • offerAllAsync

      public CompletableFuture<Integer> offerAllAsync(Collection<? extends E> items)
    • pollAsync

      public CompletableFuture<List<E>> pollAsync(int count)
    • drainAsync

      public CompletableFuture<List<E>> drainAsync()
    • drainToAsync

      public CompletableFuture<Integer> drainToAsync(Collection<? super E> target, int maxElements)