[SNMP4J] Inconsistency in JavaDoc

Frank Fock fock at agentpp.com
Mon May 5 22:40:03 CEST 2008


Hi Paul,

I have fixed that. To be on the
safe side, call Snmp.cancel always.
Although you are right that it is
redundant on a timeout.

Best regards,
Frank

Paul Donohue wrote:
> 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
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com



More information about the SNMP4J mailing list