Java Dynamic Management Kit 3.2 Programming Guide
[ Previous ][ Fast Back ]Chapter 20. Developing SNMP Managers With the Java Dynamic Management Kit [ Next ]

Operation of the SNMP Manager

The Java Dynamic Management Kit SNMP manager can operate in two modes:

Synchronous Mode

In synchronous mode all operations are blocking, that is, an SNMP request is sent and the request object waits for a specified time, blocking the user thread. If no response is received during the wait time, the request is considered to have failed.

The request object provides the waitForCompletion() method. The waitForCompletion() method is used to specify synchronous mode and the interval to wait for the response. This is done by blocking the user's thread for the required period. The user thread is notified whenever a request reaches completion, irrespective of its success or failure. Invoking the waitForCompletion() method with an interval of zero blocks the request object until a response is received. Example 20-3 shows the instantiation of a synchronous request.

Example 20-3. Instantiating a Synchronous Request
// Make the SNMP get request and wait for the result.

SnmpRequest request= session.snmpGet(null, list);
System.out.println("SimpleManager::main: Send get request to SNMP Agent on " +
host + " at port " + port);
boolean completed= request.waitForCompletion(10000);

Asynchronous Mode

In asynchronous mode, management applications are able to send multiple requests and wait for individual responses. Asynchronous mode also permits polling, as described in Polling.

You send a request by instantiating an SnmpRequest object that specifies a response handler. The response handler is a class that implements the SnmpHandlerIf interface. The response handler has three methods that inform you that:

When a request is submitted, it joins a queue. When the request is sent, it is placed in a PDU packet and a timer is started when the packet is sent. If specified in the SnmpOptions object, requests are multiplexed and sent in a PDU packet containing other requests. Responses are de-multiplexed automatically. All of the multiplexing operations are transparent.

Requests are automatically retried if a response does not arrive within a specified interval. If the agent responds with an error, the SnmpRequest object uses the options defined in the SnmpOptions object to determine the subsequent actions. Example 20-4 shows the instantiation of an asynchronous request.

Example 20-4. Instantiating an Asynchronous Request
// Build the list of variables you want to query.
// For debug purposes, you can associate a name to your list.
SnmpVarbindList list= new SnmpVarbindList("AsyncManager varbind list");

// We want to read the "sysDescr" variable.
list.addVariable("sysDescr.0");

// Create a simple implementation of a SnmpHandlerIf.
AsyncRspHandler handler= new AsyncRspHandler(Thread.currentThread());

// Make the SNMP walk request.
// Read all the MIB variables starting at  "sysDescr" and ending
// up at "sysServices".
// The responses will be received through the handler specified.

SnmpRequest request= session.snmpWalkUntil(handler,list, new 
             SnmpOid("sysServices"));
System.out.println("AsyncManager::main: Start snmpWalkUntil for SNMP Agent on
             " + host + " at port " + port);


[ Previous ][ Home ][ Next ]
SNMP Manager Overview[ Up ]Loading Metadata Into the MibStore