cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: rev 47533 - in cocoon/branches/BRANCH_2_1_X: . src/blocks/cron/java/org/apache/cocoon/components/cron
Date Thu, 30 Sep 2004 03:15:56 GMT
Author: vgritsenko
Date: Wed Sep 29 20:15:55 2004
New Revision: 47533

Modified:
   cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/JobScheduler.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobExecutor.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
fix fireJob


Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/JobScheduler.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/JobScheduler.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/JobScheduler.java
Wed Sep 29 20:15:55 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,12 +22,11 @@
 import org.apache.avalon.framework.CascadingException;
 import org.apache.avalon.framework.parameters.Parameters;
 
-
 /**
  * This component schedules jobs.
  *
  * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
- * @version CVS $Id: JobScheduler.java,v 1.7 2004/03/08 13:43:42 unico Exp $
+ * @version CVS $Id$
  *
  * @since 2.1.1
  */

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobExecutor.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobExecutor.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobExecutor.java
Wed Sep 29 20:15:55 2004
@@ -53,7 +53,7 @@
     public void execute(final JobExecutionContext context)
     throws JobExecutionException {
         final JobDataMap data = context.getJobDetail().getJobDataMap();
-        data.put(QuartzJobScheduler.DATA_MAP_JOB_EXECUTION_CONTEXT, context);
+        // data.put(QuartzJobScheduler.DATA_MAP_JOB_EXECUTION_CONTEXT, context);
 
         final Logger logger = (Logger)data.get(QuartzJobScheduler.DATA_MAP_LOGGER);
         final String name = (String)data.get(QuartzJobScheduler.DATA_MAP_NAME);
@@ -62,8 +62,7 @@
 
         if (!canRunConcurrently) {
             Boolean isRunning = (Boolean)data.get(QuartzJobScheduler.DATA_MAP_KEY_ISRUNNING);
-
-            if ((null != isRunning) && isRunning.booleanValue()) {
+            if (Boolean.TRUE.equals(isRunning)) {
                 logger.warn("Cron job name '" + name +
                             " already running but configured to not allow concurrent runs.
Will discard this scheduled run");
                 return;
@@ -71,7 +70,7 @@
         }
 
         if (logger.isInfoEnabled()) {
-            logger.info("Scheduling cron job named '" + name + "'");
+            logger.info("Executing cron job named '" + name + "'");
         }
 
         Context appContext = (Context) data.get(QuartzJobScheduler.DATA_MAP_CONTEXT);
@@ -80,8 +79,7 @@
         try {
             envContext =
                 (org.apache.cocoon.environment.Context) appContext.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
-        }
-        catch (ContextException e) {
+        } catch (ContextException e) {
         	throw new JobExecutionException(e);
         }
 
@@ -139,10 +137,10 @@
                 logger.error("job named '" + name + "' is of invalid class: " + job.getClass().getName());
             }
         } catch (final Throwable t) {
-            logger.error("Cron job name '" + name + " died.", t);
+            logger.error("Cron job name '" + name + "' died.", t);
 
             if (t instanceof JobExecutionException) {
-                throw (JobExecutionException)t;
+                throw (JobExecutionException) t;
             }
         } finally {
             data.put(QuartzJobScheduler.DATA_MAP_KEY_ISRUNNING, Boolean.FALSE);

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
Wed Sep 29 20:15:55 2004
@@ -46,11 +46,14 @@
 import org.quartz.SchedulerException;
 import org.quartz.SimpleTrigger;
 import org.quartz.Trigger;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
 import org.quartz.impl.DirectSchedulerFactory;
 import org.quartz.impl.jdbcjobstore.InvalidConfigurationException;
 import org.quartz.impl.jdbcjobstore.JobStoreSupport;
 import org.quartz.simpl.RAMJobStore;
 import org.quartz.spi.JobStore;
+import org.quartz.spi.TriggerFiredBundle;
 import org.quartz.utils.ConnectionProvider;
 import org.quartz.utils.DBConnectionManager;
 import org.quartz.utils.JNDIConnectionProvider;
@@ -115,8 +118,8 @@
     /** Map key for additional Object Map */
     static final String DATA_MAP_OBJECTMAP = "QuartzJobScheduler.Map";
 
-    /** Map key for the last JobExecutionContext */
-    static final String DATA_MAP_JOB_EXECUTION_CONTEXT = "QuartzJobScheduler.JobExecutionContext";
+    /* Map key for the last JobExecutionContext
+    static final String DATA_MAP_JOB_EXECUTION_CONTEXT = "QuartzJobScheduler.JobExecutionContext";
*/
 
     /** Map key for the run status */
     static final String DATA_MAP_KEY_ISRUNNING = "QuartzJobExecutor.isRunning";
@@ -537,23 +540,16 @@
     throws CascadingException {
         try {
             final JobDetail jobdetail = scheduler.getJobDetail(name, DEFAULT_QUARTZ_JOB_GROUP);
-
             if (jobdetail != null) {
                 removeJob(name);
             }
-        } catch (final SchedulerException se) {
+        } catch (final SchedulerException ignored) {
         }
 
-        jobDataMap.put(DATA_MAP_NAME, name);
-        jobDataMap.put(DATA_MAP_LOGGER, getLogger());
-        jobDataMap.put(DATA_MAP_CONTEXT, this.context);
-        jobDataMap.put(DATA_MAP_MANAGER, this.manager);
-        jobDataMap.put(DATA_MAP_RUN_CONCURRENT, new Boolean(canRunConcurrently));
-
+        initDataMap(jobDataMap, name, canRunConcurrently);
         if (null != params) {
             jobDataMap.put(DATA_MAP_PARAMETERS, params);
         }
-
         if (null != objects) {
             jobDataMap.put(DATA_MAP_OBJECTMAP, objects);
         }
@@ -580,6 +576,15 @@
         }
     }
 
+    private JobDataMap initDataMap(JobDataMap jobDataMap, String jobName, boolean concurent)
{
+        jobDataMap.put(DATA_MAP_NAME, jobName);
+        jobDataMap.put(DATA_MAP_LOGGER, getLogger());
+        jobDataMap.put(DATA_MAP_CONTEXT, this.context);
+        jobDataMap.put(DATA_MAP_MANAGER, this.manager);
+        jobDataMap.put(DATA_MAP_RUN_CONCURRENT, concurent? Boolean.TRUE: Boolean.FALSE);
+        return jobDataMap;
+    }
+
     /**
      * Create a ThreadPool
      *
@@ -755,16 +760,32 @@
     private boolean fireJob(final String name, final Object job) {
         try {
             if (job instanceof CronJob) {
+                JobDataMap jobDataMap = new JobDataMap();
+                jobDataMap.put(DATA_MAP_OBJECT, job);
+                initDataMap(jobDataMap, name, true);
+
+                JobDetail detail = new JobDetail(name, DEFAULT_QUARTZ_JOB_GROUP, QuartzJobExecutor.class);
+                detail.setJobDataMap(jobDataMap);
+
+                TriggerFiredBundle trigger = new TriggerFiredBundle(detail, null, null, false,
null, null, null, null);
+
+                final QuartzJobExecutor executor = new QuartzJobExecutor();
+                final JobExecutionContext context = new JobExecutionContext(this.scheduler,
trigger, executor);
+
                 this.executor.execute(new Runnable() {
                         public void run() {
-                            ((CronJob)job).execute(name);
+                            // ((CronJob)job).execute(name);
+                            try {
+                                executor.execute(context);
+                            } catch (JobExecutionException e) {
+                                getLogger().error("Job '" + job + "' died.", e);
+                            }
                         }
                     });
             } else if (job instanceof Runnable) {
                 this.executor.execute((Runnable)job);
             } else {
-                getLogger().error("job named '" + name + "' is of invalid class: " + job.getClass().getName());
-
+                getLogger().error("Job named '" + name + "' is of invalid class: " + job.getClass().getName());
                 return false;
             }
 

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml	Wed Sep 29 20:15:55 2004
@@ -206,6 +206,10 @@
   <changes>
  <release version="@version@" date="@date@">
    <action dev="VG" type="fix">
+     Cron block: JobScheduler's fireJob method now supports jobs calling Cocoon
+     pipelines.
+   </action>
+   <action dev="VG" type="fix">
      Allow recursive Flow invocations with processPipelineTo.
    </action>
    <action dev="SW" type="fix">

Mime
View raw message