[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Michael Yuan michael.yuan at jboss.com
Tue Jun 5 13:02:43 EDT 2007


  User: myuan   
  Date: 07/06/05 13:02:43

  Modified:    src/main/org/jboss/seam/core        AbstractDispatcher.java
                        QuartzDispatcher.java ThreadPoolDispatcher.java
                        TimerSchedule.java TimerServiceDispatcher.java
  Added:       src/main/org/jboss/seam/core        CronSchedule.java
                        Schedule.java
  Log:
  Cron support in Quartz
  
  Revision  Changes    Path
  1.6       +13 -4     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.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- AbstractDispatcher.java	5 Jun 2007 01:06:05 -0000	1.5
  +++ AbstractDispatcher.java	5 Jun 2007 17:02:43 -0000	1.6
  @@ -148,7 +148,7 @@
         
      }
   
  -   protected TimerSchedule createSchedule(InvocationContext invocation)
  +   protected Schedule createSchedule(InvocationContext invocation)
      {
         Long duration = null;
         Date expiration = null;
  @@ -180,11 +180,20 @@
            }
         }
         
  -      if (cron == null) {
  -        return new TimerSchedule(duration, expiration, intervalDuration);
  +      if (cron != null && (!cron.trim().equals(""))) 
  +      {
  +        return new CronSchedule(duration, expiration, cron.trim());
         } else {
  -        return new TimerSchedule(duration, expiration, cron);
  +        return new TimerSchedule(duration, expiration, intervalDuration);
  +      }
  +
  +      /*
  +      } else if (intervalDuration != null) {
  +        return new TimerSchedule(duration, expiration, intervalDuration);
  +      } else if (expiration != null || duration != null) {
  +        return new Schedule (duration, expiration);
         }
  +      */
      }
      
   }
  
  
  
  1.3       +38 -36    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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- QuartzDispatcher.java	5 Jun 2007 01:06:05 -0000	1.2
  +++ QuartzDispatcher.java	5 Jun 2007 17:02:43 -0000	1.3
  @@ -42,7 +42,7 @@
   @Name("org.jboss.seam.core.dispatcher")
   @Interceptors(SeamInterceptor.class)
   @Install(value=false, precedence=BUILT_IN)
  -public class QuartzDispatcher extends AbstractDispatcher<QuartzDispatcher.QuartzTriggerHandle, TimerSchedule>
  +public class QuartzDispatcher extends AbstractDispatcher<QuartzDispatcher.QuartzTriggerHandle, Schedule>
   {
      
      private static final LogProvider log = Logging.getLogProvider(QuartzDispatcher.class);
  @@ -84,7 +84,7 @@
         }
      }
       
  -   public QuartzTriggerHandle scheduleTimedEvent(String type, TimerSchedule schedule, Object... parameters)
  +   public QuartzTriggerHandle scheduleTimedEvent(String type, Schedule schedule, Object... parameters)
      {
         log.info("In the scheduleTimedEvent()");
         try {
  @@ -118,7 +118,7 @@
        return now;
      }
   
  -   private QuartzTriggerHandle scheduleWithQuartzService(TimerSchedule schedule, Asynchronous async) throws SchedulerException
  +   private QuartzTriggerHandle scheduleWithQuartzService(Schedule schedule, Asynchronous async) throws SchedulerException
      {
         log.info("In the scheduleWithQuartzService()");
         
  @@ -128,54 +128,54 @@
         JobDetail jobDetail = new JobDetail(jobName, null, QuartzJob.class);
         jobDetail.getJobDataMap().put("async", async);
   
  -      if ( schedule.getCron()!=null )
  +      if (schedule instanceof CronSchedule) 
         {
  +        CronSchedule cronSchedule = (CronSchedule) schedule; 
           try {
             CronTrigger trigger = new CronTrigger (triggerName, null);
  -          trigger.setCronExpression(schedule.getCron());
  -          if ( schedule.getExpiration()!=null )
  +          trigger.setCronExpression(cronSchedule.getCron());
  +          if ( cronSchedule.getExpiration()!=null )
             {
  -            trigger.setStartTime (schedule.getExpiration());
  +            trigger.setStartTime (cronSchedule.getExpiration());
             }
  -          else if ( schedule.getDuration()!=null )
  +          else if ( cronSchedule.getDuration()!=null )
             {
  -            trigger.setStartTime (calculateDelayedDate(schedule.getDuration()));
  +            trigger.setStartTime (calculateDelayedDate(cronSchedule.getDuration()));
             }
   
             scheduler.scheduleJob( jobDetail, trigger );
   
  -          return new QuartzTriggerHandle (triggerName);
  -
           } catch (Exception e) {
  -          log.error ("Cannot submit cron job, fall back to fixed interval");
  +          log.error ("Cannot submit cron job");
             e.printStackTrace ();
  -
  -          // The method does not return, and execution flow follows
  +          return null;
           }
         }
  -
  -      if ( schedule.getIntervalDuration()!=null )
  +      else if (schedule instanceof TimerSchedule && ((TimerSchedule) schedule).getIntervalDuration() != null) 
         {
  -         if ( schedule.getExpiration()!=null )
  +         TimerSchedule timerSchedule = (TimerSchedule) schedule;
  +         if ( timerSchedule.getExpiration()!=null )
            {
  -            SimpleTrigger trigger = new SimpleTrigger (triggerName, null, schedule.getExpiration(), null, SimpleTrigger.REPEAT_INDEFINITELY, schedule.getIntervalDuration());
  +            SimpleTrigger trigger = new SimpleTrigger (triggerName, null, timerSchedule.getExpiration(), null, SimpleTrigger.REPEAT_INDEFINITELY, timerSchedule.getIntervalDuration());
               scheduler.scheduleJob( jobDetail, trigger );
   
            }
  -         else if ( schedule.getDuration()!=null )
  +         else if ( timerSchedule.getDuration()!=null )
            {
  -             SimpleTrigger trigger = new SimpleTrigger (triggerName, null, calculateDelayedDate(schedule.getDuration()), null, SimpleTrigger.REPEAT_INDEFINITELY, schedule.getIntervalDuration());
  +             SimpleTrigger trigger = new SimpleTrigger (triggerName, null, calculateDelayedDate(timerSchedule.getDuration()), null, SimpleTrigger.REPEAT_INDEFINITELY, timerSchedule.getIntervalDuration());
                scheduler.scheduleJob( jobDetail, trigger );
   
            }
            else
            {
  -            SimpleTrigger trigger = new SimpleTrigger (triggerName, null, SimpleTrigger.REPEAT_INDEFINITELY, schedule.getIntervalDuration());
  +            SimpleTrigger trigger = new SimpleTrigger (triggerName, null, SimpleTrigger.REPEAT_INDEFINITELY, timerSchedule.getIntervalDuration());
               scheduler.scheduleJob( jobDetail, trigger );
   
            }
         }
  -      else if ( schedule.getExpiration()!=null )
  +      else 
  +      {
  +        if ( schedule.getExpiration()!=null )
         {
             SimpleTrigger trigger = new SimpleTrigger (triggerName, null, schedule.getExpiration());
             scheduler.scheduleJob( jobDetail, trigger );
  @@ -193,6 +193,8 @@
            scheduler.scheduleJob( jobDetail, trigger );
   
         }
  +      }
  +
         return new QuartzTriggerHandle (triggerName);
      }
      
  
  
  
  1.4       +1 -1      jboss-seam/src/main/org/jboss/seam/core/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/core/ThreadPoolDispatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- ThreadPoolDispatcher.java	31 May 2007 21:05:28 -0000	1.3
  +++ ThreadPoolDispatcher.java	5 Jun 2007 17:02:43 -0000	1.4
  @@ -49,7 +49,7 @@
      public Future scheduleInvocation(InvocationContext invocation, Component component)
      {
         return scheduleWithExecutorService( 
  -               createSchedule(invocation), 
  +               (TimerSchedule) createSchedule(invocation), 
                  new RunnableAsynchronous( new AsynchronousInvocation(invocation, component) ) 
               );
      }
  
  
  
  1.3       +1 -50     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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- TimerSchedule.java	5 Jun 2007 01:06:05 -0000	1.2
  +++ TimerSchedule.java	5 Jun 2007 17:02:43 -0000	1.3
  @@ -1,9 +1,5 @@
  -/**
  - * 
  - */
   package org.jboss.seam.core;
   
  -import java.io.Serializable;
   import java.util.Date;
   
   /**
  @@ -15,33 +11,15 @@
    * @author Gavin King
    *
    */
  -public class TimerSchedule implements Serializable
  +public class TimerSchedule extends Schedule
   {
  -   private Long duration;
  -   private Date expiration;
      private Long intervalDuration;
  -   private String cron;
  -   
  -   Long getDuration()
  -   {
  -      return duration;
  -   }
  -   
  -   Date getExpiration()
  -   {
  -      return expiration;
  -   }
      
      Long getIntervalDuration()
      {
         return intervalDuration;
      }
      
  -   String getCron()
  -   {
  -      return cron;
  -   }
  -   
      /**
       * @param duration the delay before the event occurs
       */
  @@ -69,16 +47,6 @@
      }
   
      /**
  -    * @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
       */
  @@ -88,16 +56,6 @@
         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;
  @@ -105,13 +63,6 @@
         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();
  
  
  
  1.4       +1 -1      jboss-seam/src/main/org/jboss/seam/core/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/core/TimerServiceDispatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- TimerServiceDispatcher.java	31 May 2007 21:05:28 -0000	1.3
  +++ TimerServiceDispatcher.java	5 Jun 2007 17:02:43 -0000	1.4
  @@ -62,7 +62,7 @@
      
      public Timer scheduleInvocation(InvocationContext invocation, Component component)
      {
  -      return new TimerProxy( scheduleWithTimerService( createSchedule(invocation), new AsynchronousInvocation(invocation, component) ) );
  +      return new TimerProxy( scheduleWithTimerService( (TimerSchedule) createSchedule(invocation), new AsynchronousInvocation(invocation, component) ) );
         
      }
   
  
  
  
  1.1      date: 2007/06/05 17:02:43;  author: myuan;  state: Exp;jboss-seam/src/main/org/jboss/seam/core/CronSchedule.java
  
  Index: CronSchedule.java
  ===================================================================
  package org.jboss.seam.core;
  
  import java.util.Date;
  
  /**
   * A "cron schedule" for a timed event executed by
   * the Quartz CronTrigger.
   * 
   * @author Michael Yuan
   *
   */
  public class CronSchedule extends Schedule
  {
     private String cron;
     
     String getCron()
     {
        return cron;
     }
     
     /**
      * @param duration the delay before the first event occurs
      * @param cron the unix cron string to control how the events are repeated
      */
     public CronSchedule(Long duration, String cron)
     {
        this.duration = duration;
        this.cron = cron;
     }
  
     /**
      * @param expiration the datetime at which the first event occurs
      * @param cron the unix cron string to control how the events are repeated
      */
     public CronSchedule(Date expiration, String cron)
     {
        this.expiration = expiration;
        this.cron = cron;
     }
  
     CronSchedule(Long duration, Date expiration, String cron)
     {
        this.duration = duration;
        this.expiration = expiration;
        this.cron = cron;
     }
  
     CronSchedule() {}
     
  }
  
  
  
  1.1      date: 2007/06/05 17:02:43;  author: myuan;  state: Exp;jboss-seam/src/main/org/jboss/seam/core/Schedule.java
  
  Index: Schedule.java
  ===================================================================
  package org.jboss.seam.core;
  
  import java.io.Serializable;
  import java.util.Date;
  
  /**
   * A "schedule" for a timed event executed by
   * a timer service which supports delayed
   * timed events. It is the base class for the more
   * useful TimerSchedule and CronSchedule classes.
   * 
   * @author Michael Yuan
   *
   */
  public class Schedule implements Serializable
  {
     Long duration;
     Date expiration;
     
     Long getDuration()
     {
        return duration;
     }
     
     Date getExpiration()
     {
        return expiration;
     }
     
     /**
      * @param duration the delay before the event occurs
      * @param expriation the datetime at which the event occurs
      */
     public Schedule(Long duration, Date expiration)
     {
        this.duration = duration;
        this.expiration = expiration;
     }
  
     public Schedule () { }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list