com.crankuptheamps.client
Class Command

java.lang.Object
  extended by com.crankuptheamps.client.Command

public class Command
extends Object

Command is an encapsulation of a single AMPS command sent by the client. Using Command you can build valid commands to be executed either synchronously or asynchronously via the Client execute() and executeAsync() methods. Command is designed to be used as a "builder" enabling AMPS commands to be built easily, for example:


 Client client = new Client(...);
 for(Message m : client.execute(new Command("sow").setTopic("topic"))) { ... }
 

Since:
4.0.0.0

Constructor Summary
Command()
          Create a new Command with no command type or arguments set.
Command(int command_)
          Create a Command with the Command field set.
Command(String command_)
          Create a Command with the Command field set.
 
Method Summary
 Command addAckType(int ackType)
          Adds an additional ackType to the ackTypes already set for this Command.
 int getAckType()
          Get the ackType for this command.
 int getBatchSize()
          Get the batchSize for this command.
 String getBookmark()
          Get the bookmark for this command.
 long getClientSequenceNumber()
          Get the client sequence number for this command.
 int getCommand()
          Return the command type for this command.
 CommandId getCommandId()
           
 String getCorrelationId()
          Returns the correlation Id for this command
 String getData()
          Get the data for this command.
 int getExpiration()
          Get the expiration from this command.
 String getFilter()
          Get the filter for this command.
 String getOptions()
          Get the options for this command.
 String getOrderBy()
          Get the orderBy clause for this command.
 CommandId getQueryId()
          Get the queryId for this command.
 String getSOWKeys()
          Returns the SOW keys on this command.
 CommandId getSubId()
          Get the subId for this command.
 long getTimeout()
          Get the timeout for this command.
 String getTopic()
          Get the topic for this command.
 int getTopN()
          Get the topN value for this command.
 boolean hasExpiration()
          Returns true if this command has an expiration set.
 boolean isSow()
          Returns true if this command queries a SOW.
 boolean isSubscribe()
          Returns true if this command creates a subscription.
 boolean needsSequenceNumber()
          Returns true if this command can be associated with a client sequence number.
protected  CommandId prepare(Client client_)
          Binds self to a given client, preparing a message from that client to be sent.
 Command reset(int command_)
          Resets this command with a new Command type and re-initializes all other fields.
 Command reset(String command_)
          Resets this command with a new Command type and re-initializes all other fields.
 Command setAckType(int ackType)
          Set the ackType for this command.
 Command setBatchSize(int batchSize)
          Set the batchSize for this command.
 Command setBookmark(String bookmark)
          Set the bookmark for this command.
protected  Command setClientSequenceNumber(long seqNumber)
          Sets the client sequence number for this command.
 Command setCommand(int command)
          Set the command type for this command.
 Command setCommandId(CommandId commandId)
          Set the commandId for this command.
 Command setCorrelationId(String correlationId_)
          Sets the correlation Id for this command
 Command setData(byte[] data, int offset, int length)
          Set the data for this command.
 Command setData(String data)
          Set the data for this command.
 Command setExpiration(int expiration)
          Set the expiration for this command.
 Command setFilter(String filter)
          Set the filter for this command.
 Command setOptions(String options)
          Set the options for this command.
 Command setOrderBy(String orderBy)
          Set the orderBy clause for this command.
 Command setQueryId(CommandId queryId)
          Set the queryId for this command.
 Command setSOWKeys(String sowKeys)
          The SowKeys for a command are a comma-separated list of the keys that AMPS assigns to SOW messages.
 Command setSubId(CommandId subId)
          Set the subId for this command.
 Command setSubId(String subId)
          Set the subId for this command.
 Command setTimeout(long timeout)
          Set the timeout for this command.
 Command setTopic(byte[] topic, int offset, int length)
          Set the topic for this command from raw bytes.
 Command setTopic(String topic)
          Set the topic for this command.
 Command setTopN(int topN)
          Set the topN value for this command.
 void unsetExpiration()
          Clears any expiration value set on self.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

public Command()
Create a new Command with no command type or arguments set.

Since:
4.0.0.0

Command

public Command(int command_)
Create a Command with the Command field set.

Parameters:
command_ - A Message.Command value indicating the AMPS command.
Since:
4.0.0.0

Command

public Command(String command_)
Create a Command with the Command field set.

Parameters:
command_ - A string indicating the AMPS command.
Since:
4.0.0.0
Method Detail

getSOWKeys

public String getSOWKeys()
Returns the SOW keys on this command.

Returns:
the sow keys
Since:
4.0.0.0

setSOWKeys

public Command setSOWKeys(String sowKeys)
The SowKeys for a command are a comma-separated list of the keys that AMPS assigns to SOW messages. The SOW key for a message is available through the Message.getSowKey() method on a message.

Parameters:
sowKeys - the sow keys to set
Since:
4.0.0.0

isSubscribe

public boolean isSubscribe()
Returns true if this command creates a subscription.

Returns:
true if this command creates a subscription.
Since:
4.0.0.0

isSow

public boolean isSow()
Returns true if this command queries a SOW.

Returns:
true if this command queries a SOW.
Since:
4.0.0.0

needsSequenceNumber

public boolean needsSequenceNumber()
Returns true if this command can be associated with a client sequence number.

Returns:
true if this command can be associated with a client sequence number.
Since:
4.0.0.0

reset

public Command reset(int command_)
Resets this command with a new Command type and re-initializes all other fields.

Parameters:
command_ - A Message.Command value indicating the AMPS command.
Since:
4.0.0.0

reset

public Command reset(String command_)
Resets this command with a new Command type and re-initializes all other fields.

Parameters:
command_ - A string value indicating the AMPS command.
Since:
4.0.0.0

getCommandId

public CommandId getCommandId()
Returns:
the commandId, which is automatically generated for some command types.
Since:
4.0.0.0

setCommandId

public Command setCommandId(CommandId commandId)
Set the commandId for this command.

Parameters:
commandId - the commandId to set
Since:
4.0.0.0

getQueryId

public CommandId getQueryId()
Get the queryId for this command.

Returns:
the queryId
Since:
4.0.0.0

setQueryId

public Command setQueryId(CommandId queryId)
Set the queryId for this command.

Parameters:
queryId - the queryId to set
Since:
4.0.0.0

getCommand

public int getCommand()
Return the command type for this command.

Returns:
the command
Since:
4.0.0.0

setCommand

public Command setCommand(int command)
Set the command type for this command.

Parameters:
command - the command to set
Since:
4.0.0.0

getTopic

public String getTopic()
Get the topic for this command.

Returns:
the topic
Since:
4.0.0.0

setTopic

public Command setTopic(String topic)
Set the topic for this command.

Parameters:
topic - the topic to set
Since:
4.0.0.0

setTopic

public Command setTopic(byte[] topic,
                        int offset,
                        int length)
Set the topic for this command from raw bytes.

Parameters:
topic - The raw bytes to be used for the topic.
offset - The offset into topic where the topic data begins
length - The length of the topic.
Since:
4.0.0.0

getFilter

public String getFilter()
Get the filter for this command.

Returns:
the filter
Since:
4.0.0.0

setFilter

public Command setFilter(String filter)
Set the filter for this command.

Parameters:
filter - the filter to set
Since:
4.0.0.0

getOrderBy

public String getOrderBy()
Get the orderBy clause for this command.

Returns:
the orderBy
Since:
4.0.0.0

setOrderBy

public Command setOrderBy(String orderBy)
Set the orderBy clause for this command.

Parameters:
orderBy - the orderBy to set
Since:
4.0.0.0

getSubId

public CommandId getSubId()
Get the subId for this command.

Returns:
the subId
Since:
4.0.0.0

setSubId

public Command setSubId(CommandId subId)
Set the subId for this command.

Parameters:
subId - the subId to set
Since:
4.0.0.0

setSubId

public Command setSubId(String subId)
Set the subId for this command.

Parameters:
subId - the subId to set
Since:
4.0.0.0

getBookmark

public String getBookmark()
Get the bookmark for this command.

Returns:
the bookmark
Since:
4.0.0.0

setBookmark

public Command setBookmark(String bookmark)
Set the bookmark for this command.

Parameters:
bookmark - the bookmark to set
Since:
4.0.0.0

getOptions

public String getOptions()
Get the options for this command.

Returns:
the options
Since:
4.0.0.0

setOptions

public Command setOptions(String options)
Set the options for this command. Options are a comma-delimited list.

Parameters:
options - the options to set
Since:
4.0.0.0

getAckType

public int getAckType()
Get the ackType for this command.

Returns:
the ackType
Since:
4.0.0.0

setAckType

public Command setAckType(int ackType)
Set the ackType for this command. Different ackTypes are supported for each command. See the Command Reference for details.

Parameters:
ackType - the ackType to set
Since:
4.0.0.0

addAckType

public Command addAckType(int ackType)
Adds an additional ackType to the ackTypes already set for this Command.

Parameters:
ackType - the ackType to add
Since:
4.0.0.0

getData

public String getData()
Get the data for this command.

Returns:
the data
Since:
4.0.0.0

setData

public Command setData(String data)
Set the data for this command.

Parameters:
data - the data to set
Since:
4.0.0.0

setData

public Command setData(byte[] data,
                       int offset,
                       int length)
Set the data for this command.

Parameters:
data - The raw bytes to be used for the data.
offset - The offset into data where the data begins.
length - The length of the data.
Since:
4.0.0.0

getTimeout

public long getTimeout()
Get the timeout for this command.

Returns:
the timeout
Since:
4.0.0.0

setTimeout

public Command setTimeout(long timeout)
Set the timeout for this command. Notice that the timeout is monitored in the AMPS client, not on the server.

Parameters:
timeout - the timeout to set
Since:
4.0.0.0

getTopN

public int getTopN()
Get the topN value for this command.

Returns:
the topN
Since:
4.0.0.0

setTopN

public Command setTopN(int topN)
Set the topN value for this command. This parameter sets a maximum number of records returned by a SOW query.

Parameters:
topN - the topN to set
Since:
4.0.0.0

getBatchSize

public int getBatchSize()
Get the batchSize for this command.

Returns:
the batchSize
Since:
4.0.0.0

setBatchSize

public Command setBatchSize(int batchSize)
Set the batchSize for this command.

Parameters:
batchSize - the batchSize to set
Since:
4.0.0.0

getExpiration

public int getExpiration()
Get the expiration from this command. This method returns 0 if no expriation is set. Use hasExpiration() to check if an expiration is set.

Returns:
the expiration
Since:
4.0.0.0

hasExpiration

public boolean hasExpiration()
Returns true if this command has an expiration set.

Returns:
true if an expiration is set.
Since:
4.0.0.0

setExpiration

public Command setExpiration(int expiration)
Set the expiration for this command.

Parameters:
expiration - the expiration to set
Since:
4.0.0.0

unsetExpiration

public void unsetExpiration()
Clears any expiration value set on self.

Since:
4.0.0.0

prepare

protected CommandId prepare(Client client_)
Binds self to a given client, preparing a message from that client to be sent.

Parameters:
client_ - The client to bind against
Returns:
The CommandId for this command, if one is set, or null.
Since:
4.0.0.0

setClientSequenceNumber

protected Command setClientSequenceNumber(long seqNumber)
Sets the client sequence number for this command.

Since:
4.0.0.0

getClientSequenceNumber

public long getClientSequenceNumber()
Get the client sequence number for this command.

Returns:
the client sequence number generated for this command, or 0 if none was generated.
Since:
4.0.0.0

setCorrelationId

public Command setCorrelationId(String correlationId_)
Sets the correlation Id for this command

Since:
4.0.0.0

getCorrelationId

public String getCorrelationId()
Returns the correlation Id for this command

Since:
4.0.0.0