agent.setParams(params);
// Build the session. A session creates, controls and
// manages one or more requests.
//
final SnmpSession session =
new SnmpSession("SyncManager session");
// A default peer (agent) can be associated to a SnmpSession.
// When invoking a service provided by the SnmpSession, if the
// agent is not specified, the session will perform the service
// using the default peer as the target of the service.
//
session.setDefaultPeer(agent);
// Build the list of variables you want to query.
// For debug purposes, you can associate a name to your list.
//
final SnmpVarBindList list =
new SnmpVarBindList("SyncManager varbind list");
// We want to read the "dsServerDescription" variable.
//
// We will thus query "dsServerDescription"
//
list.addVarBind("dsServerDescription");
// Make the SNMP get request and wait for the result.
//
SnmpRequest request = session.snmpGetNextRequest(null, list);
final boolean completed = request.waitForCompletion(0);
// Check for a timeout of the request.
//
if (completed == false) {
fail("SyncManager::main: Request timed out." +
" Check reachability of agent");
return;
}
// Now we have a response. Check if the response contains
// an error.
//
final int errorStatus = request.getErrorStatus();
if (errorStatus != SnmpDefinitions.snmpRspNoError) {
fail("Error status = " +
SnmpRequest.snmpErrorToString(errorStatus));
fail("Error index = " + request.getErrorIndex());
return;
}
// Now we shall display the content of the result.
//
final SnmpVarBindList result = request.getResponseVarBindList();
assertNotNull(result);
assertEquals(result.getVarBindCount(), 1);
assertEquals(result.getVarBindAt(0).isValidValue(), expectedResult);
// Nicely stop the session
//
session.destroySession();
//
// That's all !
//
return;