com.lambdaworks.redis.protocol
Class Command<K,V,T>

java.lang.Object
  extended by com.lambdaworks.redis.protocol.Command<K,V,T>
Type Parameters:
T - Command output type.
All Implemented Interfaces:
Future<T>

public class Command<K,V,T>
extends Object
implements Future<T>

A redis command and its result. All successfully executed commands will eventually return a CommandOutput object.

Author:
Will Glozer

Field Summary
protected  CommandArgs<K,V> args
           
protected  CountDownLatch latch
           
protected  CommandOutput<K,V,T> output
           
 CommandType type
           
 
Constructor Summary
Command(CommandType type, CommandOutput<K,V,T> output, CommandArgs<K,V> args, boolean multi)
          Create a new command with the supplied type and args.
 
Method Summary
 boolean await(long timeout, TimeUnit unit)
          Wait up to the specified time for the command output to become available.
 boolean cancel(boolean ignored)
          Cancel the command and notify any waiting consumers.
 void complete()
          Mark this command complete and notify all waiting threads.
 T get()
          Get the command output and if the command hasn't completed yet, wait until it does.
 T get(long timeout, TimeUnit unit)
          Get the command output and if the command hasn't completed yet, wait up to the specified time until it does.
 CommandOutput<K,V,T> getOutput()
          Get the object that holds this command's output.
 boolean isCancelled()
          Check if the command has been cancelled.
 boolean isDone()
          Check if the command has completed.
protected static void writeInt(ChannelBuffer buf, int value)
          Write the textual value of a positive integer to the supplied buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

public final CommandType type

args

protected CommandArgs<K,V> args

output

protected CommandOutput<K,V,T> output

latch

protected CountDownLatch latch
Constructor Detail

Command

public Command(CommandType type,
               CommandOutput<K,V,T> output,
               CommandArgs<K,V> args,
               boolean multi)
Create a new command with the supplied type and args.

Parameters:
type - Command type.
output - Command output.
args - Command args, if any.
multi - Flag indicating if MULTI active.
Method Detail

cancel

public boolean cancel(boolean ignored)
Cancel the command and notify any waiting consumers. This does not cause the redis server to stop executing the command.

Specified by:
cancel in interface Future<T>
Parameters:
ignored - Ignored parameter.
Returns:
true if the command was cancelled.

isCancelled

public boolean isCancelled()
Check if the command has been cancelled.

Specified by:
isCancelled in interface Future<T>
Returns:
True if the command was cancelled.

isDone

public boolean isDone()
Check if the command has completed.

Specified by:
isDone in interface Future<T>
Returns:
true if the command has completed.

get

public T get()
Get the command output and if the command hasn't completed yet, wait until it does.

Specified by:
get in interface Future<T>
Returns:
The command output.

get

public T get(long timeout,
             TimeUnit unit)
      throws TimeoutException
Get the command output and if the command hasn't completed yet, wait up to the specified time until it does.

Specified by:
get in interface Future<T>
Parameters:
timeout - Maximum time to wait for a result.
unit - Unit of time for the timeout.
Returns:
The command output.
Throws:
TimeoutException - if the wait timed out.

await

public boolean await(long timeout,
                     TimeUnit unit)
Wait up to the specified time for the command output to become available.

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.

Returns:
The command output object.

complete

public void complete()
Mark this command complete and notify all waiting threads.


writeInt

protected static void writeInt(ChannelBuffer buf,
                               int value)
Write the textual value of a positive integer to the supplied buffer.

Parameters:
buf - Buffer to write to.
value - Value to write.


Copyright © 2013. All Rights Reserved.