[SNMP4J] Re: snmpTRAP

Tejo Vamsi Prayaga tejovamsi at yahoo.com
Mon Apr 4 10:48:26 CEST 2005


Hello abdel,
 
You need to comment out the code where you wait. Wait/notify is for the purpose of inter-thread communication and synchronous resource sharing and not exactly needed here.
Also wait/notify calls should be used with synchronized methods/blocks.
 
In this we case we need to make sure that the JVM does not exit. It infact will not exit, because transport listener runs as a daemon thread. So we need not have any extra code for making the main thread to join the remaining threads. Comment out the block where you invoke this.wait() and things should work fine.
 
Also we need to bind to the specifi IP address I guess and not 127.0.0.1. However I did not check it out though. If you do not recevie traps still, you can try specifying your IP address.
 
Plz. see inline, if needed to see the necessary code change.
 
Regards
Tejo
 
> Hello, I have a small problem with function TRAP I am to go to see in the class snmpRequest but I am not able to find my problem here my code: 
> 
> import org.snmp4j.*;
> import org.snmp4j.smi.*;
> import org.snmp4j.util.*;
> import org.snmp4j.event.*;
> import org.snmp4j.transport.*;
> import org.snmp4j.mp.*;
> import org.snmp4j.security.*;
> import org.apache.log4j.*;
> 
> public class snmpTrap {
>     
>     /** Creates a new instance of snmpTrap */
>     public snmpTrap() 
>     {
>          int numDispatcherThreads = 2;
>          try
>         {
>           Address targetAddress = GenericAddress.parse("udp:127.0.0.1/162");
>                                      
>           TransportMapping transport = new DefaultUdpTransportMapping();
>                                 
>           CommandResponder trapPrinter = new CommandResponder() { 
>           public synchronized void processPdu(CommandResponderEvent e) 
>           {
>             PDU command = e.getPDU();
>             if (command != null) 
>             {
>                System.out.println(command.toString());
>             }
>           }
>         };
>         
>           ThreadPool threadPool =
>           ThreadPool.create("DispatcherPool", numDispatcherThreads);
>           MessageDispatcher mtDispatcher =
>           new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
>           mtDispatcher.addMessageProcessingModel(new MPv1());
> 
>           Snmp snmp = new Snmp(mtDispatcher, transport);
>           snmp.addCommandResponder(trapPrinter);
>           
>           transport.listen();
/* COMMENTED
           try {
                     this.wait();
               }
           catch (InterruptedException ex) {
               }    
 */
 

   
>       }
>       catch(Exception ex)
>       {
>           ex.printStackTrace();
>           System.out.println(ex.getMessage());
>           System.exit(0);
>       }
>         
>     }
> }
> but it posts me this error: 
> java.lang.IllegalMonitorStateException: current thread not owner
>         at java.lang.Object.wait(Native Method)
>         at java.lang.Object.wait(Object.java:429)
>         at snmpTrap.<init>(snmpTrap.java:47)
>         at applic.main(applic.java:19)
> log4j:WARN No appenders could be found for logger (org.snmp4j.transport.DefaultUdpTransportMapping).
> log4j:WARN Please initialize the log4j system properly. _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j
> 


		
---------------------------------
Do you Yahoo!?
 Better first dates. More second dates. Yahoo! Personals 


More information about the SNMP4J mailing list