Class AsyncLoomClient
java.lang.Object
com.loomcache.client.AsyncLoomClient
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionAsyncLoomClient(LoomClient delegate) Create an async client wrapping the given synchronous client. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the async facade's executor.Async connect to the cluster.intGet the number of connected nodes.booleanCheck if the underlying client is connected.Async map DELETE operation.<R> CompletableFuture<@Nullable R> mapExecuteOnKey(String mapName, String key, EntryProcessor<?, ?, R> processor) CompletableFuture<@Nullable String> Async map GET operation.Async map PUT operation.Async map SIZE operation.<E> Pipelining<E> pipelining(int depth) Create a bounded in-flight helper for async operations issued by one caller thread.queueDrain(String queueName) queueDrainTo(String queueName, int maxElements) queueOffer(String queueName, String item) Async queue OFFER operation (enqueue).queueOfferAll(String queueName, Collection<String> items) CompletableFuture<@Nullable String> Async queue PEEK operation (non-destructive read).CompletableFuture<@Nullable String> Async queue POLL operation (dequeue).queuePollN(String queueName, int count) Async set ADD operation.Async set CLEAR operation.setContains(String setName, String element) Async set CONTAINS operation.Async set REMOVE operation.Async set SIZE operation.voidshutdown()CompletableFuture<@Nullable String> Async topic POLL operation.topicPublish(String topicName, String message) Async topic PUBLISH operation.
-
Constructor Details
-
AsyncLoomClient
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
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
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
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
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
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
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
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
-
queueOfferAll
-
queuePollN
-
queueDrainTo
-
queueDrain
-
setAdd
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
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
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
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
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
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
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
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
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:
closein interfaceAutoCloseable
-