com.msi.network.server
Class Command

java.lang.Object
  extended bycom.msi.network.server.Command

public class Command
extends java.lang.Object

Defines the common API for server commands.

A command is instantiated with a name and generally the default isValid() method will adequately identify that the request is for this command. Subclasses should maintain this behaviour.

Most of the processing occurs in the processCommand method:

 public class myCommand extents Command {
   public boolean processCommand(Connection conn) {
     // do all the magic your command requires:
     //   - update/fetch data from a db
     //   - format your response
     setResponse(yourAnswerObject.toString());
     return true; // indicate success
   }
 }

Version:
1.0
Author:
Ken Thompson

Field Summary
protected  java.lang.String _commandInput
          Describe variable _commandInput here.
protected  CommandProcessor _commandProcessor
          Describe variable _commandProcessor here.
protected  java.lang.String _name
          Each command has a unique string name.
protected  java.lang.String _response
          The response sent to the client including all punctuation.
protected  java.util.StringTokenizer _tokes
          Describe variable _tokes here.
 
Constructor Summary
Command(java.lang.String nm)
          Set the minimum required state for command execution.
 
Method Summary
 java.lang.String getResponse()
          Get the value of _response.
 boolean isLast()
          When a command terminates a client session true is returned.
 boolean isValid()
          Verifies the client supplied information against this command.
 boolean processCommand(Connection conn)
          To be over-ridden in the sub-class implementing the specific command.
 boolean processCommand(java.lang.String cmd, Connection conn, CommandProcessor cmdProc)
          Set the command, and if it is valid do the right thing.
 void setResponse(java.lang.String v)
          Set the value of _response.
 java.lang.String usage()
          Provide a description of the Request Handler syntax and usage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_name

protected java.lang.String _name
Each command has a unique string name. For most servers this is character sequence like 'LOGI' for login. Newer servers using XML may need a more sophisticated comparision than simple strings.


_response

protected java.lang.String _response
The response sent to the client including all punctuation. This includes the newline character if required. Some clients will not process a response that does not end in a newline.

The command response is buffered to support commands requiring response editing.


_commandInput

protected java.lang.String _commandInput
Describe variable _commandInput here.


_commandProcessor

protected CommandProcessor _commandProcessor
Describe variable _commandProcessor here.


_tokes

protected java.util.StringTokenizer _tokes
Describe variable _tokes here.

Constructor Detail

Command

public Command(java.lang.String nm)
Set the minimum required state for command execution.

Parameters:
nm - name of the command used for parsing entry.
Method Detail

isValid

public boolean isValid()
Verifies the client supplied information against this command. The default is a simple case-sensitive comparision between the beginning of the line and the command name such that any input beginning with the command name is a match.

Returns:
true IFF the input command starts with this command name.

processCommand

public boolean processCommand(java.lang.String cmd,
                              Connection conn,
                              CommandProcessor cmdProc)
Set the command, and if it is valid do the right thing. The command processor reads the first line of the client request in order to identify the appropriate command. The provided connection supports connection oriented services where the specific command interacts with the client in a single session. The reference to the calling command processor provides commands with access to other commands and to the overall RequestHandler process.

Parameters:
cmd - the first line of the command sequence.
conn - the communications channel to the client.
cmdProc - reference allowing access to other commands and the server.
Returns:
true if this command is successfully processed, false otherwise.

processCommand

public boolean processCommand(Connection conn)
To be over-ridden in the sub-class implementing the specific command. This method has access to the local copy of the command for parsing. Access to the command processor supports commands which control the server itself.

Parameters:
conn - a Connection value
Returns:
true if this command is successfully processed, false otherwise.

getResponse

public java.lang.String getResponse()
Get the value of _response.

Returns:
value of _response.

setResponse

public void setResponse(java.lang.String v)
Set the value of _response.

Parameters:
v - Value to assign to _response.

isLast

public boolean isLast()
When a command terminates a client session true is returned.

Returns:
true if the command closes the connection, false otherwise.

usage

public java.lang.String usage()
Provide a description of the Request Handler syntax and usage. This should be brief, but comprehensive and a null return indicates there is no help available.

Returns:
informative message on how to use this Request Handler, null if no message.


Copyright © 2001-2002 MileStone Solutions, Inc. All Rights Reserved.