A response handler for an asynchronous manager is an implementation of the SnmpHandler interface. When a handler object is associated with a request, its methods are called when the agent returns an answer or fails to return an answer. In these methods, you implement whatever actions you wish for processing the responses to a request. Typically, these methods will extract the result of each request or the reason for its failure.
The timeout used by the request handler is the one specified by the SnmpPeer object representing the agent. The handler is also called to process any errors caused by the request in the session. This ensures that the manager application is never interrupted after issuing a request.
public class AsyncRspHandler implements SnmpHandler { // Empty constructor public AsyncRspHandler() { } // Called when the agent responds to a request public void processSnmpPollData( SnmpRequest request, int errStatus, int errIndex, SnmpVarbindList vblist) { java.lang.System.out.println( "Processing response: " + request.toString()); java.lang.System.out.println( "errStatus = " + SnmpRequest.snmpErrorToString(errStatus) + " errIndex = " + errIndex); // Check if a result is available. if (request.getRequestStatus() == SnmpRequest.stResultsAvailable) { // Extract the result for display SnmpVarbindList result = request.getResponseVbList(); java.lang.System.out.println( "Result = " + result.vbListToString()); } } // Called when the agent fails to respond to a request public void processSnmpPollTimeout(SnmpRequest request) { java.lang.System.out.println( "Request timed out: " + request.toString()); if (request.getRequestStatus() == SnmpRequest.stResultsAvailable) { // The result is empty and will display an error message SnmpVarbindList result = request.getResponseVbList(); java.lang.System.out.println( "Result = " + result.vbListToString()); } } // Called when there is an error in the session public void processSnmpInternalError(SnmpRequest request, String errmsg) { java.lang.System.out.println( "Session error: " + request.toString()); java.lang.System.out.println("Error is: " + errmsg); } } |