java.lang.Object
java.util.concurrent.CompletableFuture<T>
io.lettuce.core.protocol.AsyncCommand<K,V,T>
- Type Parameters:
K- Key type.V- Value type.T- Command output type.
- All Implemented Interfaces:
CompleteableCommand<T>,DecoratedCommand<K,V,T>,RedisCommand<K,V,T>,RedisFuture<T>,CompletionStage<T>,Future<T>
- Direct Known Subclasses:
TransactionalCommand
public class AsyncCommand<K,V,T> extends CompletableFuture<T> implements RedisCommand<K,V,T>, RedisFuture<T>, CompleteableCommand<T>, DecoratedCommand<K,V,T>
An asynchronous redis command and its result. All successfully executed commands will eventually return a
CommandOutput object.- Author:
- Mark Paluch
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask -
Constructor Summary
Constructors Modifier Constructor Description AsyncCommand(RedisCommand<K,V,T> command)protectedAsyncCommand(RedisCommand<K,V,T> command, int count) -
Method Summary
Modifier and Type Method Description booleanawait(long timeout, TimeUnit unit)Wait up to the specified time for the command output to become available.voidcancel()Attempts to cancel execution of this command.booleancancel(boolean mayInterruptIfRunning)voidcomplete()Mark this command complete and notify all waiting threads.booleancompleteExceptionally(Throwable ex)Complete this command by attaching the givenexception.protected voidcompleteResult()voidencode(ByteBuf buf)Encode the command.booleanequals(Object o)CommandArgs<K,V>getArgs()RedisCommand<K,V,T>getDelegate()The underlying command.StringgetError()CommandOutput<K,V,T>getOutput()Get the object that holds this command's output.ProtocolKeywordgetType()inthashCode()voidonComplete(BiConsumer<? super T,Throwable> action)Register a command callback for command completion that notifies the callback with the command result or the failure resulting from command completion.voidonComplete(Consumer<? super T> action)Register a command callback for successive command completion that notifies the callback with the command result.voidsetOutput(CommandOutput<K,V,T> output)Set a new output.StringtoString()Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completeAsync, completeAsync, completedFuture, completedStage, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsyncMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.CompletionStage
acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsyncMethods inherited from interface java.util.concurrent.Future
get, get, isCancelled, isDoneMethods inherited from interface io.lettuce.core.protocol.RedisCommand
isCancelled, isDone
-
Constructor Details
-
AsyncCommand
- Parameters:
command- the command, must not benull.
-
AsyncCommand
- Parameters:
command- the command, must not benull.
-
-
Method Details
-
await
Wait up to the specified time for the command output to become available.- Specified by:
awaitin interfaceRedisFuture<K>- Parameters:
timeout- Maximum time to wait for a result.unit- Unit of time for the timeout.- Returns:
- true if the output became available.
-
getOutput
Get the object that holds this command's output.- Specified by:
getOutputin interfaceRedisCommand<K,V,T>- Returns:
- The command output object.
-
complete
public void complete()Mark this command complete and notify all waiting threads.- Specified by:
completein interfaceRedisCommand<K,V,T>
-
completeResult
protected void completeResult() -
completeExceptionally
Description copied from interface:RedisCommandComplete this command by attaching the givenexception.- Specified by:
completeExceptionallyin interfaceRedisCommand<K,V,T>- Overrides:
completeExceptionallyin classCompletableFuture<T>- Parameters:
ex- the exception- Returns:
trueif this invocation caused this CompletableFuture to transition to a completed state, elsefalse
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
getError
- Specified by:
getErrorin interfaceRedisFuture<K>- Returns:
- error text, if any error occurred.
-
getArgs
- Specified by:
getArgsin interfaceRedisCommand<K,V,T>- Returns:
- the current command args.
-
toString
- Overrides:
toStringin classCompletableFuture<T>
-
getType
- Specified by:
getTypein interfaceRedisCommand<K,V,T>- Returns:
- the Redis command type like
SADD,HMSET,QUIT.
-
cancel
public void cancel()Description copied from interface:RedisCommandAttempts to cancel execution of this command. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason.- Specified by:
cancelin interfaceRedisCommand<K,V,T>
-
encode
Description copied from interface:RedisCommandEncode the command.- Specified by:
encodein interfaceRedisCommand<K,V,T>- Parameters:
buf- byte buffer to operate on.
-
setOutput
Description copied from interface:RedisCommandSet a new output. Only possible as long as the command is not completed/cancelled.- Specified by:
setOutputin interfaceRedisCommand<K,V,T>- Parameters:
output- the new command output
-
onComplete
Description copied from interface:CompleteableCommandRegister a command callback for successive command completion that notifies the callback with the command result.- Specified by:
onCompletein interfaceCompleteableCommand<K>- Parameters:
action- must not benull.
-
onComplete
Description copied from interface:CompleteableCommandRegister a command callback for command completion that notifies the callback with the command result or the failure resulting from command completion.- Specified by:
onCompletein interfaceCompleteableCommand<K>- Parameters:
action- must not benull.
-
getDelegate
Description copied from interface:DecoratedCommandThe underlying command.- Specified by:
getDelegatein interfaceDecoratedCommand<K,V,T>- Returns:
- never
null.
-
equals
-
hashCode
public int hashCode()
-