com.adventnet.cli.transport
Class TelnetProtocolOptionsImpl

java.lang.Object
  |
  +--com.adventnet.cli.transport.TelnetProtocolOptionsImpl

public class TelnetProtocolOptionsImpl
extends java.lang.Object
implements CLIProtocolOptions, java.io.Serializable

This class provides the Telnet implementation of the CLIProtocolOptions interface. It contains parameters like the Remote Host Address, Port, login parameters, etc. In order to establish a CLI session over Telnet with a particular device the appropriate parameters has to be set on an instance of this class and passed to the CLISession's constructor. A subsequent call to the open() method in CLISession will establish the Telnet connection based on the parameters set here.

See Also:
Serialized Form

Constructor Summary
TelnetProtocolOptionsImpl()
          Constructs ProtocolOptions for Telnet Connections.
 
Method Summary
 java.lang.Object clone()
          Returns an exact copy of this object.
 ConnectionHandler getConnectionHandler()
          Gets the connection handler used for the telnet protocol connection.
 java.lang.Object getID()
          Gets the Key based on the combination of remoteHost, Port and login name.
 java.lang.String getInitialMessage()
          Gets the initial message sent by the device after a connection is established.
 java.lang.String getLoginName()
          Gets the login Name.
 java.lang.String getLoginPrompt()
          Gets the login prompt.
 int getLoginTimeout()
          Gets the login Time-out of the Telnet connection.
 java.lang.String getPasswdPrompt()
          Gets the password prompt.
 java.lang.String getPassword()
          Gets the login Password.
 java.lang.String getPrompt()
          Gets the Prompt.
 java.util.Properties getProperties()
          Gets the list of properties on this CLIProperty instance.
 java.lang.String getRemoteHost()
          Gets the Remote Host name or IP address.
 int getRemotePort()
          Gets the Remote Port.
 java.lang.String getTerminalType()
          Gets the terminal type.
 boolean isPerformPing()
          Gets the perform ping flag.
 void setConnectionHandler(ConnectionHandler ch)
          This method is used to set the connection handler for the telnet protocol connection.
 void setInitialMessage(java.lang.String message)
          Sets the initial message sent by the device after a connection is established.
 void setLoginName(java.lang.String loginName)
          Sets the login Name.
 void setLoginPrompt(java.lang.String loginPrompt)
          Sets the login prompt.
 void setLoginTimeout(int timeout)
          Sets the login time-out.
 void setPasswdPrompt(java.lang.String passwdPrompt)
          Sets the password prompt.
 void setPassword(java.lang.String passwd)
          Sets the login Password.
 void setPerformPing(boolean flag)
          Sets the perform ping flag.
 void setPrompt(java.lang.String prompt)
          Sets the Prompt.
 void setProperties(java.util.Properties properties)
          Sets a list of properties on this CLIProperty instance.
 void setRemoteHost(java.lang.String remoteHost)
          Sets the Remote Host name or IP address in dotted format.
 void setRemotePort(int remotePort)
          Sets the Remote Port.
 void setTerminalType(java.lang.String type)
          Sets the terminal type.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TelnetProtocolOptionsImpl

public TelnetProtocolOptionsImpl()
Constructs ProtocolOptions for Telnet Connections. Contains the RemoteHost/RemotePort and other parameters. This class contains all the parameters that are needed for opening a telnet connection to a device.

For example to set various protocol options the following can be done:

 TelnetProtocolOptionsImpl protocolOptions = new TelnetProtocolOptions()
 protocolOptions.setRemoteHost("localhost");
 protocolOptions.setRemotePort(23);
 protocolOptions.setLoginName("guest");
 protocolOptions.setPassword("guest");
 protocolOptions.setPrompt("$");

 

This will be the parameters to open a telnet connection to the localhost on port 23 (the standard telnet port). The login user and password will be 'guest' and the prompt that would be expected will be '$'. For example this can be set on the CLIMessage and sent to the corresponding device using CLISession like:

 CLIMessage msg = new CLIMessage("date");
 msg.setCLIProtocolOptions(protocolOptions);
 cliSess.syncSend(msg);
 

Where cliSess is an instance of an open CLISession. This will send the CLI message to the appropriate device based on the above parameters set.
Method Detail

setRemoteHost

public void setRemoteHost(java.lang.String remoteHost)
Sets the Remote Host name or IP address in dotted format.
Parameters:
remoteHost - the remoteHost to connect.

getRemoteHost

public java.lang.String getRemoteHost()
Gets the Remote Host name or IP address.
Returns:
the remoteHost.

setRemotePort

public void setRemotePort(int remotePort)
Sets the Remote Port.
Parameters:
remotePort - the remotePort to connect with.

getRemotePort

public int getRemotePort()
Gets the Remote Port.
Returns:
the remotePort.

getID

public java.lang.Object getID()
Gets the Key based on the combination of remoteHost, Port and login name. The API user need not call this method. It is internally used by the API.
Specified by:
getID in interface CLIProtocolOptions
Returns:
returns the ID as an Object.

setLoginName

public void setLoginName(java.lang.String loginName)
Sets the login Name. For devices which do not prompt for a login name, this parameter need not be set or left as an empty String or null.
Parameters:
loginName - the login user Name for the connection.

getLoginName

public java.lang.String getLoginName()
Gets the login Name.
Returns:
the login Name.

setPassword

public void setPassword(java.lang.String passwd)
Sets the login Password. For devices which do not prompt for a Password, this parameter need not be set or left as an empty String or null.
Parameters:
passwd - the login Password.

getPassword

public java.lang.String getPassword()
Gets the login Password.
Returns:
the login Password.

setPrompt

public void setPrompt(java.lang.String prompt)
Sets the Prompt. This is the String that is issued by the device after a successful login. Usually this is also sent back by the device after the execution of each command.
Parameters:
prompt - the command prompt.

getPrompt

public java.lang.String getPrompt()
Gets the Prompt. This is the String that is issued by the device after a successful login.
Returns:
the command prompt as a String instance.

clone

public java.lang.Object clone()
Returns an exact copy of this object.
Specified by:
clone in interface CLIProtocolOptions
Overrides:
clone in class java.lang.Object
Returns:
copy of this object.

getLoginPrompt

public java.lang.String getLoginPrompt()
Gets the login prompt. This is the String the device issues before waiting for the login name.
Returns:
the login prompt.

setLoginPrompt

public void setLoginPrompt(java.lang.String loginPrompt)
Sets the login prompt.
Parameters:
loginPrompt - login Prompt as a String.

getPasswdPrompt

public java.lang.String getPasswdPrompt()
Gets the password prompt. This is the String the device issues before waiting for the password.
Returns:
the password prompt.

setPasswdPrompt

public void setPasswdPrompt(java.lang.String passwdPrompt)
Sets the password prompt.
Parameters:
passwdPrompt - passwordPrompt as a String.

getLoginTimeout

public int getLoginTimeout()
Gets the login Time-out of the Telnet connection. This is the time for which the CLISession tries to do a successful login. If this time expires, the session throws an Exception.
Returns:
the login Time-out in milliseconds.

setLoginTimeout

public void setLoginTimeout(int timeout)
Sets the login time-out. During login if this time-out expires, an exception is thrown.
Parameters:
timeout - the time-out in milliseconds.

getInitialMessage

public java.lang.String getInitialMessage()
Gets the initial message sent by the device after a connection is established.
Specified by:
getInitialMessage in interface CLIProtocolOptions
Returns:
the initial login message from the device.

setInitialMessage

public void setInitialMessage(java.lang.String message)
Sets the initial message sent by the device after a connection is established. Implementors of this interface should set the initial message sent by the device after a successful connection establishment.
Specified by:
setInitialMessage in interface CLIProtocolOptions
Parameters:
message - the login Message from the device.

isPerformPing

public boolean isPerformPing()
Gets the perform ping flag. This is used to check whether ping is to be done for the host, before establishing a connection with it.
Returns:
a boolean value to indicate if ping needs to be done.

setPerformPing

public void setPerformPing(boolean flag)
Sets the perform ping flag. When this is enabled, a ping is done to check if the device is alive before establishing a connection with it. Only if the ping succeeds a connection is opened to the device, otherwise a ConnectException is thrown. This is mainly done to reduce the time delay while opening connection to the device, if the device is not alive.
Parameters:
flag - a boolean value to enable/disable ping.

setTerminalType

public void setTerminalType(java.lang.String type)
Sets the terminal type. This will be used when a connection is established with the remote host.
Parameters:
type - the terminal type
See Also:
getTerminalType()

getTerminalType

public java.lang.String getTerminalType()
Gets the terminal type. This method is used when a connection is established with remote host (during the telnet protocol negotiation).
Returns:
the terminal type

setProperties

public void setProperties(java.util.Properties properties)
Sets a list of properties on this CLIProperty instance.
Specified by:
setProperties in interface CLIProtocolOptions
Parameters:
props - the property object which contains the list of properties.

getProperties

public java.util.Properties getProperties()
Gets the list of properties on this CLIProperty instance.
Specified by:
getProperties in interface CLIProtocolOptions

setConnectionHandler

public void setConnectionHandler(ConnectionHandler ch)
This method is used to set the connection handler for the telnet protocol connection. The object should be an instance of a class implementing the ConnectionHandler interface.
Parameters:
ch - the ConnectionHandler object

getConnectionHandler

public ConnectionHandler getConnectionHandler()
Gets the connection handler used for the telnet protocol connection. This is mainly used when commands are to be sent before or after connection is established, logging into the device and when the connection is closed.
Returns:
the ConnectionHandler value


Copyright (c)AdventNet Inc., 1996-2003