[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Michael Yuan
michael.yuan at jboss.com
Mon Jun 4 21:06:05 EDT 2007
User: myuan
Date: 07/06/04 21:06:05
Modified: src/main/org/jboss/seam/core AbstractDispatcher.java
QuartzDispatcher.java TimerSchedule.java
Log:
initial support for cron job in QuartzDispatcher. Will update the examples soon .
Revision Changes Path
1.5 +12 -1 jboss-seam/src/main/org/jboss/seam/core/AbstractDispatcher.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractDispatcher.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/AbstractDispatcher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- AbstractDispatcher.java 31 May 2007 22:41:07 -0000 1.4
+++ AbstractDispatcher.java 5 Jun 2007 01:06:05 -0000 1.5
@@ -9,6 +9,7 @@
import org.jboss.seam.annotations.timer.Duration;
import org.jboss.seam.annotations.timer.Expiration;
import org.jboss.seam.annotations.timer.IntervalDuration;
+import org.jboss.seam.annotations.timer.Cron;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.contexts.Lifecycle;
import org.jboss.seam.intercept.InvocationContext;
@@ -152,6 +153,8 @@
Long duration = null;
Date expiration = null;
Long intervalDuration = null;
+ String cron = null;
+
Annotation[][] parameterAnnotations = invocation.getMethod().getParameterAnnotations();
for ( int i=0; i<parameterAnnotations.length; i++ )
{
@@ -170,10 +173,18 @@
{
expiration = (Date) invocation.getParameters()[i];
}
+ else if ( annotation.annotationType().equals(Cron.class) )
+ {
+ cron = (String) invocation.getParameters()[i];
+ }
}
}
+ if (cron == null) {
return new TimerSchedule(duration, expiration, intervalDuration);
+ } else {
+ return new TimerSchedule(duration, expiration, cron);
+ }
}
}
1.2 +27 -6 jboss-seam/src/main/org/jboss/seam/core/QuartzDispatcher.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: QuartzDispatcher.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/QuartzDispatcher.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- QuartzDispatcher.java 4 Jun 2007 22:46:26 -0000 1.1
+++ QuartzDispatcher.java 5 Jun 2007 01:06:05 -0000 1.2
@@ -15,6 +15,7 @@
import org.quartz.JobDataMap;
import org.quartz.Trigger;
import org.quartz.SimpleTrigger;
+import org.quartz.CronTrigger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
@@ -127,6 +128,32 @@
JobDetail jobDetail = new JobDetail(jobName, null, QuartzJob.class);
jobDetail.getJobDataMap().put("async", async);
+ if ( schedule.getCron()!=null )
+ {
+ try {
+ CronTrigger trigger = new CronTrigger (triggerName, null);
+ trigger.setCronExpression(schedule.getCron());
+ if ( schedule.getExpiration()!=null )
+ {
+ trigger.setStartTime (schedule.getExpiration());
+ }
+ else if ( schedule.getDuration()!=null )
+ {
+ trigger.setStartTime (calculateDelayedDate(schedule.getDuration()));
+ }
+
+ scheduler.scheduleJob( jobDetail, trigger );
+
+ return new QuartzTriggerHandle (triggerName);
+
+ } catch (Exception e) {
+ log.error ("Cannot submit cron job, fall back to fixed interval");
+ e.printStackTrace ();
+
+ // The method does not return, and execution flow follows
+ }
+ }
+
if ( schedule.getIntervalDuration()!=null )
{
if ( schedule.getExpiration()!=null )
@@ -134,21 +161,18 @@
SimpleTrigger trigger = new SimpleTrigger (triggerName, null, schedule.getExpiration(), null, SimpleTrigger.REPEAT_INDEFINITELY, schedule.getIntervalDuration());
scheduler.scheduleJob( jobDetail, trigger );
- // return executor.scheduleAtFixedRate( runnable, toDuration( schedule.getExpiration() ), schedule.getIntervalDuration(), TimeUnit.MILLISECONDS );
}
else if ( schedule.getDuration()!=null )
{
SimpleTrigger trigger = new SimpleTrigger (triggerName, null, calculateDelayedDate(schedule.getDuration()), null, SimpleTrigger.REPEAT_INDEFINITELY, schedule.getIntervalDuration());
scheduler.scheduleJob( jobDetail, trigger );
- // return executor.scheduleAtFixedRate( runnable, schedule.getDuration(), schedule.getIntervalDuration(), TimeUnit.MILLISECONDS );
}
else
{
SimpleTrigger trigger = new SimpleTrigger (triggerName, null, SimpleTrigger.REPEAT_INDEFINITELY, schedule.getIntervalDuration());
scheduler.scheduleJob( jobDetail, trigger );
- // return executor.scheduleAtFixedRate( runnable, 0l, schedule.getIntervalDuration(), TimeUnit.MILLISECONDS );
}
}
else if ( schedule.getExpiration()!=null )
@@ -156,21 +180,18 @@
SimpleTrigger trigger = new SimpleTrigger (triggerName, null, schedule.getExpiration());
scheduler.scheduleJob( jobDetail, trigger );
- // return executor.schedule( runnable, toDuration( schedule.getExpiration() ), TimeUnit.MILLISECONDS );
}
else if ( schedule.getDuration()!=null )
{
SimpleTrigger trigger = new SimpleTrigger (triggerName, null, calculateDelayedDate(schedule.getDuration()));
scheduler.scheduleJob( jobDetail, trigger );
- // return executor.schedule( runnable, schedule.getDuration(), TimeUnit.MILLISECONDS );
}
else
{
SimpleTrigger trigger = new SimpleTrigger (triggerName, null);
scheduler.scheduleJob( jobDetail, trigger );
- // return executor.schedule(runnable, 0l, TimeUnit.MILLISECONDS);
}
return new QuartzTriggerHandle (triggerName);
}
1.2 +34 -1 jboss-seam/src/main/org/jboss/seam/core/TimerSchedule.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TimerSchedule.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/TimerSchedule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- TimerSchedule.java 31 May 2007 21:05:28 -0000 1.1
+++ TimerSchedule.java 5 Jun 2007 01:06:05 -0000 1.2
@@ -20,6 +20,7 @@
private Long duration;
private Date expiration;
private Long intervalDuration;
+ private String cron;
Long getDuration()
{
@@ -36,6 +37,11 @@
return intervalDuration;
}
+ String getCron()
+ {
+ return cron;
+ }
+
/**
* @param duration the delay before the event occurs
*/
@@ -63,6 +69,16 @@
}
/**
+ * @param duration the delay before the first event occurs
+ * @param cron the unix cron string to control how the events are repeated
+ */
+ public TimerSchedule(Long duration, String cron)
+ {
+ this.duration = duration;
+ this.cron = cron;
+ }
+
+ /**
* @param expiration the datetime at which the first event occurs
* @param intervalDuration the period between the events
*/
@@ -72,6 +88,16 @@
this.intervalDuration = intervalDuration;
}
+ /**
+ * @param expiration the datetime at which the first event occurs
+ * @param cron the unix cron string to control how the events are repeated
+ */
+ public TimerSchedule(Date expiration, String cron)
+ {
+ this.expiration = expiration;
+ this.cron = cron;
+ }
+
TimerSchedule(Long duration, Date expiration, Long intervalDuration)
{
this.duration = duration;
@@ -79,6 +105,13 @@
this.intervalDuration = intervalDuration;
}
+ TimerSchedule(Long duration, Date expiration, String cron)
+ {
+ this.duration = duration;
+ this.expiration = expiration;
+ this.cron = cron;
+ }
+
TimerSchedule() {}
public static final TimerSchedule ONCE_IMMEDIATELY = new TimerSchedule();
More information about the jboss-cvs-commits
mailing list