com.adventnet.cli
Class CLIMessage

java.lang.Object
  |
  +--com.adventnet.cli.CLIMessage

public class CLIMessage
extends java.lang.Object
implements java.io.Serializable

This class contains the CLI command(message) to be sent. Other parameters such as the CLIProtocolOptions can be set so that the message can be sent to the appropriate device. API users had to instantiate this class with the message to be sent and pass it to send() or syncSend() in CLISession class to send the message.

See Also:
CLISession.send(CLIMessage cliMsg), CLISession.syncSend(CLIMessage cliMsg), Serialized Form

Constructor Summary
CLIMessage(byte[] data)
          Constructs a CLI Message with the byte[] data.
CLIMessage(java.lang.String data)
          Constructs a CLI Message with the String message
 
Method Summary
 java.lang.Object clone()
          Returns an exact copy of this CLIMessage object.
 java.lang.String getCLIPrompt()
          Gets the CLIPrompt for the message.
 java.util.Properties getCLIPromptAction()
          Gets the list of prompts and its corresponding commands.
 CLIProtocolOptions getCLIProtocolOptions()
          Gets the CLIProtocolOptions for this message.
 java.lang.String getData()
          Gets the CLI message.
 java.lang.String getMessageSuffix()
          Gets the message suffix for the message.
 int getMsgID()
          Gets the messageID for this message.
 boolean getPartialResponse()
          Gets the partial response flag.
 int getRequestTimeout()
          Gets the request timeout in milliseconds for this request message.
 boolean isSetCommandEcho()
          Gets the command echo flag.
 boolean isSetPromptEcho()
          Gets the prompt echo flag.
 void setCLIPrompt(java.lang.String cliPrompt)
          Sets the CLIPrompt for the message.
 void setCLIPromptAction(java.util.Properties prop)
          Sets the prompt list.
 void setCLIProtocolOptions(CLIProtocolOptions cliProtocolOptions)
          Sets the CLIProtocolOptions for the message.
 void setCommandEcho(boolean cmdEcho)
          Sets the command echo flag to enable/disable the echoing of commands.
 void setData(byte[] data)
          Sets the message in byte[] that has to be sent.
 void setData(java.lang.String data)
          Sets the message in String that is to be sent.
 void setMessageSuffix(java.lang.String suffix)
          Sets the message suffix for the message.
 void setMsgID(int id)
          Sets the messageID for this message.
 void setPartialResponse(boolean flag)
          Sets the partial response flag.
 void setPromptEcho(boolean promptEcho)
          Sets the prompt echo flag to enable/disable the echoing of prompts.
 void setRequestTimeout(int timeout)
          Sets the timeout value in milliseconds for this request message.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CLIMessage

public CLIMessage(java.lang.String data)
Constructs a CLI Message with the String message
Parameters:
data - the CLI command data

For example, the following code can be used to set the various parameters

 CLIMessage cliMsg = new CLIMessage("date");
 cliMsg.setCLIPrompt("$");
 cliMsg.setCommandEcho(false);
 cliMsg.setPromptEcho(false);
 cliMsg.setRequestTimeout(2000);

 

Sending the above message, using cliSession.syncSend(cliMsg) will give the response for the "date" command without the echoed command or prompt (a $). The timeout value for the request will be 2000 milliseconds. Note that parameters set on the CLIMessage will override those set on the CLISession.

CLIMessage

public CLIMessage(byte[] data)
Constructs a CLI Message with the byte[] data.
Parameters:
data - the CLI command as a byte array.
Method Detail

setData

public void setData(byte[] data)
Sets the message in byte[] that has to be sent.
Parameters:
data - the CLI command data as a byte array.

setData

public void setData(java.lang.String data)
Sets the message in String that is to be sent.
Parameters:
data - the CLI command as a String.

getData

public java.lang.String getData()
Gets the CLI message.
Returns:
the CLI command as a String.

setMsgID

public void setMsgID(int id)
Sets the messageID for this message. The message Id is used to match the Commands sent with the responses for asynchronous communication. The API user need not set this because it is generated internally.
Parameters:
id - the message id.

getMsgID

public int getMsgID()
Gets the messageID for this message.
Returns:
msgID the message id.

setCLIProtocolOptions

public void setCLIProtocolOptions(CLIProtocolOptions cliProtocolOptions)
Sets the CLIProtocolOptions for the message. This parameter is used to connect to the appropriate device. In most cases, CLIProtocolOptions contain parameters such as the Remote Host Address , Remote Port, etc.
Parameters:
cliProtocolOptions - the CLIProtocolOptions instance which contains the destination device's information (for example: remote host address, port, etc.).

getCLIProtocolOptions

public CLIProtocolOptions getCLIProtocolOptions()
Gets the CLIProtocolOptions for this message.
Returns:
the CLIProtocolOptions for the device.

setCLIPrompt

public void setCLIPrompt(java.lang.String cliPrompt)
Sets the CLIPrompt for the message. The prompt refers to the String issued by the remote host/device after a successful connection establishment and/or login (example: a $ prompt).
Parameters:
cliPrompt - The CLI prompt as a String.

getCLIPrompt

public java.lang.String getCLIPrompt()
Gets the CLIPrompt for the message.
Returns:
The CLI Prompt for the message.

setCommandEcho

public void setCommandEcho(boolean cmdEcho)
Sets the command echo flag to enable/disable the echoing of commands. Commands sent to a device are usually echoed back to the sender. This method can disable or enable this behavior.
Parameters:
cmdEcho - boolean to indicate whether to enable or disable the command echoing. Setting to false disables echoing of commands.

isSetCommandEcho

public boolean isSetCommandEcho()
Gets the command echo flag. This method can be used to check whether echoing of commands is enabled or not.
Returns:
the command echo flag.

setPromptEcho

public void setPromptEcho(boolean promptEcho)
Sets the prompt echo flag to enable/disable the echoing of prompts. Normally all the CLI devices issue back the prompt after a completion of executing the Command. This method can be used to enable or disable this behavior.
Parameters:
promptEcho - boolean to indicate whether to enable or disable the prompt echoing. Setting to false disables echoing of prompts.

isSetPromptEcho

public boolean isSetPromptEcho()
Gets the prompt echo flag. This method can be used to check whether the prompt echoing is enabled or not.
Returns:
the prompt echo flag.

setRequestTimeout

public void setRequestTimeout(int timeout)
Sets the timeout value in milliseconds for this request message. If the response is not received within this time, a time out occurs and an Exception is thrown.
Parameters:
timeout - the timeout value in milliseconds for which the session waits for the response.

getRequestTimeout

public int getRequestTimeout()
Gets the request timeout in milliseconds for this request message.
Returns:
the timeout in milliseconds.

setMessageSuffix

public void setMessageSuffix(java.lang.String suffix)
Sets the message suffix for the message. This will be appended at the end of the message sent (for example, appended to the data set using setData()).
Parameters:
suffix - the message suffix.

getMessageSuffix

public java.lang.String getMessageSuffix()
Gets the message suffix for the message.
Returns:
the message suffix.

getCLIPromptAction

public java.util.Properties getCLIPromptAction()
Gets the list of prompts and its corresponding commands. This is the list of prompts, one of which will be returned by the device after execution of a command. In the properties, the prompts will have a command/action defined for it. When a prompt is encountered, the command corresponding to the prompt is sent by the session. When no action or command is to be sent for a prompt, it can have an empty value.
  
 (i.e.) prop.setProperty(prompt,""); 
 
and this will be assumed as the command prompt. Note that this will take precedence over the CLISession.getCLIPromptAction() method when a command is sent.
Returns:
a Properties object having the prompts and the corresponding commands.

setCLIPromptAction

public void setCLIPromptAction(java.util.Properties prop)
Sets the prompt list. This method is used for setting the possible prompts, the device can return after executing a command. The session will wait for one of the prompts to be returned by the device, for a command sent. If any command is to be sent for the prompt received, the command can be set as the value of the prompt. The command corresponding to the matched prompt will be sent by the device.
        prop.setProperty(prompt, cmd);
 

Note that this will take precedence over the CLISession.setCLIPromptAction(Properties) method when a command is sent.

Parameters:
prop - a Properties object having the prompts and the corresponding commands.

getPartialResponse

public boolean getPartialResponse()
Gets the partial response flag. When the complete response for a command is not obtained, and the request to the device has timed out, this flag is set to true and the partial response is returned to the user. By default this is set to "false".
Returns:
true, if only a part of response is obtained.

setPartialResponse

public void setPartialResponse(boolean flag)
Sets the partial response flag. This flag indicates that the response obtained is only partial. When the complete response for a command is not obtained, and the request to the device has timed out, this flag is set to true and the partial response is returned to the user.
Parameters:
flag - the partial response flag.

clone

public java.lang.Object clone()
Returns an exact copy of this CLIMessage object.
Overrides:
clone in class java.lang.Object
Returns:
the clone of this object.


Copyright (c)AdventNet Inc., 1996-2003