[SNMP4J] (WIP) SNMP4J CommonJ integration contrib

Brice Fines bfines at sermepa.es
Mon Mar 8 14:33:56 CET 2010


Hi Frank,

I'am working on integrating SNMP4J in WAS 6.1 (with SNMP4JSettings).
I based my work on some IBM example code (i.e. not official code) that 
provide the base for a J2EE thread factory under WAS 6.1.
The IBM code is available at :

http://www.ibm.com/developerworks/websphere/techjournal/0606_johnson/0606_johnson.html

http://www.ibm.com/developerworks/apps/download/index.jsp?contentid=132574&filename=ConcurrencyAdapterSample.zip&method=http&locale=worldwide

The WAS thread factory uses WAS threads from WorkManager.

I made the following code (please note that's a work in progress; I still 
have to integrate a timer factory (maybe there is something to do with 
CommonJ timers)). 
I still have some problem when stopping the server in the IDE environment 
(the WAS threads go on, but that can be a RAD 7 problem).
I am running my tests with SNMP4J 1.10.2 (just to be sure to avoid IBM JVM 
troubles with threads select used in SNMP4J 1.11)
My app use its own Workmanager, and this workmanager has the "growable" 
option activated (i.e. it creates threads as needed, even if it has to 
exceed the maximum specified in his configuration). (the work manager is 
injected into the factory, the factory is injected in SNMP4JSettings, and 
Spring makes sure that SNMP4JSettings is called first).
So far so good (except for the RAD7 problems as mentioned above).
It would be great if you can somewhat "validate" this. For example, I have 
some doubts, is there any problem in ignoring the daemon parameter? In 
ignoring thread name parameter?
This could be used for SNMP4J projects in IBM WAS servers and BEA Weblogic 
servers .
I hope that you will find some time to have a look, I would be very 
interested if you have any comments.
Thanks in advance.

Brice


import org.snmp4j.log.LogAdapter;
import org.snmp4j.log.LogFactory;
import org.snmp4j.util.ThreadFactory;
import org.snmp4j.util.WorkerTask;

import com.ibm.websphere.asynchbeans.WorkManager;
import com.ibm.websphere.sample.concurrentadapter.WASThreadFactoryBase;

/**
 * TreadFactory implementation for Websphere WAS 6.1, based on 
WASThreadFactory
 * by IBM, to integrate SNMP4J.
 */
public class WasThreadFactoryImpl extends WASThreadFactoryBase implements
                ThreadFactory {

        /**
         * Logger.
         */
        final static LogAdapter LOGGER = LogFactory
                        .getLogger(WasThreadFactoryImpl.class);

        /**
         * Constructor.
         * 
         * @param wm
         *            a WorkManager.
         */
        public WasThreadFactoryImpl(WorkManager wm) {
                super(wm);
        }

        /*
         * (without Javadoc)
         * 
         * @see 
org.snmp4j.util.ThreadFactory#createWorkerThread(java.lang.String,
         *      org.snmp4j.util.WorkerTask, boolean)
         */
        public WorkerTask createWorkerThread(String name, WorkerTask task,
                        boolean daemon) {
                LOGGER.debug("Creating thread: " + name + " daemon: " + 
daemon);
                final Thread thread = super.newThread(task);
                // thread.setName(name);
                // seems to work without applying thread name
                // thread.setDaemon(daemon);
                // seems to prevent IDE from terminating server properly 
if daemon
                // parameter is applied
                return new WasWorkerThread(thread);
        }

}

import org.snmp4j.log.LogAdapter;
import org.snmp4j.log.LogFactory;
import org.snmp4j.util.WorkerTask;

/**
 * WorkerTask implementation for Websphere WAS 6.1, based on 
WASThreadFactory by
 * IBM, to integrate SNMP4J.
 */
public class WasWorkerThread implements WorkerTask {

        /**
         * Logger.
         */
        final static LogAdapter LOGGER = LogFactory
                        .getLogger(WasWorkerThread.class);

        /**
         * Thread.
         */
        private Thread thread;

        /**
         * Constructor.
         * 
         * @param wm
         *            a WorkManager.
         * @param runnableWrapper
         *            a RunnableWrapper.
         */
        public WasWorkerThread(Thread thread) {
                this.thread = thread;
        }

        /*
         * (without Javadoc)
         * 
         * @see java.lang.Runnable#run()
         */
        public void run() {
                LOGGER.debug("Thread run: " + this.thread.getName());
                thread.start();
                // thread.run();
                // seems the thread is run automatically
        }

        /*
         * (without Javadoc)
         * 
         * @see org.snmp4j.util.WorkerTask#interrupt()
         */
        public void interrupt() {
                LOGGER.debug("Thread interrupt: " + this.thread
.getName());
                thread.interrupt();
        }

        /*
         * (without Javadoc)
         * 
         * @see org.snmp4j.util.WorkerTask#join()
         */
        public void join() throws InterruptedException {
                LOGGER.debug("Thread join: " + this.thread.getName());
                thread.join();
        }

        /*
         * (without Javadoc)
         * 
         * @see org.snmp4j.util.WorkerTask#terminate()
         */
        public void terminate() {
                LOGGER.debug("Thread terminate: " + this.thread
.getName());
                // do nothing
        }

}


More information about the SNMP4J mailing list