[Jboss-cvs] JBossAS SVN: r55376 - trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 7 14:57:57 EDT 2006


Author: alesj
Date: 2006-08-07 14:57:53 -0400 (Mon, 07 Aug 2006)
New Revision: 55376

Modified:
   trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/JBossQuartzThreadPool.java
   trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/QuartzResourceAdapter.java
Log:
Fixed Quartz thread pool: JBAS-1792.

Modified: trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/JBossQuartzThreadPool.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/JBossQuartzThreadPool.java	2006-08-07 18:01:51 UTC (rev 55375)
+++ trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/JBossQuartzThreadPool.java	2006-08-07 18:57:53 UTC (rev 55376)
@@ -21,52 +21,39 @@
 */
 package org.jboss.resource.adapter.quartz.inflow;
 
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.util.threadpool.RunnableTaskWrapper;
-import org.jboss.util.threadpool.ThreadPool;
 import org.quartz.SchedulerConfigException;
 
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkManager;
 
 /**
  * Thread pool used to fire Quartz Jobs.
+ * <p/>
+ * Using BootstrapContext's workManager thread pool.
+ * No dependency outside this rar or JCA.
  *
- * By default it uses 'in house' thread pool - JCA's WorkerManagerThreadPool.
- * You can create your own instance of JBoss's thread pool and instantiate it in
- * jbossjca-service.xml or any other -service.xml deploy file.
- * Simply link it with JMX object name - see property threadPoolObjectName.
- *
+ * @see http://jira.jboss.com/jira/browse/JBAS-1792
  * @see quartz.properties
- * #org.quartz.threadPool.threadPoolObjectName=jboss.jca:service=MyThreadPool
  *
  * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
  */
 public class JBossQuartzThreadPool implements org.quartz.spi.ThreadPool
 {
-   private static final String WORK_MANAGER_THREAD_POOL = "jboss.jca:service=WorkManagerThreadPool";
+   private int poolSize = Integer.MAX_VALUE;
 
-   private String threadPoolObjectName = WORK_MANAGER_THREAD_POOL;
+   private WorkManager workManager;
 
-   private int poolSize;
-
-   private ThreadPool threadPool;
-
    public void initialize() throws SchedulerConfigException
    {
-      try
-      {
-         MBeanServer server = MBeanServerLocator.locateJBoss();
-         ObjectName tpObjectName = new ObjectName(getThreadPoolObjectName());
-         threadPool = (ThreadPool) server.getAttribute(tpObjectName, "Instance");
-         poolSize = ((Integer) server.getAttribute(tpObjectName, "MaximumPoolSize")).intValue();
-      }
-      catch (Exception e)
-      {
-         throw new SchedulerConfigException("Unable to use jboss thread pool.", e);
-      }
+      workManager = QuartzResourceAdapter.getConfigTimeWorkManager();
    }
 
+   /**
+    * Currently this method is only used in metadata lookup.
+    * Which is has no further use.
+    * How to provide better estimate?
+    */
    public int getPoolSize()
    {
       return poolSize;
@@ -74,31 +61,52 @@
 
    public boolean runInThread(Runnable runnable)
    {
-      RunnableTaskWrapper runnableTaskWrapper = new RunnableTaskWrapper(runnable, 0, 0);
-      threadPool.run(runnableTaskWrapper);
-      return runnableTaskWrapper.isComplete();
+      try
+      {
+         WorkWrapper workWrapper = new WorkWrapper(runnable);
+         workManager.doWork(workWrapper);
+         return true;
+      }
+      catch (WorkException e)
+      {
+         return false;
+      }
    }
 
    /**
-    * JBoss Thread Pool is stopped by ServiceController.
-    * By default it waits for threads (jobs) to finish.
-    *
-    * @see org.jboss.util.threadpool.BasicThreadPool#stop();
+    * No shutdown impl - workManager is shutdown by itself.
     */
    public void shutdown(boolean waitForJobsToComplete)
    {
    }
 
-   // -------- setters & getters
-
-   public String getThreadPoolObjectName()
+   /**
+    * Just in case we want to set pool size.
+    */
+   public void setPoolSize(int poolSize)
    {
-      return threadPoolObjectName;
+      this.poolSize = poolSize;
    }
 
-   public void setThreadPoolObjectName(String threadPoolObjectName)
+   private class WorkWrapper implements Work
    {
-      this.threadPoolObjectName = threadPoolObjectName;
+
+      private Runnable delegate;
+
+      public WorkWrapper(Runnable delegate)
+      {
+         this.delegate = delegate;
+      }
+
+      public void run()
+      {
+         delegate.run();
+      }
+
+      public void release()
+      {
+      }
+
    }
 
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/QuartzResourceAdapter.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/QuartzResourceAdapter.java	2006-08-07 18:01:51 UTC (rev 55375)
+++ trunk/connector/src/main/org/jboss/resource/adapter/quartz/inflow/QuartzResourceAdapter.java	2006-08-07 18:57:53 UTC (rev 55376)
@@ -29,6 +29,7 @@
 import javax.resource.spi.BootstrapContext;
 import javax.resource.spi.ResourceAdapterInternalException;
 import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.work.WorkManager;
 import javax.resource.spi.endpoint.MessageEndpointFactory;
 import javax.resource.spi.endpoint.MessageEndpoint;
 import javax.resource.ResourceException;
@@ -44,8 +45,14 @@
 {
    private static Logger log = Logger.getLogger(QuartzResourceAdapter.class);
 
+   private static final ThreadLocal holder = new ThreadLocal();
+
    private Scheduler sched;
 
+   public static WorkManager getConfigTimeWorkManager() {
+      return (WorkManager) holder.get();
+   }
+
    public void start(BootstrapContext ctx) throws ResourceAdapterInternalException
    {
       log.info("start quartz!!!");
@@ -53,6 +60,7 @@
       SchedulerFactory sf = new StdSchedulerFactory();
       try
       {
+         holder.set(ctx.getWorkManager());
          sched = sf.getScheduler();
          sched.start();
       }
@@ -60,6 +68,10 @@
       {
          throw new ResourceAdapterInternalException(e);
       }
+      finally
+      {
+         holder.set(null);
+      }
    }
 
    public void stop()




More information about the jboss-cvs-commits mailing list