[SNMP4J] (WIP) SNMP4J CommonJ integration contrib

Frank Fock fock at agentpp.com
Mon Mar 8 22:25:03 CET 2010


Hi Brice,

I do not understand why you are using Threads instead
submitting WorkTasks directly using the WorkManager.
I have started implementing a generic adapter for JavaEE
but have not finished it yet. There is IMHO no need
to create any Threads, instead creating Work instances
and then submitting them is enough.

This should also solve the Thread sync problems you
described which are probably caused because the underlying
Threads are bound to a pool and not terminated.

Best regards,
Frank

On 08.03.2010 14:33, Brice Fines wrote:
> 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
>          }
>
> }
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.snmp4j.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list