com.foxsmart.ic.net
Interface CliProtocolHandler

All Superinterfaces:
ProtocolHandler
All Known Implementing Classes:
AbstractCliProtocolHandler, CommonsTelnetProtocolHandler, MindTermSshProtocolHandler, MindTermSshProtocolHandlerImpl, PlinkSshProtocolHandler

public interface CliProtocolHandler
extends ProtocolHandler

The CliProtocolHandler handles the communications for various command line interface (CLI) protocols in a consistent manner.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.foxsmart.ic.net.ProtocolHandler
ProtocolHandler.Protocol
 
Field Summary
static java.lang.String CR
          A carriage return character.
static int DEFAULT_NO_DATA_READ_DELAY
          The number of 1/10 second increments that must pass without getting data before we consider a new data read complete.
static java.lang.String PASSWORD_PROMPT
          A password prompt.
static java.lang.String USERNAME_PROMPT
          A username prompt.
 
Fields inherited from interface com.foxsmart.ic.net.ProtocolHandler
DEFAULT_PROTOCOL_TIMEOUT_SECONDS
 
Method Summary
 void connect(java.lang.String hostname, java.lang.Integer port, java.lang.String username, java.lang.String password, java.lang.Integer timeout)
          Connects to the hostname at the specified port number and authenticates with the remote device.
 void disconnect()
          Disconnects the socket connection.
 java.lang.String expect(java.util.List matches)
          Reads data from the device until one of the expected strings is found.
 java.lang.String expect(java.util.List matches, boolean includeMatch)
          Reads data from the device until one of the expected strings is found.
 java.lang.String expect(java.util.List matches, boolean includeMatch, java.lang.Integer timeout)
          Reads data from the device until one of a list of expected strings is found.
 java.lang.String expect(java.lang.String match)
          Reads data from the device until the expected string is found.
 java.lang.String expect(java.lang.String match, boolean includeMatch)
          Reads data from the device until the expected string is found.
 java.lang.String expect(java.lang.String match, boolean includeMatch, java.lang.Integer timeout)
          Reads data from the device until the expected string is found.
 java.lang.String getAscii(java.lang.String string, int pos)
          Gets a formatted ASCII dump of the passed in string.
 int getDefaultNoDataReadDelay()
          Gets the default no data read delay.
 java.io.InputStream getInputStream()
          Returns the connection input stream.
 java.io.OutputStream getOutputStream()
          Returns the connection output stream.
 boolean getPasswordUsed()
          Gets whether the password was used for authentication.
 boolean getUsernameUsed()
          Gets whether the username was used for authentication.
 boolean isConnected()
          Returns true if the client is currently connected to a server.
 java.lang.String read()
          Reads the next set of data from the device until enough time has passed that we assume no more data will arrive.
 java.lang.String read(java.lang.Integer timeout)
          Reads the next set of data from the device until enough time has passed that we assume no more data will arrive.
 void sendCommand(java.lang.String command)
          Sends a command to the device.
 void sendCommand(java.lang.String command, boolean containsPassword)
          Sends a command to the device.
 void setDefaultNoDataReadDelay(int delay)
          Modifies the default no data read delay in 1/10 seconds.
 void setPasswordUsed(boolean passwordUsed)
          Sets whether the password was used for authentication.
 void setUsernameUsed(boolean usernameUsed)
          Sets whether the username was used for authentication.
 void write(java.lang.String text)
          Writes the specified string to the device.
 
Methods inherited from interface com.foxsmart.ic.net.ProtocolHandler
getAvailable, getDefaultProtocolTimeout, getProtocol, setDefaultProtocolTimeout
 

Field Detail

USERNAME_PROMPT

static final java.lang.String USERNAME_PROMPT
A username prompt.

See Also:
Constant Field Values

PASSWORD_PROMPT

static final java.lang.String PASSWORD_PROMPT
A password prompt.

See Also:
Constant Field Values

CR

static final java.lang.String CR
A carriage return character.

See Also:
Constant Field Values

DEFAULT_NO_DATA_READ_DELAY

static final int DEFAULT_NO_DATA_READ_DELAY
The number of 1/10 second increments that must pass without getting data before we consider a new data read complete.

See Also:
Constant Field Values
Method Detail

connect

void connect(java.lang.String hostname,
             java.lang.Integer port,
             java.lang.String username,
             java.lang.String password,
             java.lang.Integer timeout)
             throws java.lang.Exception
Connects to the hostname at the specified port number and authenticates with the remote device. A socket connection will be established when this call is complete.

Parameters:
hostname - The name of the remote host.
port - The port to connect to on the remote host. If null is passed in, a default port will be used.
username - The username to connect with. Null should be passed in if no username is required.
password - The password to connect with. Null should be passed in if no password is required.
timeout - The timeout in seconds. If null is passed in, a default timeout will be used.
Throws:
AuthenticationFailedException - when a successful connection could not be made
java.net.SocketException - if the socket timeout could not be set.
java.io.IOException - if the socket could not be opened. In most cases you will only want to catch IOException since SocketException is derived from it.
ThreadTimeoutException - if a timeout occurred while connecting to the router.
java.net.UnknownHostException - If the hostname cannot be resolved.
java.lang.Exception - if any other problems were encountered.

isConnected

boolean isConnected()
Returns true if the client is currently connected to a server.

Returns:
True if the client is currently connected to a server, false otherwise.

disconnect

void disconnect()
                throws java.io.IOException
Disconnects the socket connection.

Throws:
java.io.IOException - If there is an error closing the socket.

setUsernameUsed

void setUsernameUsed(boolean usernameUsed)
Sets whether the username was used for authentication.

Parameters:
usernameUsed - True if the username was used or false if not.

getUsernameUsed

boolean getUsernameUsed()
Gets whether the username was used for authentication.

Returns:
True if the username was used or false if not.

setPasswordUsed

void setPasswordUsed(boolean passwordUsed)
Sets whether the password was used for authentication.

Parameters:
passwordUsed - True if the password was used or false if not.

getPasswordUsed

boolean getPasswordUsed()
Gets whether the password was used for authentication.

Returns:
True if the password was used or false if not.

getInputStream

java.io.InputStream getInputStream()
Returns the connection input stream. You should not close the stream when you finish with it. Rather, you should call disconnect.

Returns:
The connection input stream.

getOutputStream

java.io.OutputStream getOutputStream()
Returns the connection output stream. You should not close the stream when you finish with it. Rather, you should call disconnect.

Returns:
the connection output stream.

write

void write(java.lang.String text)
           throws java.io.IOException
Writes the specified string to the device.

Parameters:
text - The text to write to the device.
Throws:
java.io.IOException - if there was a problem writing the data.

sendCommand

void sendCommand(java.lang.String command)
                 throws java.io.IOException
Sends a command to the device. This method functions the same as calling the write method with the exception that a carriage return is appended. This method is the same as sendCommand(command, false).

Parameters:
command - The command to send to the device.
Throws:
java.io.IOException - if there was a problem sending the command.

sendCommand

void sendCommand(java.lang.String command,
                 boolean containsPassword)
                 throws java.io.IOException
Sends a command to the device. This method functions the same as calling the write method with the exception that a carriage return is appended.

Parameters:
command - The command to send to the device.
containsPassword - true if the command contains a password or false if not. Send true to cause the password to only be logged in "trace" mode.
Throws:
java.io.IOException - if there was a problem sending the command.

expect

java.lang.String expect(java.lang.String match,
                        boolean includeMatch)
                        throws java.lang.Exception
Reads data from the device until the expected string is found. Once the expected string is found, the data buffer up to the point where the string was found is returned. A default timeout of 1 minute will be used.

Parameters:
match - The string to search for.
includeMatch - If true, the match string is returned in the resulting data string. If false, the match string is not returned as part of the resultant string.
Returns:
the expected data buffer
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

expect

java.lang.String expect(java.util.List matches,
                        boolean includeMatch)
                        throws java.lang.Exception
Reads data from the device until one of the expected strings is found. Once an expected string is found, the data buffer up to the point where the string was found is returned. A default timeout of 1 minute will be used.

Parameters:
matches - The strings to search for.
includeMatch - If true, the match string is returned in the resulting data string. If false, the match string is not returned as part of the resultant string.
Returns:
the expected data buffer
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

expect

java.lang.String expect(java.lang.String match)
                        throws java.lang.Exception
Reads data from the device until the expected string is found. Once the expected string is found, the data buffer up to the point where the string was found is returned. A default timeout of 1 minute will be used and the match string will not be included in the resultant string.

Parameters:
match - The string to search for.
Returns:
the expected data buffer
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

expect

java.lang.String expect(java.util.List matches)
                        throws java.lang.Exception
Reads data from the device until one of the expected strings is found. Once an expected string is found, the data buffer up to the point where the string was found is returned. A default timeout of 1 minute will be used and the match string will not be included in the resultant string.

Parameters:
matches - The strings to search for.
Returns:
the expected data buffer
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

expect

java.lang.String expect(java.lang.String match,
                        boolean includeMatch,
                        java.lang.Integer timeout)
                        throws java.lang.Exception
Reads data from the device until the expected string is found. Once the expected string is found, the data buffer up to the point where the string was found is returned.

Parameters:
match - The string to search for.
includeMatch - If true, the match string is returned in the resulting data string. If false, the match string is not returned as part of the resultant string.
timeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method will not return.
Returns:
the expected data buffer
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

expect

java.lang.String expect(java.util.List matches,
                        boolean includeMatch,
                        java.lang.Integer timeout)
                        throws java.lang.Exception
Reads data from the device until one of a list of expected strings is found. Once the expected string is found, the data buffer up to the point where the string was found is returned.

Parameters:
matches - The strings to search for.
includeMatch - If true, the match string is returned in the resulting data string. If false, the match string is not returned as part of the resultant string.
timeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method will not return.
Returns:
the expected data buffer
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

read

java.lang.String read()
                      throws java.lang.Exception
Reads the next set of data from the device until enough time has passed that we assume no more data will arrive. The default timeout will be used.

Returns:
the next set of read data.
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

read

java.lang.String read(java.lang.Integer timeout)
                      throws java.lang.Exception
Reads the next set of data from the device until enough time has passed that we assume no more data will arrive.

Parameters:
timeout - The timeout value in seconds to wait for the data to be returned. If null is passed, no timeout will be used. Beware that if the expected match string is not found or if the device doesn't respond, this method will not return.
Returns:
the next set of read data.
Throws:
ThreadTimeoutException - if the expected string was not found within the passed in timeout period.
java.io.IOException - if there was an error reading data from the device.
java.lang.Exception - if any other unexpected error occurs.

setDefaultNoDataReadDelay

void setDefaultNoDataReadDelay(int delay)
Modifies the default no data read delay in 1/10 seconds. The "no data read delay" is the amount of time that the protocol waits when receiving no data that a data read is considered complete.

Parameters:
delay - The default no data read delay.

getDefaultNoDataReadDelay

int getDefaultNoDataReadDelay()
Gets the default no data read delay.

Returns:
the delay.

getAscii

java.lang.String getAscii(java.lang.String string,
                          int pos)
Gets a formatted ASCII dump of the passed in string.

Parameters:
string - the string to log
pos - the byte position of the read string
Returns:
the formatted ASCII dump.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.