Other Core APIs

 

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:

Following methods are available in the CLI message to set the above mentioned parameters:

 

Method Purpose

setCLIProtocolOptions(CLIProtocolOptions cliProtocolOptions)

This method can be used to set the protocol options for each message.

setMsgID(int id)

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.

setData(byte[] data)

This method can be used to set the message in the form of bytes.

setData(java.lang.String data)

This method can be used to set the message in the form of a string.

setCLIPrompt(java.lang.String cliPrompt)

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();

session.addCLIClient(async);

 

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 keepAliveTimeout, the transport connection associated with it is closed and the application that has registered with the CLISession will be notified.

 

Managing Resources

 

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:

Following methods can be used to manage the CLI resources.

 

Method

Purpose

setPooling(boolean poolFlag)

 

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.

setMaxConnections(int connections)

This method can be used to set the maximum number of CLI connections that can exist per device for any session.

setSystemWideMaxConnections(int connections)

This method can be used to set the maximum number of connections system wide that can exist at any given instant of time.

closeAllConnections()

This method can be used to close all the connections in the common transport pool.

 

Please refer to Java documentation for complete details.

 

Related Topics

 



Copyright © 2009 ZOHO Corp. All Rights Reserved.