Thread and Listener  
Author Message
Bob Rivers





PostPosted: 2004-12-7 21:23:00 Top

java-programmer, Thread and Listener Hi,

I'm doing some experiences with JOESNMP. It's very good. Guided by the
examples I was able to build a listener that receives snmp traps. It's
working fine (when running through console).

So I decided to start it automatically, together with my web
application (that is running under tomcat).

I have a servlet that is executed when tomcat starts (using
<load-on-startup>). So I did a call to my new class.

The problem is that this class is actually a listener. When it starts,
it hangs the other procedures, including tomcat initilization.

I tryed to put it under a thread, but it also hangs as soon it starts
to listen for snmp traps.

How do I ran a listner without blocking other processes? I am looking
for a solution that should work both on linux and windows.

I don't know if I made myself understood. Sorry my poor english.
TIA,

Bob

 
Sudsy





PostPosted: 2004-12-7 22:51:00 Top

java-programmer >> Thread and Listener Bob Rivers wrote:
<snip>
> How do I ran a listner without blocking other processes? I am looking
> for a solution that should work both on linux and windows.

Perhaps a change in architecture? How about if your listener just performs
a POST to the webserver each time it receives a trap? That way you can run
it stand-alone, perhaps just modify the Tomcat startup script to also fire
up your daemon.

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

 
Chris Smith





PostPosted: 2004-12-8 0:32:00 Top

java-programmer >> Thread and Listener Bob Rivers <email***@***.com> wrote:
> I have a servlet that is executed when tomcat starts (using
> <load-on-startup>). So I did a call to my new class.
>
> The problem is that this class is actually a listener. When it starts,
> it hangs the other procedures, including tomcat initilization.

The simple answer is to create a new thread for it. However, pay
attention to Sudsy's response as well. When you are creating separate
threads inside a servlet container to do things that have nothing to do
with answering HTTP requests, you're quite possibly doing something
wrong.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
 
celeste zhu via JavaKB.com





PostPosted: 2004-12-23 10:19:00 Top

java-programmer >> Thread and Listener could the joesnmp provide the setting function like "snmpset of net-snmp"?
i study the test sample in opennms: snmpwalk.java

i guess if i want to set new value to some OID, the following code is enough:

SnmpVarBind[] vblist = { new SnmpVarBind(walker.m_startOid),1 };
SnmpPduRequest pdu = new SnmpPduRequest(SnmpPduPacket.SET, vblist);

or i should change "1" to some handler of "org.opennms.protocols.snmp.SnmpInt32"

right?!

--
Message posted via http://www.javakb.com