The procedure by which an user client applications can perform
the above mentioned transactions with the ManagementServer is depicted
in the following code snippets,
(1) Getting a ManagementServices implementation.
The applications perform all management transactions with this instance.
// To get an applet instance
ManagementServices ms = ManagementServicesAPI.getInstance
(applet ,ManagementServicesAPI.MS_THREE_TIER_MODE);
/* In the applet the following parameter should be set , * MS_ROOT_DIR - The directory where the conf/ directory containing
* configuration files (like conf/provider.xml) of ManagementServer
* is present.
*/
// To get an application instance ,
// Form the transport arguments
String transportArgs[] = {"TCP","com.adventnet.management.transport.TcpClientTransportImpl","venkat","9001"};
// The transport arguments are as follows ,
ManagementServices ms = ManagementServicesAPI.getInstance (transportArgs,ManagementServicesAPI.MS_THREE_TIER_MODE);
// To get an applet instance ,
ManagementServices ms =
ManagementServicesAPI.getInstance (applet,ManagementServicesAPI.MS_THREE_TIER_MODE);
/* In the applet the following parameters should be set ,
* CLIENT_SERVER - The transport protocol used for communication
with the
* Server.
* CLIENT_CLASS_NAME - The TransportProvider implementation
in the
* client side ,
*
* MS_ROOT_DIR - The directory where the conf/
directory containing
* configuration files (like conf/provider.xml) of ManagementServer
is
* present.
*/
// Set up the Property for sending a request
SnmpProperty property = new SnmpProperty();
// Set generic parameters on the Protocol Property
property.setRetries (0);
property.setTimeout (1000);
property.setOperationType (com.adventnet.management.Property.OP_READ);
// Set the Protocol specific parameters in the Protocol Property.
property.setTargetHost("localhost");
property.setObjectID("1.1.0");
/*For synchronous requests the result is returned as a
* generic result of type ManagementServerResultEvent
*/
// Perform the transaction and get the result .
ManagementServerResultEvent result = ms.syncSend(property);
// The result is obtained as follows
if(re != null)
{
// Check for error results
if(re.getErrString() != null)
{
// Get the error message
String errorMessage = re.getErrString();
// Get the error index .(Here SNMP Error Index in the Response PDU)
byte errorIndex =re.getErrStat();
}
else
{
// Get the Valid response
Object result = re.getResult();
}
}
// Set up a Property for establishing
a device session
TL1Property property = new TL1Property();
/* Set the Protocol specific parameters in the Protocol Property
* necessary for establishing a device session .
*/
property.setTargetHost("localhost");
property.settargetPort(9099);
/* set the object instance which will be notified of session
* connection loss through DeviceConnectionListener
*/
property.setComponent(this);
// establish the session and get the sessionId.
String sessionId = establishSession(property);
/* This String sessionId should be set in the Property(s)
used
* for all transactions through the device session
* using Property.setSessionId(String)
*
* This sessionId can be used for terminating
the device session in
* using ManagementServices.terminateSession(String)
* The same Property instance used in establishSession
can be used for
* terminating the device session
* in ManagementServices.terminateSession(Property)
*/
//Set up a Property for sending a request
TL1Property prop = new TL1Property();
// Set generic parameters on the Protocol Property
property.setRetries (0);
property.setTimeout (1000);
// Set the Protocol specific parameters in the Protocol Property.
property.setTargetHost("localhost");
property.settargetPort(9099);
prop.setTargetId("target");
prop.setCommandCode("DGN-EQPT");
// Set the sessionId which was returned during establish
.
property.setSessionId(sessionId);
/* Follow the same procedure as mentioned in the Connectionless
* protocol to get the result .
*/
(3.1) Code Snippet for a connectionless protocol like SNMP .
/** Set up a Property following the same steps
as mentioned
* in the (Synchronous - connectionless)
.
* For asynchronous requests the user client application
object may get
* the result through ProtocolListener
interface .
* For this the object which implements this interface
has to be
* specified using Property.setComponent(Object)
*/
property.setComponent(this);
/** The result may also be received through
a method specified
* using Property.setMethodDetail(String,
int ,String[] ,Object[])
* For example consider that the method to be invoked
is
* method1(String username, int pos,Vector vec);
* The result type is int type and the result is to
be passed to
* second parameter on the method method1.
*/
// The usage for this method is
Object [] obj = {"StringValue",null,new Vector()};
property.setMethodDetail( "method1", 1,
{"java.lang.String","int","java.util.Vector"},
obj);
/* Here the position of the second parameter is specified
as 1 since
* the position is ranging from 0.
*/
// Set the Object to which the result is to
be applied .
property.setComponent(this);
/** The setMethodDetail approach is slightly
slower as it involves
* using reflection
*
* If both approaches are followed by the
application in the same
* Property request the result is returned through
the ProtocolListener
*interface.
*/
// Perform the transaction and get the requestId
of the send operation .
int reqid = ms.send(property);
/* For applications which are designed to receive
from the same Thread
* context , the following two approaches
may be used .
*/
/* The requestId can be used to get the response as follows*/
if ( ms.checkResponse(reqid) == true)
{
ManagementServerResultEvent
msre = ms.receive (reqid);
}
/* If a number
of requests are sent they can be recieved using
* as follows .
*/
int reqIds[] = new int[10];
reqIds = ms.checkResponses();
for(int i=0 ; i < reqIds.length ; i++)
{
ManagementServerResultEvent msre
= ms.receive (reqids[i]);
}
/* Set up a Property and establish a device session following the same(3.2) Code Snippet for a connection oriented protocol like TL1 .
/* Code Snippet for a connection oriented protocol
like TL1 . */
/* Set up a Property for establishing a device session
in which the
* transport protocol between the device and agent is implemented
by the
* user .
*/
TL1Property property = new TL1Property();
/* Set the Protocol specific parameters in the Protocol Property
* necessary for establishing a device session .
*/
TL1Property property = new TL1Property();
// Specify If dedicated session is needed
property.setUserProperty("DEDICATED_SESSION","TRUE");
/* Specify the transport implementation of the TransportProvider
between
*the device agent and the ProtocolProvider .
*/
property.setUserProperty("ProtocolOptions","SerialProtocolOptionsImpl");
// Specify the list of Protocol Options
property.setUserProperty("PROTOCOL_OPTIONS_PROPERTIES","SERIAL_PORT","BAUD_RATE");
// Specify the above mentioned parameters of the Protocol
Options
property.setUserProperty("SERIAL_PORT","COM2");
property.setUserProperty("BAUD_RATE","9600");
// Establish the device session
String sessionId = ms.establishSession(property);
/* set the object instance which will be notified of session
connection
* loss through DeviceConnectionListener
*/
property.setComponent(this);
// establish the session and get the sessionId.
String sessionId = establishSession(property);
/* This String sessionId should be set in the Property(s)
used
* for all transactions through the device session
* using Property.setSessionId(String)
*/
/* Here the device session in TL1 is through Serial
Port
* communication. Consider the case when it is required
to set some
* properties of the serial controller like Baud Rate etc.
*/
// Set up a Property for sending a request
TL1Property property = new TL1Property();
// Set the sessionId returned in establishSession .
property.setSessionId(sessionId);
// Specify the list of Parameters to be Set
prop.setUserProperty("ACTION_ARGS","CBREAK, PAUSE,BAUD_RATE,ESCAPE");
// Specify the above mentioned parameters of the Control Sequence.
prop.setUserProperty("CBREAK", "5 2400 p");
prop.setUserProperty("PAUSE", "20");
prop.setUserProperty("BAUD_RATE", "111");
prop.setUserProperty("ESCAPE", "222");
// Send the request command to perform the action .
ms.sendAction(prop);
(5.1) Code Snippet for a connectionless protocol like SNMP .
// Set up a Property following the same steps
as mentioned in the
(Asynchronous - connectionless)
.
// Set the Poll related parameters if needed
.
property.setPollInterval(5000); // Set the Poll
Interval in millisecs .
// Register the Property request for polling
ms.registerClient(property);
/* The results are obtained periodically according to the
Poll Interval ,
* in the same manner as in (Asynchronous
- connectionless) .
*
* The same Property instance used in registerClient can
be used for
* unregistering from recieving Poll responses in
* ManagementServices.unregisterClient(Property)
*/
/* Set up a Property and establish a device session followingCode Snippet for a connection oriented protocol like TL1 .
// Set up the Property for registering a request for receiving Events. SnmpProperty property = new SnmpProperty(); // Set the event related parameters on the Protocol Propertyproperty.setTargetHost ("localhost");
/* The application object gets the result through
* {@link com.adventnet.management.MSEventListener}
interface .
* For this the object which implements this interface has
to be specified
* using Property.setComponent(Object)
*/
property.setComponent(this);
// Register the request for receiving Event Notifications.
String eventId= ms.registerForNotification(property);
/* This eventId can be used for unregistering from recieving
Events in
* ManagementServices.unregisterForNotification(String)
* The same Property instance
used in registerForNotification can be used
* for unregistering from recieving Events in
* ManagementServices.unregisterForNotification(Property)
*/
// Set up the Property for registering a request for receiving Events, TL1Property property = new TL1Property(); // Set the event related parameters on the Protocol Propertyproperty.setTargetHost ("localhost");
// Set the sessionId which was returned during establish .
property.setSessionId(sessionId);
/* Register the Property request for recieving events by following
the
* same proceedure in (EventRegistration
- connectionless)
*/