Class AsyncLoomClient

java.lang.Object
com.loomcache.client.AsyncLoomClient
All Implemented Interfaces:
AutoCloseable

public class AsyncLoomClient extends Object implements AutoCloseable
Async wrapper for LoomClient using CompletableFuture and a bounded executor.

Design

Wraps the synchronous LoomClient and exposes all operations as CompletableFuture, using a bounded thread pool for non-blocking execution with backpressure.

Usage

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

AsyncLoomClient client = new AsyncLoomClient(syncClient);

client.mapPut("myMap", "key1", "value1")
    .thenCompose(v -> client.mapGet("myMap", "key1"))
    .thenAccept(value -> log.info("Got: {}", value))
    .join();
  • Constructor Details

    • AsyncLoomClient

      public AsyncLoomClient(LoomClient delegate)
      Create an async client wrapping the given synchronous client. The executor uses a bounded thread pool for non-blocking execution.
      Parameters:
      delegate - the synchronous LoomClient to wrap (must not be null)
      Throws:
      NullPointerException - if delegate is null
  • Method Details

    • mapPut

      public CompletableFuture<Void> mapPut(String mapName, String key, String value)
      Async map PUT operation.
      Parameters:
      mapName - the map name (must not be null)
      key - the key (must not be null)
      value - the value to store (must not be null)
      Returns:
      a CompletableFuture completing when the PUT is done
      Throws:
      NullPointerException - if any parameter is null
    • mapGet

      public CompletableFuture<@Nullable String> mapGet(String mapName, String key)
      Async map GET operation.
      Parameters:
      mapName - the map name (must not be null)
      key - the key to retrieve (must not be null)
      Returns:
      a CompletableFuture with the value, or null if not found
      Throws:
      NullPointerException - if any parameter is null
    • mapDelete

      public CompletableFuture<Boolean> mapDelete(String mapName, String key)
      Async map DELETE operation.
      Parameters:
      mapName - the map name (must not be null)
      key - the key to delete (must not be null)
      Returns:
      a CompletableFuture with true if the key existed and was deleted
      Throws:
      NullPointerException - if any parameter is null
    • mapExecuteOnKey

      public <R> CompletableFuture<@Nullable R> mapExecuteOnKey(String mapName, String key, EntryProcessor<?,?,R> processor)
    • mapSize

      public CompletableFuture<Integer> mapSize(String mapName)
      Async map SIZE operation.
      Parameters:
      mapName - the map name (must not be null)
      Returns:
      a CompletableFuture with the number of entries in the map
      Throws:
      NullPointerException - if mapName is null
    • queueOffer

      public CompletableFuture<Boolean> queueOffer(String queueName, String item)
      Async queue OFFER operation (enqueue).
      Parameters:
      queueName - the queue name (must not be null)
      item - the item to enqueue (must not be null)
      Returns:
      a CompletableFuture with true if the operation succeeded
      Throws:
      NullPointerException - if any parameter is null
    • queuePoll

      public CompletableFuture<@Nullable String> queuePoll(String queueName)
      Async queue POLL operation (dequeue).
      Parameters:
      queueName - the queue name (must not be null)
      Returns:
      a CompletableFuture with the dequeued item, or null if queue is empty
      Throws:
      NullPointerException - if queueName is null
    • queuePeek

      public CompletableFuture<@Nullable String> queuePeek(String queueName)
      Async queue PEEK operation (non-destructive read).
      Parameters:
      queueName - the queue name (must not be null)
      Returns:
      a CompletableFuture with the first item without removing it, or null if queue is empty
      Throws:
      NullPointerException - if queueName is null
    • queueSize

      public CompletableFuture<Integer> queueSize(String queueName)
    • queueOfferAll

      public CompletableFuture<Integer> queueOfferAll(String queueName, Collection<String> items)
    • queuePollN

      public CompletableFuture<List<String>> queuePollN(String queueName, int count)
    • queueDrainTo

      public CompletableFuture<List<String>> queueDrainTo(String queueName, int maxElements)
    • queueDrain

      public CompletableFuture<List<String>> queueDrain(String queueName)
    • setAdd

      public CompletableFuture<Boolean> setAdd(String setName, String element)
      Async set ADD operation.
      Parameters:
      setName - the set name (must not be null)
      element - the element to add (must not be null)
      Returns:
      a CompletableFuture with true if the element was added (didn't already exist)
      Throws:
      NullPointerException - if any parameter is null
    • setContains

      public CompletableFuture<Boolean> setContains(String setName, String element)
      Async set CONTAINS operation.
      Parameters:
      setName - the set name (must not be null)
      element - the element to check (must not be null)
      Returns:
      a CompletableFuture with true if the element is in the set
      Throws:
      NullPointerException - if any parameter is null
    • setRemove

      public CompletableFuture<Boolean> setRemove(String setName, String element)
      Async set REMOVE operation.
      Parameters:
      setName - the set name (must not be null)
      element - the element to remove (must not be null)
      Returns:
      a CompletableFuture with true if the element was removed (did exist)
      Throws:
      NullPointerException - if any parameter is null
    • setSize

      public CompletableFuture<Integer> setSize(String setName)
      Async set SIZE operation.
      Parameters:
      setName - the set name (must not be null)
      Returns:
      a CompletableFuture with the number of elements in the set
      Throws:
      NullPointerException - if setName is null
    • setClear

      public CompletableFuture<Void> setClear(String setName)
      Async set CLEAR operation.
      Parameters:
      setName - the set name (must not be null)
      Returns:
      a CompletableFuture completing when the set is cleared
      Throws:
      NullPointerException - if setName is null
    • topicPublish

      public CompletableFuture<Void> topicPublish(String topicName, String message)
      Async topic PUBLISH operation. Publishes a message to all subscribers on the given topic.
      Parameters:
      topicName - the topic name (must not be null)
      message - the message to publish (must not be null)
      Returns:
      a CompletableFuture completing when the publish is done
      Throws:
      NullPointerException - if any parameter is null
    • topicPoll

      public CompletableFuture<@Nullable String> topicPoll(String topicName, long sequenceId)
      Async topic POLL operation. Client-side polling for topic subscription messages.
      Parameters:
      topicName - the topic name (must not be null)
      sequenceId - the last seen sequence ID (to avoid duplicates)
      Returns:
      a CompletableFuture with the message if available, null if no new messages
      Throws:
      NullPointerException - if topicName is null
    • connectAsync

      public CompletableFuture<Void> connectAsync()
      Async connect to the cluster.
      Returns:
      a CompletableFuture completing when the connection is established
    • isConnected

      public boolean isConnected()
      Check if the underlying client is connected. This is a synchronous check (doesn't require a future).
      Returns:
      true if connected to at least one node
    • connectedNodeCount

      public int connectedNodeCount()
      Get the number of connected nodes. This is a synchronous check (doesn't require a future).
      Returns:
      number of connected nodes
    • pipelining

      public <E> Pipelining<E> pipelining(int depth)
      Create a bounded in-flight helper for async operations issued by one caller thread.
      Type Parameters:
      E - result type produced by the pipeline
      Parameters:
      depth - maximum number of in-flight operations
      Returns:
      a new pipeline helper
    • shutdown

      public void shutdown()
    • close

      public void close()
      Close the async facade's executor. Does NOT close the underlying delegate — callers that own the synchronous client are responsible for closing it independently. This allows a shared async wrapper to be torn down without tearing down the long-lived client and every other proxy that uses it. Idempotent and safe to call multiple times.
      Specified by:
      close in interface AutoCloseable