giacomo 2003/09/05 03:21:28
Modified: src/blocks/cron/java/org/apache/cocoon/components/cron
QuartzJobScheduler.java
Log:
pretty printed
Revision Changes Path
1.5 +51 -47
cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
Index: QuartzJobScheduler.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -b -u -r1.4 -r1.5
--- QuartzJobScheduler.java 4 Sep 2003 15:57:41 -0000 1.4
+++ QuartzJobScheduler.java 5 Sep 2003 10:21:28 -0000 1.5
@@ -85,6 +85,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @version CVS $Id$
+ *
* @since 2.1.1
*/
public class QuartzJobScheduler
@@ -176,35 +177,6 @@
return null;
}
- /**
- * Schedule a period job. Note that if a Job already has same name then
it is overwritten.
- *
- * @param name the name of the job
- * @param jobrole The Avalon components role name of the job itself
- * @param period Every period seconds this job is started
- * @param canRunConcurrently whether this job can run even previous
scheduled runs are still running
- */
- public void addPeriodicJob(String name,
- String jobrole,
- long period,
- boolean canRunConcurrently,
- Parameters params,
- Map objects)
- throws CascadingException {
- final JobDataMap jobDataMap = new JobDataMap();
- jobDataMap.put(DATA_MAP_ROLE, jobrole);
-
- final long ms = period * 1000;
- final SimpleTrigger timeEntry = new SimpleTrigger(name,
-
DEFAULT_QUARTZ_JOB_GROUP,
- new
Date(System.currentTimeMillis() + ms),
- null,
-
SimpleTrigger.REPEAT_INDEFINITELY,
- ms);
-
- addJob(name, jobDataMap, timeEntry, canRunConcurrently, params,
objects);
- }
-
/* (non-Javadoc)
* @see
org.apache.cocoon.components.cron.JobScheduler#addJob(java.lang.String,
java.lang.Object, java.lang.String, boolean,
org.apache.avalon.framework.parameters.Parameters, java.util.Map)
*/
@@ -248,6 +220,32 @@
addJob(name, jobrole, cronSpec, canRunConcurrently, null, null);
}
+ /**
+ * Schedule a period job. Note that if a Job already has same name then
it is overwritten.
+ *
+ * @param name the name of the job
+ * @param jobrole The Avalon components role name of the job itself
+ * @param period Every period seconds this job is started
+ * @param canRunConcurrently whether this job can run even previous
scheduled runs are still running
+ * @param params additional Parameters to be passed to the job
+ * @param objects additional objects to be passed to the job
+ *
+ * @throws CascadingException in case of failures
+ */
+ public void addPeriodicJob(String name, String jobrole, long period,
boolean canRunConcurrently, Parameters params,
+ Map objects)
+ throws CascadingException {
+ final JobDataMap jobDataMap = new JobDataMap();
+ jobDataMap.put(DATA_MAP_ROLE, jobrole);
+
+ final long ms = period * 1000;
+ final SimpleTrigger timeEntry =
+ new SimpleTrigger(name, DEFAULT_QUARTZ_JOB_GROUP, new
Date(System.currentTimeMillis() + ms), null,
+ SimpleTrigger.REPEAT_INDEFINITELY, ms);
+
+ addJob(name, jobDataMap, timeEntry, canRunConcurrently, params,
objects);
+ }
+
/* (non-Javadoc)
* @see
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
@@ -393,16 +391,13 @@
public void removeJob(final String name)
throws NoSuchElementException {
try {
- if( m_scheduler.deleteJob(name, DEFAULT_QUARTZ_JOB_GROUP) )
- {
- getLogger().info( "job " + name + " removed by request" );
- }
- else
- {
- getLogger().error( "couldn't remove requested job " + name
);
+ if (m_scheduler.deleteJob(name, DEFAULT_QUARTZ_JOB_GROUP)) {
+ getLogger().info("job " + name + " removed by request");
+ } else {
+ getLogger().error("couldn't remove requested job " + name);
}
} catch (final SchedulerException se) {
- getLogger().error( "cannot remove job " + name, se );
+ getLogger().error("cannot remove job " + name, se);
throw new NoSuchElementException(se.getMessage());
}
}
@@ -491,6 +486,15 @@
private void addJob(final String name, final JobDataMap jobDataMap,
final Trigger trigger,
final boolean canRunConcurrently, final Parameters
params, final Map objects)
throws CascadingException {
+ try {
+ final JobDetail jobdetail = m_scheduler.getJobDetail(name,
DEFAULT_QUARTZ_JOB_GROUP);
+
+ if (jobdetail != null) {
+ removeJob(name);
+ }
+ } catch (final SchedulerException se) {
+ }
+
jobDataMap.put(DATA_MAP_NAME, name);
jobDataMap.put(DATA_MAP_LOGGER, getLogger());
jobDataMap.put(DATA_MAP_MANAGER, m_manager);
@@ -509,20 +513,20 @@
if (getLogger().isInfoEnabled()) {
getLogger().info("Adding CronJob '" + trigger.getFullName() +
"'");
-
- if (getLogger().isDebugEnabled()) {
- if (trigger instanceof CronTrigger) {
- getLogger().debug("Time schedule summary:\n" +
((CronTrigger)trigger).getExpressionSummary());
- } else if (trigger instanceof SimpleTrigger) {
- getLogger().debug("Next scheduled time: " +
((SimpleTrigger)trigger).getNextFireTime());
- }
- }
}
try {
m_scheduler.scheduleJob(detail, trigger);
} catch (final SchedulerException se) {
throw new CascadingException(se.getMessage(), se);
+ }
+
+ if (getLogger().isDebugEnabled()) {
+ if (trigger instanceof CronTrigger) {
+ getLogger().debug("Time schedule summary:\n" +
((CronTrigger)trigger).getExpressionSummary());
+ } else {
+ getLogger().debug("Next scheduled time: " +
trigger.getNextFireTime());
+ }
}
}