AdventNet Web NMS 4 API Specification

com.adventnet.nms.startclient
Class MainSocketClient

java.lang.Object
  |
  +--com.adventnet.nms.startclient.MainSocketClient
All Implemented Interfaces:
java.lang.Runnable

public class MainSocketClient
extends java.lang.Object
implements java.lang.Runnable

This class serves as the basic communication endpoint for the Web NMS client. This class handles all the communication done between the Web NMS Client and the Web NMS Server. All the responses from the Web NMS Server are received and processed here. The actual transport of the data (based on the underlying protocol) is taken care by the TransportProvider implementation class.

The communication between the client and server modules are achieved through sessions. The client side sessions classes should implement the interface SocketConnection. The sessions should have a corresponding implementation either in the Front End server or the Back End server of Web NMS for communication.

The client side sessions should register with a unique session id, with this class for communication using the method registerForResponses(). The communication will be routed to the corresponding sessions both on the server and client side based on this unqiue session id, which will distinctly identify the session.

The class implements the Runnable interface as it is started as a thread during client intialization. The users should note to use only the prescribed methods in this class, as any misuse of the methods might lead to undesirable behaviour of the client.

This is a client side class and hence can be used only in the JVM as that of the client.

See Also:
SocketConnection, TransportProvider

Field Summary
 boolean connected
          The value specifies if the client is connected to the server or not.
 boolean isDialogShowing
           
 java.lang.String licenseAllowed
          The value that specifies the license permission string.
 
Constructor Summary
MainSocketClient(java.applet.Applet app)
          Creates a MainSocketClient with the applet argument.
MainSocketClient(java.applet.Applet app, java.lang.String className)
          Creates the MainSocketClient with the applet and the TransportProvider Class name.
MainSocketClient(java.lang.String hostname, java.lang.String rmi)
          This constructor is used for instantiating the MainSocketclient when the communication protocol is RMI.
 
Method Summary
 boolean checkTimeout(java.lang.String reqid, long timeOut)
          Checks whether there are any timed-out requests for this specific ID.
 void deRegisterForResponses(java.lang.String id)
           
 boolean establishConnection(java.applet.Applet app, java.lang.String className)
           
 java.lang.String genReqID()
          Generate a request ID for PDU.
 java.util.Vector getCachedRequests(java.lang.String id)
          This method is used to get the cached requests (Requests were received after identifying the connection failure).
 java.lang.StringBuffer getLicenseDetails()
           
 long getTimeOutCount()
          This method returns the current timeout interval set for synchronous call to the server.
 boolean isConnected()
          This method is used to check connection variable of MainSocket
 boolean isUserStatusModified()
           
 void killMeSilently()
          Terminates the connection maintained with the server and closes all the resources used up.
 void processNmsPDU(byte[] pduData)
          Processes the data received from the transport provider.
 void processTheCachedRequests()
          This method will process the cached requests after the FailOver Operation successfully.
 java.lang.String registerForResponses(SocketConnection sockClient, java.lang.String id)
          All clients sessions mplementing the SocketConnection Interface will register for responses here with the session id the client will use for communicating with the server.
 java.util.Vector removeCachedRequests(java.lang.String id)
          This method is used to remove the cached requests (Requests were received after identifying the connection failure).
 void run()
          Implementation of the Runnable interface.
 boolean send(java.lang.String id, byte[] data)
          This method sends the data asynchronously to the Server.ie., this method returns immediately after placing the request in a request queue.
 void sendInitialFERequests(boolean f)
           
 void setCachingState(boolean state)
          This method will enable the caching flag
 void setClientFrameWorkAPI(ClientFrameWorkAPI cfwAPI)
          This method sets the ClientFrameWorkAPI instance.
 void setTimeOutCount(long milliSeconds)
          This method sets the timeOutCount for Synchronized send to the Server.
 void showCloseDialog()
          This method just pops-up a dialog saying that the connection to the NMS server is lost and gets out.
 void showCustomizedServerClosedDialog(javax.swing.JOptionPane optionPane, java.lang.String strOptionPaneTitle)
          This method is used to cutomize the title and the JOptionPane of the "Connection lost" dialog.
 byte[] syncSend(java.lang.String id, byte[] data)
          Sends the data to the server and returns only after a response is received for this particular request i.e., the data is transferred synchronously.
 byte[] syncSend(java.lang.String id, byte[] data, long timeOut)
          Sends the data to the server and returns only after a response is received for this particular request i.e., the data is transferred synchronously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connected

public boolean connected
The value specifies if the client is connected to the server or not. Will be set true as soon as the client gets connected to the server. Will be set to false when the connection is disconnected.

licenseAllowed

public java.lang.String licenseAllowed
The value that specifies the license permission string. The possible values are null,allow,disallow. Java client will be opened only when this value is set as allow during startup This value has no effect after the startup of the client.

isDialogShowing

public boolean isDialogShowing
Constructor Detail

MainSocketClient

public MainSocketClient(java.applet.Applet app)
Creates a MainSocketClient with the applet argument. The TransportProvider implementation class is retrieved from the CLIENT_CLASS_NAME applet parameter, which is essential for transport provider initialization.
Parameters:
app - The Web NMS Applet reference, which should contain the CLIENT_CLASS_NAME applet parameter for initializing the transport provider.

MainSocketClient

public MainSocketClient(java.applet.Applet app,
                        java.lang.String className)
Creates the MainSocketClient with the applet and the TransportProvider Class name. The constructor initializes the transport provider for communication.
Parameters:
app - the Web NMS Client applet.
className - The implementation classname of the TransportProvider interface

MainSocketClient

public MainSocketClient(java.lang.String hostname,
                        java.lang.String rmi)
                 throws java.lang.Exception
This constructor is used for instantiating the MainSocketclient when the communication protocol is RMI.
Parameters:
hostname - The hostname of the Web NMS Front end server to which the client should connect
rmi - The string is presently not used for any purpose. Reserved for future use.
Throws:
java.lang.Exception -  
Method Detail

establishConnection

public boolean establishConnection(java.applet.Applet app,
                                   java.lang.String className)

run

public void run()
Implementation of the Runnable interface. This is method starts the thread which will be receving the data dedicatedly in this thread. This thread will be started when the client framework is initialized.
Specified by:
run in interface java.lang.Runnable

sendInitialFERequests

public void sendInitialFERequests(boolean f)

getLicenseDetails

public java.lang.StringBuffer getLicenseDetails()

showCloseDialog

public void showCloseDialog()
This method just pops-up a dialog saying that the connection to the NMS server is lost and gets out.

processNmsPDU

public void processNmsPDU(byte[] pduData)
Processes the data received from the transport provider. The method just converts the received data into the NmsPDU and puts into a Queue for further distribution to the appropriate sessions by the scheduler threads. As such the method does not perform any operation on the data received.
Parameters:
pduData - The byte arragy to be processed.

isUserStatusModified

public boolean isUserStatusModified()

registerForResponses

public java.lang.String registerForResponses(SocketConnection sockClient,
                                             java.lang.String id)
All clients sessions mplementing the SocketConnection Interface will register for responses here with the session id the client will use for communicating with the server. The id should unique among all the sessions as its used to identify the appropriate session during communication.
Parameters:
sockClient - the client session registering for the response.
id - the unique ID to be used for the communication with the server.
Returns:
id to be used for communication with the Server. This is same as the id passed as parameter.

deRegisterForResponses

public void deRegisterForResponses(java.lang.String id)

send

public boolean send(java.lang.String id,
                    byte[] data)
This method sends the data asynchronously to the Server.ie., this method returns immediately after placing the request in a request queue. The data passed to this method will be later processed via scheduling mechanism.
Parameters:
id - the registered session id.
data - the data to be sent to the server.
Returns:
true if the send succeeds, false otherwise.

syncSend

public byte[] syncSend(java.lang.String id,
                       byte[] data)
Sends the data to the server and returns only after a response is received for this particular request i.e., the data is transferred synchronously. The method will timeout if there is no response from the server for more than the time out duration specified. The default time out duration is 20 secs.
Parameters:
id - the registered session ID.
data - the data that needs to be sent.
Returns:
byte[] data - the response data received or null if there is any time out.

syncSend

public byte[] syncSend(java.lang.String id,
                       byte[] data,
                       long timeOut)
Sends the data to the server and returns only after a response is received for this particular request i.e., the data is transferred synchronously. The method will timeout if there is no response from the server for more than the provided time out duration specified.
Parameters:
id - the registered session ID.
data - the data that needs to be sent.
timeout - the max time in milliseconds for which the request will wait for response.
Returns:
byte[] data - the response data received or null if there is any time out.

checkTimeout

public boolean checkTimeout(java.lang.String reqid,
                            long timeOut)
Checks whether there are any timed-out requests for this specific ID. If there are any such requests then they are removed from the request queue.
Parameters:
reqid - the request ID for which the time out request is to be verified.
Returns:
true if there are any timed out requests, false otherwise.

genReqID

public java.lang.String genReqID()
Generate a request ID for PDU. Uses the random number generator.
Returns:
the random ID generated.

killMeSilently

public void killMeSilently()
Terminates the connection maintained with the server and closes all the resources used up.

setTimeOutCount

public void setTimeOutCount(long milliSeconds)
This method sets the timeOutCount for Synchronized send to the Server. The time given should be in milliseconds
Parameters:
milliSeconds - The time out count to be set for synchronized calls to the server.
See Also:
getTimeOutCount()

getTimeOutCount

public long getTimeOutCount()
This method returns the current timeout interval set for synchronous call to the server.
Returns:
Returns a long value, which will be the current time out interval in milliseconds.
See Also:
setTimeOutCount(long)

isConnected

public boolean isConnected()
This method is used to check connection variable of MainSocket

setCachingState

public void setCachingState(boolean state)
This method will enable the caching flag

processTheCachedRequests

public void processTheCachedRequests()
This method will process the cached requests after the FailOver Operation successfully.

getCachedRequests

public java.util.Vector getCachedRequests(java.lang.String id)
This method is used to get the cached requests (Requests were received after identifying the connection failure).
Returns:
the cached request Vector.

removeCachedRequests

public java.util.Vector removeCachedRequests(java.lang.String id)
This method is used to remove the cached requests (Requests were received after identifying the connection failure).
Returns:
the cached request Vector.

setClientFrameWorkAPI

public void setClientFrameWorkAPI(ClientFrameWorkAPI cfwAPI)
This method sets the ClientFrameWorkAPI instance.
Parameters:
cfwAPI - instance of ClienFrameWorkAPI

showCustomizedServerClosedDialog

public void showCustomizedServerClosedDialog(javax.swing.JOptionPane optionPane,
                                             java.lang.String strOptionPaneTitle)
This method is used to cutomize the title and the JOptionPane of the "Connection lost" dialog.
Parameters:
optionPane - JOptionPane with cutomized buttons and Messages
strOptionPaneTitle - title for the "Connection lost" dialog.

AdventNet Web NMS 4 API Specification