Author: unico
Date: Tue Aug 17 06:26:46 2004
New Revision: 36526

Modified:
   cocoon/branches/BRANCH_2_1_X/src/blocks/cron/conf/cron.xconf
   
cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
Log:
port from 2.2: make type of job store to use configurable

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/cron/conf/cron.xconf
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/cron/conf/cron.xconf        
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/cron/conf/cron.xconf        Tue Aug 
17 06:26:46 2004
@@ -45,6 +45,14 @@
             <!-- The maximum time to wait for running jobs to complete. 
Defaults to unlimited time (<0 == default) -->
             <shutdown-wait-time-ms>5000</shutdown-wait-time-ms>
         </thread-pool>
+        <!-- Definition of the JobStore -->
+        <!-- store type is one of "ram" (default), "tx", or "cmt" -->
+        <store type="ram"/>
+        <!--
+        <store type="tx">
+          <datasource>jdbc/MyJobStoreDS</datasource>
+        </store>
+        -->
         <!-- Definintions of triggers -->
         <triggers>
             <!-- Sample definition of a trigger -->

Modified: 
cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
 Tue Aug 17 06:26:46 2004
@@ -48,7 +48,11 @@
 import org.quartz.SimpleTrigger;
 import org.quartz.Trigger;
 import org.quartz.impl.DirectSchedulerFactory;
+import org.quartz.impl.jdbcjobstore.JobStoreCMT;
+import org.quartz.impl.jdbcjobstore.JobStoreSupport;
+import org.quartz.impl.jdbcjobstore.JobStoreTX;
 import org.quartz.simpl.RAMJobStore;
+import org.quartz.spi.JobStore;
 
 import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
@@ -59,7 +63,7 @@
  * This component can either schedule jobs or directly execute one.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Id: QuartzJobScheduler.java,v 1.12 2004/03/11 22:05:12 
sylvain Exp $
+ * @version CVS $Id$
  *
  * @since 2.1.1
  */
@@ -304,8 +308,8 @@
                        // we cannot create the same scheduler again
                        final String runID = new Date().toString().replace(' ', 
'_');
                        final ThreadPool pool = 
createThreadPool(this.config.getChild("thread-pool"));
-                       
DirectSchedulerFactory.getInstance().createScheduler(DEFAULT_QUARTZ_SCHEDULER_NAME,
 runID, pool,
-                                                                               
                                                 new RAMJobStore());
+            final JobStore store = 
createJobStore(this.config.getChild("job-store"));
+                       
DirectSchedulerFactory.getInstance().createScheduler(DEFAULT_QUARTZ_SCHEDULER_NAME,
 runID, pool, store);
                        // scheduler = 
DirectSchedulerFactory.getInstance().getScheduler(DEFAULT_QUARTZ_SCHEDULER_NAME,
 runID);
                        scheduler = 
DirectSchedulerFactory.getInstance().getScheduler(DEFAULT_QUARTZ_SCHEDULER_NAME);
                } catch (final SchedulerException se) {
@@ -686,6 +690,26 @@
         }
     }
 
+    private JobStore createJobStore(final Configuration configuration)
+    throws ConfigurationException {
+        String type = configuration.getAttribute("type", "ram");
+        if (type.equals("ram")) {
+            return new RAMJobStore();
+        }
+        JobStoreSupport store = null;
+        if (type.equals("tx")) {
+            store = new JobStoreTX();
+        }
+        else if (type.equals("cmt")) {
+            store = new JobStoreCMT();
+        }
+        else {
+            throw new ConfigurationException("Unknown store type: " + type);
+        }
+        store.setDataSource(configuration.getChild("datasource").getValue());
+        return store;
+    }
+
     /* (non-Javadoc)
      * @see 
org.apache.cocoon.components.cron.JobScheduler#fireTarget(java.lang.Object)
      */
@@ -717,7 +741,7 @@
      * A ThreadPool for the Quartz Scheduler based on Doug Leas concurrency 
utilities PooledExecutor
      *
      * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
-     * @version CVS $Id: QuartzJobScheduler.java,v 1.12 2004/03/11 22:05:12 
sylvain Exp $
+     * @version CVS $Id$
      */
     private static class ThreadPool extends AbstractLogEnabled implements 
org.quartz.spi.ThreadPool {
         /** Our executor thread pool */

Reply via email to