Class LoomQueue<E>
java.lang.Object
com.loomcache.client.LoomQueue<E>
- Type Parameters:
E- the type of elements in the queue
Client-side distributed queue proxy.
Provides transparent access to a distributed FIFO queue stored in the LoomCache cluster. Elements are inserted at the tail and removed from the head. All operations are routed through the connected LoomClient and may raise LoomException if the cluster becomes unavailable or a timeout occurs.
Thread Safety
This class is thread-safe. Multiple threads may call methods concurrently; the underlying LoomClient handles synchronization and connection pooling.Async API
This class provides both synchronous and asynchronous methods. Async methods return CompletableFuture for non-blocking operations.Usage Example
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("loom-queue");
LoomClient client = LoomClient.builder()
.addSeed("127.0.0.1:5701")
.build();
client.connect();
LoomQueue<String> tasks = client.getQueue("tasks");
tasks.offer("process-order-123");
tasks.offer("send-notification");
String nextTask = tasks.poll(); // "process-order-123"
// Async variant
tasks.offerAsync("process-order-456")
.thenCompose(v -> tasks.pollAsync())
.thenAccept(item -> log.info("Got task: {}", item))
.join();
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptiondrain()Drains the queue into a new list.intdrainTo(Collection<? super E> target) Drains all currently available elements into the supplied target collection.intdrainTo(Collection<? super E> target, int maxElements) Drains up tomaxElementselements into the supplied target collection.drainToAsync(Collection<? super E> target, int maxElements) booleanInserts an element at the tail of the queue.intofferAll(Collection<? extends E> items) Inserts all supplied elements at the tail of the queue.offerAllAsync(Collection<? extends E> items) offerAsync(E item) Asynchronously inserts an element at the tail of the queue.@Nullable Epeek()Returns the element at the head of the queue without removing it.CompletableFuture<@Nullable E> Asynchronously returns the element at the head of the queue without removing it.@Nullable Epoll()Removes and returns the element at the head of the queue.poll(int count) Removes up tocountelements from the head of the queue.CompletableFuture<@Nullable E> Asynchronously removes and returns the element at the head of the queue.pollAsync(int count) intsize()Return the number of items currently in the queue.
-
Method Details
-
offer
Inserts an element at the tail of the queue.- Parameters:
item- the element to add (serialized viaClientSerializer)- Returns:
- true if the element was successfully added; false if the queue is full
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
poll
Removes and returns the element at the head of the queue.This is a non-blocking operation; if the queue is empty, returns null.
- Returns:
- the head element, or null if the queue is empty
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
peek
Returns the element at the head of the queue without removing it.This is a non-blocking, read-only operation; if the queue is empty, returns null.
- Returns:
- the head element, or null if the queue is empty
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
size
public int size()Return the number of items currently in the queue.- Returns:
- queue size, or 0 when the queue does not exist
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
offerAll
Inserts all supplied elements at the tail of the queue.- Parameters:
items- elements to add (serialized viaClientSerializer)- Returns:
- number of elements accepted by the queue
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
poll
Removes up tocountelements from the head of the queue.- Parameters:
count- maximum number of elements to remove- Returns:
- removed elements in FIFO order
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
drain
Drains the queue into a new list.- Returns:
- removed elements in FIFO order
- Throws:
LoomException- if the operation fails or the cluster is unavailable
-
drainTo
Drains up tomaxElementselements into the supplied target collection.- Parameters:
target- collection receiving removed elementsmaxElements- maximum number of elements to remove- Returns:
- number of elements added to
target - Throws:
LoomException- if the operation fails or the cluster is unavailable
-
drainTo
Drains all currently available elements into the supplied target collection.- Parameters:
target- collection receiving removed elements- Returns:
- number of elements added to
target - Throws:
LoomException- if the operation fails or the cluster is unavailable
-
offerAsync
Asynchronously inserts an element at the tail of the queue.- Parameters:
item- the element to add (serialized viaClientSerializer)- Returns:
- a CompletableFuture with true if the element was successfully added; false if the queue is full
-
pollAsync
Asynchronously removes and returns the element at the head of the queue.This is a non-blocking operation; if the queue is empty, returns null.
- Returns:
- a CompletableFuture with the head element, or null if the queue is empty
-
peekAsync
Asynchronously returns the element at the head of the queue without removing it.This is a non-blocking, read-only operation; if the queue is empty, returns null.
- Returns:
- a CompletableFuture with the head element, or null if the queue is empty
-
sizeAsync
-
offerAllAsync
-
pollAsync
-
drainAsync
-
drainToAsync
-