[jboss-cvs] jboss-seam/src/main/org/jboss/seam/async ...
Gavin King
gavin.king at jboss.com
Fri Nov 9 05:01:46 EST 2007
User: gavin
Date: 07/11/09 05:01:46
Modified: src/main/org/jboss/seam/async
ThreadPoolDispatcher.java AbstractDispatcher.java
TimerServiceDispatcher.java QuartzDispatcher.java
Removed: src/main/org/jboss/seam/async
NthBusinessDaySchedule.java NthBusinessDay.java
Log:
Remove NthBusinessDay stuff
Fix exception handling
Revision Changes Path
1.4 +17 -5 jboss-seam/src/main/org/jboss/seam/async/ThreadPoolDispatcher.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ThreadPoolDispatcher.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/async/ThreadPoolDispatcher.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ThreadPoolDispatcher.java 20 Jun 2007 15:53:32 -0000 1.3
+++ ThreadPoolDispatcher.java 9 Nov 2007 10:01:46 -0000 1.4
@@ -61,24 +61,36 @@
{
if ( schedule.getExpiration()!=null )
{
- return executor.scheduleAtFixedRate( runnable, toDuration( schedule.getExpiration() ), schedule.getIntervalDuration(), TimeUnit.MILLISECONDS );
+ return executor.scheduleAtFixedRate( runnable,
+ toDuration( schedule.getExpiration() ),
+ schedule.getIntervalDuration(),
+ TimeUnit.MILLISECONDS );
}
else if ( schedule.getDuration()!=null )
{
- return executor.scheduleAtFixedRate( runnable, schedule.getDuration(), schedule.getIntervalDuration(), TimeUnit.MILLISECONDS );
+ return executor.scheduleAtFixedRate( runnable,
+ schedule.getDuration(),
+ schedule.getIntervalDuration(),
+ TimeUnit.MILLISECONDS );
}
else
{
- return executor.scheduleAtFixedRate( runnable, 0l, schedule.getIntervalDuration(), TimeUnit.MILLISECONDS );
+ return executor.scheduleAtFixedRate( runnable, 0l,
+ schedule.getIntervalDuration(),
+ TimeUnit.MILLISECONDS );
}
}
else if ( schedule.getExpiration()!=null )
{
- return executor.schedule( runnable, toDuration( schedule.getExpiration() ), TimeUnit.MILLISECONDS );
+ return executor.schedule( runnable,
+ toDuration( schedule.getExpiration() ),
+ TimeUnit.MILLISECONDS );
}
else if ( schedule.getDuration()!=null )
{
- return executor.schedule( runnable, schedule.getDuration(), TimeUnit.MILLISECONDS );
+ return executor.schedule( runnable,
+ schedule.getDuration(),
+ TimeUnit.MILLISECONDS );
}
else
{
1.7 +0 -11 jboss-seam/src/main/org/jboss/seam/async/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/async/AbstractDispatcher.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- AbstractDispatcher.java 25 Jul 2007 19:42:05 -0000 1.6
+++ AbstractDispatcher.java 9 Nov 2007 10:01:46 -0000 1.7
@@ -9,7 +9,6 @@
import org.jboss.seam.annotations.async.FinalExpiration;
import org.jboss.seam.annotations.async.IntervalCron;
import org.jboss.seam.annotations.async.IntervalDuration;
-import org.jboss.seam.annotations.async.IntervalBusinessDay;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.intercept.InvocationContext;
import org.jboss.seam.transaction.Transaction;
@@ -52,7 +51,6 @@
Long intervalDuration = null;
String cron = null;
- NthBusinessDay intervalBusinessDay = null;
int intervalParamCount = 0;
@@ -84,11 +82,6 @@
cron = (String) invocation.getParameters()[i];
intervalParamCount++;
}
- else if ( annotation.annotationType().equals(IntervalBusinessDay.class) )
- {
- intervalBusinessDay = (NthBusinessDay) invocation.getParameters()[i];
- intervalParamCount++;
- }
}
}
@@ -100,10 +93,6 @@
{
return new CronSchedule(duration, expiration, cron, finalExpiration);
}
- else if (intervalBusinessDay != null)
- {
- return new NthBusinessDaySchedule(duration, expiration, intervalBusinessDay, finalExpiration);
- }
else
{
return new TimerSchedule(duration, expiration, intervalDuration, finalExpiration);
1.3 +3 -1 jboss-seam/src/main/org/jboss/seam/async/TimerServiceDispatcher.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TimerServiceDispatcher.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/async/TimerServiceDispatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- TimerServiceDispatcher.java 19 Jun 2007 20:08:12 -0000 1.2
+++ TimerServiceDispatcher.java 9 Nov 2007 10:01:46 -0000 1.3
@@ -62,7 +62,9 @@
public Timer scheduleInvocation(InvocationContext invocation, Component component)
{
- return new TimerProxy( scheduleWithTimerService( (TimerSchedule) createSchedule(invocation), new AsynchronousInvocation(invocation, component) ) );
+ return new TimerProxy(
+ scheduleWithTimerService( (TimerSchedule) createSchedule(invocation),
+ new AsynchronousInvocation(invocation, component) ) );
}
1.12 +98 -163 jboss-seam/src/main/org/jboss/seam/async/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/async/QuartzDispatcher.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- QuartzDispatcher.java 16 Oct 2007 16:48:56 -0000 1.11
+++ QuartzDispatcher.java 9 Nov 2007 10:01:46 -0000 1.12
@@ -4,6 +4,7 @@
import java.io.InputStream;
import java.rmi.server.UID;
+import java.text.ParseException;
import java.util.Date;
import org.jboss.seam.Component;
@@ -24,7 +25,6 @@
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
-import org.quartz.NthIncludedDayTrigger;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
@@ -49,31 +49,25 @@
private Scheduler scheduler;
@Create
- public void initScheduler()
+ public void initScheduler() throws SchedulerException
{
StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
- try
- {
+ //TODO: magical properties files are *not* the way to config Seam apps!
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("seam.quartz.properties");
- if (is != null) {
+ if (is != null)
+ {
schedulerFactory.initialize(is);
log.debug("Found seam.quartz.properties file. Using it for Quartz config.");
- // } else if () {
- // log.trace("Delpoy in JBoss AS, use HSQL for default job store");
- } else {
+ }
+ else
+ {
schedulerFactory.initialize();
log.debug("No seam.quartz.properties file. Using in-memory job store.");
}
scheduler = schedulerFactory.getScheduler();
scheduler.start();
- log.info("The Quartz Dispatcher has started");
- }
- catch (SchedulerException se) {
- log.error("Cannot get or start a Quartz Scheduler");
- se.printStackTrace ();
- }
}
public QuartzTriggerHandle scheduleAsynchronousEvent(String type, Object... parameters)
@@ -85,52 +79,26 @@
jobDetail.getJobDataMap().put("async", new AsynchronousEvent(type, parameters));
SimpleTrigger trigger = new SimpleTrigger(triggerName, null);
-
- log.trace("In the scheduleAsynchronousEvent()");
-
try
{
scheduler.scheduleJob(jobDetail, trigger);
return new QuartzTriggerHandle(triggerName);
}
- catch (SchedulerException se)
+ catch (Exception se)
{
- log.error("Cannot Schedule a Quartz Job");
- se.printStackTrace ();
- return null;
+ log.error("Cannot Schedule a Quartz Job", se);
+ throw new RuntimeException(se);
}
}
public QuartzTriggerHandle scheduleTimedEvent(String type, Schedule schedule, Object... parameters)
{
- log.trace("In the scheduleTimedEvent()");
- try
- {
- return scheduleWithQuartzService( schedule, new AsynchronousEvent(type, parameters) );
- }
- catch (SchedulerException se)
- {
- log.error("Cannot Schedule a Quartz Job");
- se.printStackTrace ();
- return null;
- }
+ return scheduleWithQuartzServiceAndWrapExceptions( schedule, new AsynchronousEvent(type, parameters) );
}
public QuartzTriggerHandle scheduleInvocation(InvocationContext invocation, Component component)
{
- log.trace("In the scheduleInvocation()");
- try
- {
- return scheduleWithQuartzService(
- createSchedule(invocation),
- new AsynchronousInvocation(invocation, component)
- );
- }
- catch (SchedulerException se) {
- log.error("Cannot Schedule a Quartz Job");
- se.printStackTrace ();
- return null;
- }
+ return scheduleWithQuartzServiceAndWrapExceptions( createSchedule(invocation), new AsynchronousInvocation(invocation, component) );
}
private static Date calculateDelayedDate (long delay)
@@ -140,10 +108,24 @@
return now;
}
- private QuartzTriggerHandle scheduleWithQuartzService(Schedule schedule, Asynchronous async) throws SchedulerException
+ private QuartzTriggerHandle scheduleWithQuartzServiceAndWrapExceptions(Schedule schedule, Asynchronous async)
+ {
+ try
+ {
+ return scheduleWithQuartzService(schedule, async);
+ }
+ catch (ParseException pe)
{
- log.trace("In the scheduleWithQuartzService()");
+ throw new RuntimeException(pe);
+ }
+ catch (SchedulerException se)
+ {
+ throw new RuntimeException(se);
+ }
+ }
+ private QuartzTriggerHandle scheduleWithQuartzService(Schedule schedule, Asynchronous async) throws SchedulerException, ParseException
+ {
String jobName = nextUniqueName();
String triggerName = nextUniqueName();
@@ -153,8 +135,6 @@
if (schedule instanceof CronSchedule)
{
CronSchedule cronSchedule = (CronSchedule) schedule;
- try
- {
CronTrigger trigger = new CronTrigger (triggerName, null);
trigger.setCronExpression(cronSchedule.getCron());
trigger.setEndTime(cronSchedule.getFinalExpiration());
@@ -169,79 +149,37 @@
}
scheduler.scheduleJob( jobDetail, trigger );
-
- }
- catch (Exception e)
- {
- log.error ("Cannot submit cron job");
- e.printStackTrace ();
- return null;
- }
- }
- else if (schedule instanceof NthBusinessDaySchedule)
- {
- NthBusinessDaySchedule nthBusinessDaySchedule = (NthBusinessDaySchedule) schedule;
- try
- {
- String calendarName = nextUniqueName();
- scheduler.addCalendar(calendarName, nthBusinessDaySchedule.getNthBusinessDay().getHolidayCalendar(), false, false);
-
- NthIncludedDayTrigger trigger = new NthIncludedDayTrigger (triggerName, null);
- trigger.setN(nthBusinessDaySchedule.getNthBusinessDay().getN());
- trigger.setFireAtTime(nthBusinessDaySchedule.getNthBusinessDay().getFireAtTime());
- trigger.setEndTime(nthBusinessDaySchedule.getFinalExpiration());
- trigger.setCalendarName(calendarName);
-
-
- switch(nthBusinessDaySchedule.getNthBusinessDay().getInterval()) {
- case WEEKLY:
- trigger.setIntervalType(NthIncludedDayTrigger.INTERVAL_TYPE_WEEKLY);
- break;
- case MONTHLY:
- trigger.setIntervalType(NthIncludedDayTrigger.INTERVAL_TYPE_MONTHLY);
- break;
- case YEARLY:
- trigger.setIntervalType(NthIncludedDayTrigger.INTERVAL_TYPE_YEARLY);
- break;
- }
-
- if ( nthBusinessDaySchedule.getExpiration()!=null )
- {
- trigger.setStartTime (nthBusinessDaySchedule.getExpiration());
}
- else if ( nthBusinessDaySchedule.getDuration()!=null )
- {
- trigger.setStartTime (calculateDelayedDate(nthBusinessDaySchedule.getDuration()));
- }
-
- scheduler.scheduleJob( jobDetail, trigger );
-
- }
- catch (Exception e)
- {
- log.error ("Cannot submit nth business day job");
- e.printStackTrace ();
- return null;
- }
- }
- else if (schedule instanceof TimerSchedule && ((TimerSchedule) schedule).getIntervalDuration() != null)
+ else if (schedule instanceof TimerSchedule)
{
TimerSchedule timerSchedule = (TimerSchedule) schedule;
+ if (timerSchedule.getIntervalDuration() != null)
+ {
if ( timerSchedule.getExpiration()!=null )
{
- SimpleTrigger trigger = new SimpleTrigger(triggerName, null, timerSchedule.getExpiration(), timerSchedule.getFinalExpiration(), SimpleTrigger.REPEAT_INDEFINITELY, timerSchedule.getIntervalDuration());
+ SimpleTrigger trigger = new SimpleTrigger(triggerName, null,
+ timerSchedule.getExpiration(),
+ timerSchedule.getFinalExpiration(),
+ SimpleTrigger.REPEAT_INDEFINITELY,
+ timerSchedule.getIntervalDuration());
scheduler.scheduleJob( jobDetail, trigger );
}
else if ( timerSchedule.getDuration()!=null )
{
- SimpleTrigger trigger = new SimpleTrigger(triggerName, null, calculateDelayedDate(timerSchedule.getDuration()), timerSchedule.getFinalExpiration(), SimpleTrigger.REPEAT_INDEFINITELY, timerSchedule.getIntervalDuration());
+ SimpleTrigger trigger = new SimpleTrigger(triggerName, null,
+ calculateDelayedDate(timerSchedule.getDuration()),
+ timerSchedule.getFinalExpiration(), SimpleTrigger.REPEAT_INDEFINITELY,
+ timerSchedule.getIntervalDuration());
scheduler.scheduleJob( jobDetail, trigger );
}
else
{
- SimpleTrigger trigger = new SimpleTrigger(triggerName, null, null, timerSchedule.getFinalExpiration(), SimpleTrigger.REPEAT_INDEFINITELY, timerSchedule.getIntervalDuration());
+ SimpleTrigger trigger = new SimpleTrigger(triggerName, null, null,
+ timerSchedule.getFinalExpiration(),
+ SimpleTrigger.REPEAT_INDEFINITELY,
+ timerSchedule.getIntervalDuration());
scheduler.scheduleJob( jobDetail, trigger );
}
@@ -256,7 +194,8 @@
}
else if ( schedule.getDuration()!=null )
{
- SimpleTrigger trigger = new SimpleTrigger (triggerName, null, calculateDelayedDate(schedule.getDuration()));
+ SimpleTrigger trigger = new SimpleTrigger (triggerName, null,
+ calculateDelayedDate(schedule.getDuration()));
scheduler.scheduleJob(jobDetail, trigger);
}
@@ -267,8 +206,13 @@
}
}
+ }
+ else
+ {
+ throw new IllegalArgumentException("unrecognized schedule type");
+ }
- return new QuartzTriggerHandle (triggerName);
+ return new QuartzTriggerHandle(triggerName);
}
private String nextUniqueName ()
@@ -277,16 +221,9 @@
}
@Destroy
- public void destroy()
+ public void destroy() throws SchedulerException
{
- log.trace("The QuartzDispatcher is shut down");
- try {
scheduler.shutdown();
- } catch (SchedulerException se) {
- log.error("Cannot shutdown the Quartz Scheduler");
- se.printStackTrace ();
- }
-
}
public static class QuartzJob implements Job
@@ -298,11 +235,9 @@
public void execute(JobExecutionContext context)
throws JobExecutionException
{
- log.trace("Start executing Quartz job" );
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
async = (Asynchronous)dataMap.get("async");
async.execute(null);
- log.trace("End executing Quartz job" );
}
}
More information about the jboss-cvs-commits
mailing list