[SNMP4J] Asynchronous message sending

Nikita chudo.judo at gmail.com
Thu Apr 10 16:01:22 CEST 2008


Hi all!
Guys, I have a task to discover all SNMP devices in some IP range. I'm going
to use asynchronous message sending by means of something like this:

// iterating through IPs, ports, communities...
for (...)
{
          snmp.send(pdu, target, transportMapping, null, new
ResponseListener()
                    {
                        public void onResponse(ResponseEvent event)
                        {
                              // my code to write results
                        }
                    });
}


Then I need to get know when all requests are processed. Now the only way to
check this I see is to use counter in all listener invocations to check
condition like

while (counter < totalSent)
{
       Thread.sleep(1000);
}

This way works fine while Snmp4J engine is not interrupted (for example, by
RuntimeException thrown by ResponseListener) and listeners are actually
called. It's not rather reliable for me.

Another aproach I see is:
1. Extend current CommonTimer interface to provide number of scheduled not
yet executed tasks
2. Create getTimer() method for Snmp class or change modifier of Snmp#timer
field to protected

Your ideas are very appreciated.
Nikita.



More information about the SNMP4J mailing list