Communication Framework - Client - BE Communication - Example



Feature Overview

In Web NMS, the communication between the server (FE Vs BE) and the client (FE Vs Java Client) takes place through a Common connection which uses either TCP Socket or RMI. You can make use of this Common connection for the modules written by you through the API provided.

The BE server performs the "Core tasks" viz., discovery, maintenance of the managed objects, receiving and processing traps, etc. The FE server deals with the clients and performs all the "Client tasks" viz., servicing client requests, maintaining the state of the client in terms of the data being viewed, etc. BE server provides services to one or more FE servers and each FE server provides services to one or more clients.

A request from the client which involves Read operation on the RDBMS, is communicated to the FE server and if the request involves a Write operation, it is communicated to the BE via FE. The BE server takes care of writing into the database. Here, the FE server plays a dual role, serving both as a server and a client. When the communication is between the Java Client and the FE server, the FE acts as server. It acts as a client, when the communication is between the BE server and FE server.

For more details, refer to the following section of our documentation : Developer Guide -->Communication Framework --> Client Server Communication.

Example Overview

Example name : Client-BE Communication
Related files : ProcessTest.java,TestSession.java,TestClient.java, and FrameExample.java
Location : <Web NMS Home>/default_impl/client_server_communication

This example illustrates how the communication between Client and Server takes place. For the sake of clarity, this example has been expalined taking the PollObserver as reference. Here, the server collects some data from an agent and displays the data in the client. This example has been built using four java programs namely ProcessTest.java,TestSession.java,TestClient.java, and FrameExample.java which are explained below.

ProcessTest

One of the first things that has to be done for communication to take place between the client and server, is to write a process and register that process with the mainSocketServerBE. This class ProcessTest explains how this is done.

A process named ProcessTest is written by implementing the RunProcessInterface. In this interface, the following three methods are mandatorily implemented.

The 'callMain' method of this interface is the entry point for the corresponding NMS process. This method is invoked from a separate thread for each process, when the Web NMS server starts.

The 'isInitialized' method is used to check whether the corresponding process is started successfully and is ready to provide service to other modules/applications. The shutdown() method is used to shutdown the process.

Since this class 'ProcessTest' will be running in BE, it has to implement the interface SocketServerConnectionBE to register with mainSocketServerBE for getting updates. This is done as shown below :

PureServerUtilsBE.serverSocketBE.registerForResponses(this);

When any Client connects to the BE, the mainSocketServerBE will intimate the ProcessTest. Then the ProcessTest will create an instance of TestSession for that Client, with a specific id.

TestSession

In order to facilitate the server to communicate with specific client modules (a client can have several modules) directly and precisely, sessions are created.

The class TestSession implements SocketSessionConnectionBE and PollObserver. The SocketSessionConnectionBE is implemented to create a connection between the ProcessTest and TestSession for communication. The PollObserver is implemented to get the updates of the Polling information from Web NMS.

TestSession will register with mainSocketSessionBE. This makes all the communication between the TestSession and TestClient to use the same connection, with the specific id.

Some of the methods used in TestSession to communicate with TestClient are explained below.

The method "public void receive(String uid,byte[] data)" is used to receive the information sent by the TestClient. It uses a specific id for identifying the client which sends the request.

Response to the requests of the client can be sent through several ways. Some illustrative methods are shown here namely "exampleMethodForSending()", "void sendAllPollKeys(String agentname)", "void sendConfirmation(PolledData pd)" and "void sendOneString(int id,String s)".

The method "public void close()" is used to close the connection between the TestSession and TestClient.

TestSession registers and deregisters the client using the methods "void registerForData(String pollkey)" and "void deregisterForAgent(String agentname)" respectively.

The other methods used are "private String getAgent(String pollkey)", "public void dataUpdate(String pollkey,long time, long value)", "public void dataUpdate(String pollkey,long time, String value)" and "public void dataUpdate(CollectedInfo colinfo)".

TestClient

TestClient registers with the server for communication, using the following method.

PureClientUtils.commonSocket.registerForResponses(this,TESTID);

Many clients can be connected to the TestSession with different ids. The TESTID is unique for the TestClient and TestSession. It gets the PolledData from the TestSession.

FrameExample

This file creates an user interface, to show the PolledData for the selected node. The output of the example is shown to the user in the form of a frame.Thus the TestClient sends a request to the TestSession and it responds with the poll value requested. During the communication a specific id is used throughout, with which TestClient is registered. Only based on this id does the TestSession recognize the different clients connected to it.

Working with the Example

By default, these files are integrated with Web NMS. So, there is no need to make any classpath settings. However, if you do some changes to these files or write a new file for a similar functionality, you need to do the following :
Classpath Settings

Set the classpath  to <Web NMS Home>/classes;

Compiling and Bundling with Web NMS

Compile and move the class file created, into the destination directory using the following syntax in the command prompt.

javac -d <Web NMS Home>/classes <Java filename>

Invoking the example

A sample client screen has been designed to monitor collected data for a PolledData. You can work with the example as follows :

A frame appears showing the Statistics (PolledData) created for the selected node i.e. Interface_In_Octets and Interface_Out_Octets.


Note: You can change the Poll period of the PolledData to a very minimal value and see the collected value displayed in this screen. For e.g. set the poll period to 2 seconds and view this UI. To change the poll period follow these steps:



Copyright © 1996-2002, AdventNet Inc. All Rights Reserved.