The Remote Method Invocation (RMI) provides the mechanism by which the server and the client communicate and pass information back and forth allowing the remote clients to perform CLI operations. The advantage of using the RMI APIs is to allow a server to perform the CLI functions, while the leaner clients only makes the RMI calls to the server. For example, the server can run on the web server, while the application makes RMI calls to the server to perform CLI functions.
The figure illustrates the use of RMI from a Java application at the client end. In this architecture, the client uses the server to perform CLI operations and the communication with the server is via RMI calls over TCP socket while communication with the device is through the transport provider framework.
The sample application provided in the examples directory shows the use of the WebNMS CLI API by doing RMI calls to perform CLI operations. Here we briefly describe the basic operations, which is common for all RMI interfaces. The RMI server can be started as a standalone server or as a part of another Java application, e.g. a web server. The main interface for all the RMI operations is the
com.adventnet.CLI.rmi.CLIFactoryinterface. This interface is implemented by the com.adventnet.CLI.rmi.CLIFactoryImpl class, which can be started from the command line or from another Java application. When started from the command line, this class is published as WebNMS CLIFactory and registered with the RMI Registry. When started from another Java application, you have to publish the factory interface to allow remote access.
CLIFactoryImpl class implements the CLIFactory interface for creating the remote server objects from an RMI client to the RMI server. The server objects are created by calling createCLISession()method and the references are passed back to the client. CLIFactory interface has methods for creating instance of classes for CLI services on the server. These methods return RMI interfaces for getting access to the services provided by the CLI service classes.
String hostname = "myserver";
CLIFactory factory = (CLIFactory)Naming.lookup( "rmi://"+ hostname + "/AdventnetCLIFactory" );
TelnetProtocolOptionsImpl tpoi = new TelnetProtocolOptionsImpl(); CLISession session = factory.createCLISession(tpoi,false);
Once the com.adventnet.CLI.rmi.CLIFactory interface is obtained, the RMI client can use its methods similar to a local instance of CLISession. The method signatures between the corresponding Beans and RMI interfaces are mostly identical.
How to start the CLI Factory
The classes needed for accessing RMI client to the WebNMS CLI API are provided in the com.adventnet.CLI.rmi package. Following steps explains how to start CLI Factory:
Set the AdventNetCLI.jar in CLASSPATH.
Type the rmiregistry
command from a DOS prompt or a UNIX shell.
start rmiregistry for DOS prompt
rmiregistry & for UNIX
To start the RMI CLI
server from the same host as the RMI Registry server, please type the
following command, after ensuring correct PATH and CLASSPATH settings:
Please refer Java documentation for complete details.