The core API consists of necessary classes and interfaces that can be used along with the CLISession for constructing messages, manage connection resources, and listening on connection states.
The com.adventnet.cli package contains classes and interfaces to perform the following functions:
Constructing CLI Messages
The CLIMessage class can be used to create a CLI message that contains the command to be sent to the device. For each message, parameters such as protocol options, command prompt, message suffix and others can be set. The parameters set on the CLIMessage always override the corresponding parameters on the CLISession.
After creating a CLI message it can be sent using either the send() or syncSend() method in CLISession class. The CLIMessage contains the following parameters:
The CLI command to be sent.
The CLIProtocolOptions, which contains protocol specific parameters. For Telnet, this will be the target host address, target port, and login parameters of the device to which the CLI command has to be sent. For Serial communication, this will be the Serial port parameters such as the Baud rate, the port ID and others.
The message ID, which is used to match the commands sent with the responses for asynchronous communication.
The CLI prompt, which is the string issued by the remote host after establishing a session successfully.
The command echo flag to enable or disable the echoing of commands by the device back to the sender.
The timeout for the request message. If the response is not received within this time, an Exception is thrown indicating that the timeout has occured.
The message suffix for the message. This is the String or character that has to be appended to the message that is being sent.
Following methods are available in the CLI message to set the above mentioned parameters:
This method can be used to set the protocol options for each message.
This method can be used to set the message ID for the CLI Command. If this is not set then the message ID is generated internally.
This method can be used to set the message in the form of bytes.
This method can be used to set the message in the form of a string.
This method can be used to set the CLI prompt for the CLI session.
Receiving Asynchronous Responses and Messages
The CLIClient is the interface that has to be implemented
by the applications when asynchronous CLI responses or asynchronous messages
are to be received. The response or the asynchronous message will be received
in the callback
method of the interface. The asynchronous responses are received
when the method send() is used
in CLISession. The asynchronous messages are received when the device
sends data on occurence of some fault condition. Applications that implement
the CLIClient interface have to register with the CLISession using the
addCLIClient method. Only then
it can receive the asynchronous responses or messages.
CLIAsync async = new CLIAsync();
Listening on Connections
The ConnectionListenerinterface is implemented by applications
to get the notification of timeout of transport connection associated
with a multiplexed (non-dedicated) session. If the multiplexed session
is idle for more than the
the transport connection associated with it is closed and the application
that has registered with the CLISession will be notified.
The CLI ResourceManagerclass monitors all the transport connections. It keeps track of the number of connections open with a particular device and also the total number of connections system wide. This class manages system-wide resources associated with CLI API within the same Java Virtual Machine (JVM). The various functions that can be performed using this class are given below:
Monitor the maximum number of CLI connections that can be opened at any given instant of time (default is 3).
Monitor the maximum number of CLI connections that can exist per device for any opened session.
Enable/Disable the pooling (sharing) of the CLI transport provider among CLI sessions.
Automatic closing of multiplexed transport sessions that remain idle for a particular amount of time. The timeout for closing the connection can be set using the setKeepAliveTimeout() method.
Following methods can be used to manage the CLI resources.
This method can be used to create a multiplexed or non-multiplexed CLI session. If you set the poolFlag as true, it is multiplexed otherwise it is a non-multiplexed session.
This method can be used to set the maximum number of CLI connections that can exist per device for any session.
This method can be used to set the maximum number of connections system wide that can exist at any given instant of time.
This method can be used to close all the connections in the common transport pool.
Please refer to Java documentation for complete details.