com.foxsmart.ic.net
Class AbstractCliProtocolHandler

java.lang.Object
  extended by com.foxsmart.ic.net.AbstractCliProtocolHandler
All Implemented Interfaces:
CliProtocolHandler, ProtocolHandler
Direct Known Subclasses:
CommonsTelnetProtocolHandler, MindTermSshProtocolHandlerImpl, PlinkSshProtocolHandler

public abstract class AbstractCliProtocolHandler
extends java.lang.Object
implements CliProtocolHandler

The AbstractProtocolHandler class provides base functionality for protocols handlers.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.foxsmart.ic.net.ProtocolHandler
ProtocolHandler.Protocol
 
Field Summary
protected  int defaultNoDataReadDelay
           
protected  java.lang.Integer defaultProtocolTimeout
           
protected  org.apache.commons.logging.Log log
           
static java.lang.String PASSWORD_MASK
           
 
Fields inherited from interface com.foxsmart.ic.net.CliProtocolHandler
CR, DEFAULT_NO_DATA_READ_DELAY, PASSWORD_PROMPT, USERNAME_PROMPT
 
Fields inherited from interface com.foxsmart.ic.net.ProtocolHandler
DEFAULT_PROTOCOL_TIMEOUT_SECONDS
 
Constructor Summary
AbstractCliProtocolHandler()
          Default Constructor.
 
Method Summary
 void disconnect()
          This method sets the usernameUsed and passwordUsed flags to false.
 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.
 boolean getAvailable()
          Default implementation returns true.
 int getDefaultNoDataReadDelay()
          Gets the default no data read delay.
 java.lang.Integer getDefaultProtocolTimeout()
          Gets the default operation timeout value.
 boolean getPasswordUsed()
          Gets whether the password was used for authentication.
 boolean getUsernameUsed()
          Gets whether the username was used for authentication.
 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 setDefaultProtocolTimeout(java.lang.Integer timeout)
          Modifies the default operation protocol timeout value.
 void setPasswordUsed(boolean passwordUsed)
          Sets whether the password was used for authentication.
 void setUsernameUsed(boolean usernameUsed)
          Sets whether the username was used for authentication.
 java.lang.String toString()
           
 void write(java.lang.String text)
          Writes the specified string to the telnet device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.foxsmart.ic.net.CliProtocolHandler
connect, getInputStream, getOutputStream, isConnected
 
Methods inherited from interface com.foxsmart.ic.net.ProtocolHandler
getProtocol
 

Field Detail

log

protected org.apache.commons.logging.Log log

defaultProtocolTimeout

protected java.lang.Integer defaultProtocolTimeout

defaultNoDataReadDelay

protected int defaultNoDataReadDelay

PASSWORD_MASK

public static final java.lang.String PASSWORD_MASK
See Also:
Constant Field Values
Constructor Detail

AbstractCliProtocolHandler

public AbstractCliProtocolHandler()
Default Constructor.

Method Detail

write

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

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

sendCommand

public void sendCommand(java.lang.String command)
                 throws java.io.IOException
Description copied from interface: CliProtocolHandler
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).

Specified by:
sendCommand in interface CliProtocolHandler
Parameters:
command - The command to send to the device.
Throws:
java.io.IOException - if there was a problem sending the command.
See Also:
CliProtocolHandler.sendCommand(String)

sendCommand

public void sendCommand(java.lang.String command,
                        boolean containsPassword)
                 throws java.io.IOException
Description copied from interface: CliProtocolHandler
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.

Specified by:
sendCommand in interface CliProtocolHandler
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.
See Also:
CliProtocolHandler.sendCommand(String, boolean)

expect

public 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.

Specified by:
expect in interface CliProtocolHandler
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

public 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.

Specified by:
expect in interface CliProtocolHandler
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

public 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.

Specified by:
expect in interface CliProtocolHandler
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

public 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.

Specified by:
expect in interface CliProtocolHandler
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.

read

public 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.

Specified by:
read in interface CliProtocolHandler
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.

expect

public 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.

Specified by:
expect in interface CliProtocolHandler
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

public 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.

Specified by:
expect in interface CliProtocolHandler
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

public 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.

Specified by:
read in interface CliProtocolHandler
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.

getAscii

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

Specified by:
getAscii in interface CliProtocolHandler
Parameters:
string - the string to log
pos - the byte position of the read string
Returns:
the formatted ASCII dump.

setDefaultProtocolTimeout

public void setDefaultProtocolTimeout(java.lang.Integer timeout)
Modifies the default operation protocol timeout value.

Specified by:
setDefaultProtocolTimeout in interface ProtocolHandler
Parameters:
timeout - The default timeout value in seconds to wait for the data to be returned. If null is passed, no timeout will be used. Beware that if an expected match string is not found or if the device doesn't respond, the expect method will not return.

getDefaultProtocolTimeout

public java.lang.Integer getDefaultProtocolTimeout()
Gets the default operation timeout value.

Specified by:
getDefaultProtocolTimeout in interface ProtocolHandler
Returns:
the timeout in seconds.

setDefaultNoDataReadDelay

public 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.

Specified by:
setDefaultNoDataReadDelay in interface CliProtocolHandler
Parameters:
delay - The default no data read delay.

getDefaultNoDataReadDelay

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

Specified by:
getDefaultNoDataReadDelay in interface CliProtocolHandler
Returns:
the delay.

setUsernameUsed

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

Specified by:
setUsernameUsed in interface CliProtocolHandler
Parameters:
usernameUsed - True if the username was used or false if not.

getUsernameUsed

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

Specified by:
getUsernameUsed in interface CliProtocolHandler
Returns:
True if the username was used or false if not.

setPasswordUsed

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

Specified by:
setPasswordUsed in interface CliProtocolHandler
Parameters:
passwordUsed - True if the password was used or false if not.

getPasswordUsed

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

Specified by:
getPasswordUsed in interface CliProtocolHandler
Returns:
True if the password was used or false if not.

disconnect

public void disconnect()
                throws java.io.IOException
This method sets the usernameUsed and passwordUsed flags to false. Specific handlers should override this method to perform the actual disconnection implementation and call this super method as well.

Specified by:
disconnect in interface CliProtocolHandler
Throws:
java.io.IOException - If there is an error closing the socket.

getAvailable

public boolean getAvailable()
Default implementation returns true. Subclasses can provide a concrete implementation as needed.

Specified by:
getAvailable in interface ProtocolHandler
Returns:
true.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


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