[SNMP4J] Multiple TreeListeners at the same time

Mathew Rowley mathew_rowley at cable.comcast.com
Thu Feb 12 19:24:37 CET 2009


I think this is more of a Java/thread question, but I figured it would make
sense to ask it here because everyone works with the code. If this is the
wrong place to post, I appologize.

So, I want to have multiple TreeListers that are doing an SNMP walk and
adding things to a container object.  Specifically, grabbing MAC addresses
and Ips from a CMTS. From the code examples, you have to syncronize the
TreeListener object, then if you don¹t want the application to stop, you
must do a TreeListener.wait.  That all makes sense to me, but I have not
worked much with threads ­ would this be the correct way to create two
TreeListeners and wait for both of them to complete before continuing
execution?

           OID rootMACOID = new OID(MAC_OID);
        TreeListener macListener = new MACTreeListener(table);
        OID rootIPOID = new OID(IP_OID);
        TreeListener ipListener = new IPTreeListener(table);
        synchronized (macListener) {
            treeUtils.getSubtree(target, rootMACOID, null, macListener);
            synchronized(ipListener) {
                treeUtils.getSubtree(target, rootIPOID, null, ipListener);
                ipListener.wait();
            }
            macListener.wait();
        }


Now, the second question is that I have a container object that the
TreeListeneres will be adding objects to.  The psuedo code is:

If [ object with id from OID exists in container ] then
    set the variable in the container
Else
    create the object with the OID id and set the variable

Where variable can be IP/MAC/Status.  Is it possible to have a condition
where two listeners create the object at the same time, or one starts, then
the other overrides it?  If so, how would I get around that? With
synchronized?  

Thanks for any help.
-- 
MAT




More information about the SNMP4J mailing list