There are two examples of an onResponse handler for Asynchronous Messages in the JavaDocs:
http://www.snmp4j.org/doc/org/snmp4j/package-summary.html shows: ResponseListener listener = new ResponseListener() { public void onResponse(ResponseEvent event) { PDU response = event.getResponse(); PDU request = event.getRequest(); if (response == null) { System.out.println("Request "+request+" timed out"); } else { System.out.println("Received response "+response+" on request "+ request); } }; (note there is a missing } after the else) http://www.snmp4j.org/doc/org/snmp4j/Snmp.html shows: ResponseListener listener = new ResponseListener() { public void onResponse(ResponseEvent event) { // Always cancel async request when response has been received // otherwise a memory leak is created! Not canceling a request // immediately can be useful when sending a request to a broadcast // address. ((Snmp)event.getSource()).cancel(event.getRequest(), this); System.out.println("Received response PDU is: "+event.getResponse()); } }; Could you update the JavaDoc to make these two examples consistent? More importantly, what should be done when the request times out? Should the code be: public void onResponse(ResponseEvent event) { if (event.getResponse() == null) { System.out.println("Request "+event.getRequest()+" timed out"); } else { ((Snmp)event.getSource()).cancel(event.getRequest(), this); System.out.println("Received response "+event.getResponse()+ " on request "+event.getRequest()); } } Or: public void onResponse(ResponseEvent event) { ((Snmp)event.getSource()).cancel(event.getRequest(), this); if (event.getResponse() == null) { System.out.println("Request "+event.getRequest()+" timed out"); } else { System.out.println("Received response "+event.getResponse()+ " on request "+event.getRequest()); } } The following note in the ChangeLog for 1.9.1c makes me think the first is correct, but I wanted to make sure: * Improved: Pending async requests will be removed after timeout even if the response listener did not call Snmp.cancel. Thanks! -Paul _______________________________________________ SNMP4J mailing list [email protected] http://lists.agentpp.org/mailman/listinfo/snmp4j
