Package io.lettuce.core.protocol
Class AsyncCommand<K,V,T>
- 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 aCommandOutput
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)
protected
AsyncCommand(RedisCommand<K,V,T> command, int count)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
await(long timeout, TimeUnit unit)
Wait up to the specified time for the command output to become available.void
cancel()
Attempts to cancel execution of this command.boolean
cancel(boolean mayInterruptIfRunning)
void
complete()
Mark this command complete and notify all waiting threads.boolean
completeExceptionally(Throwable ex)
Complete this command by attaching the givenexception
.protected void
completeResult()
void
encode(ByteBuf buf)
Encode the command.boolean
equals(Object o)
CommandArgs<K,V>
getArgs()
RedisCommand<K,V,T>
getDelegate()
The underlying command.String
getError()
CommandOutput<K,V,T>
getOutput()
Get the object that holds this command's output.ProtocolKeyword
getType()
int
hashCode()
void
onComplete(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.void
onComplete(Consumer<? super T> action)
Register a command callback for successive command completion that notifies the callback with the command result.void
setOutput(CommandOutput<K,V,T> output)
Set a new output.String
toString()
-
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, 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, whenCompleteAsync
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.CompletionStage
acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, 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, whenCompleteAsync
-
Methods inherited from interface java.util.concurrent.Future
get, get, isCancelled, isDone
-
Methods inherited from interface io.lettuce.core.protocol.RedisCommand
isCancelled, isDone
-
-
-
-
Constructor Detail
-
AsyncCommand
public AsyncCommand(RedisCommand<K,V,T> command)
- Parameters:
command
- the command, must not benull
.
-
AsyncCommand
protected AsyncCommand(RedisCommand<K,V,T> command, int count)
- Parameters:
command
- the command, must not benull
.
-
-
Method Detail
-
await
public boolean await(long timeout, TimeUnit unit)
Wait up to the specified time for the command output to become available.- Specified by:
await
in 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
public CommandOutput<K,V,T> getOutput()
Get the object that holds this command's output.- Specified by:
getOutput
in interfaceRedisCommand<K,V,T>
- Returns:
- The command output object.
-
complete
public void complete()
Mark this command complete and notify all waiting threads.- Specified by:
complete
in interfaceRedisCommand<K,V,T>
-
completeResult
protected void completeResult()
-
completeExceptionally
public boolean completeExceptionally(Throwable ex)
Description copied from interface:RedisCommand
Complete this command by attaching the givenexception
.- Specified by:
completeExceptionally
in interfaceRedisCommand<K,V,T>
- Overrides:
completeExceptionally
in classCompletableFuture<T>
- Parameters:
ex
- the exception- Returns:
true
if this invocation caused this CompletableFuture to transition to a completed state, elsefalse
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
getError
public String getError()
- Specified by:
getError
in interfaceRedisFuture<K>
- Returns:
- error text, if any error occurred.
-
getArgs
public CommandArgs<K,V> getArgs()
- Specified by:
getArgs
in interfaceRedisCommand<K,V,T>
- Returns:
- the current command args.
-
toString
public String toString()
- Overrides:
toString
in classCompletableFuture<T>
-
getType
public ProtocolKeyword getType()
- Specified by:
getType
in interfaceRedisCommand<K,V,T>
- Returns:
- the Redis command type like
SADD
,HMSET
,QUIT
.
-
cancel
public void cancel()
Description copied from interface:RedisCommand
Attempts 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:
cancel
in interfaceRedisCommand<K,V,T>
-
encode
public void encode(ByteBuf buf)
Description copied from interface:RedisCommand
Encode the command.- Specified by:
encode
in interfaceRedisCommand<K,V,T>
- Parameters:
buf
- byte buffer to operate on.
-
setOutput
public void setOutput(CommandOutput<K,V,T> output)
Description copied from interface:RedisCommand
Set a new output. Only possible as long as the command is not completed/cancelled.- Specified by:
setOutput
in interfaceRedisCommand<K,V,T>
- Parameters:
output
- the new command output
-
onComplete
public void onComplete(Consumer<? super T> action)
Description copied from interface:CompleteableCommand
Register a command callback for successive command completion that notifies the callback with the command result.- Specified by:
onComplete
in interfaceCompleteableCommand<K>
- Parameters:
action
- must not benull
.
-
onComplete
public void onComplete(BiConsumer<? super T,Throwable> action)
Description copied from interface:CompleteableCommand
Register a command callback for command completion that notifies the callback with the command result or the failure resulting from command completion.- Specified by:
onComplete
in interfaceCompleteableCommand<K>
- Parameters:
action
- must not benull
.
-
getDelegate
public RedisCommand<K,V,T> getDelegate()
Description copied from interface:DecoratedCommand
The underlying command.- Specified by:
getDelegate
in interfaceDecoratedCommand<K,V,T>
- Returns:
- never
null
.
-
-