You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by un...@apache.org on 2004/03/08 14:43:42 UTC

cvs commit: cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron QuartzJobScheduler.java JobScheduler.java

unico       2004/03/08 05:43:42

  Modified:    src/blocks/cron/java/org/apache/cocoon/components/cron
                        QuartzJobScheduler.java JobScheduler.java
  Log:
  add method to schedule a periodic job directly
  
  Revision  Changes    Path
  1.10      +33 -2     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- QuartzJobScheduler.java	5 Mar 2004 13:01:49 -0000	1.9
  +++ QuartzJobScheduler.java	8 Mar 2004 13:43:42 -0000	1.10
  @@ -224,6 +224,36 @@
   
           addJob(name, jobDataMap, timeEntry, canRunConcurrently, params, objects);
       }
  +    
  +    /**
  +     * Schedule a periodic job. The job is started the first time when the period has passed.  Note that if a job with
  +     * the same name has already beed added it is overwritten.
  +     *
  +     * @param name the name of the job
  +     * @param job The job object itself. It must implement either CronJob, Runnable or might also be an implementation
  +     *        specific class (i.e. org.quartz.Job)
  +     * @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 setup CronJob
  +     * @param objects A Map with additional object to setup CronJob
  +     */
  +    public void addPeriodicJob(String name, Object job, long period, boolean canRunConcurrently, Parameters params,
  +                               Map objects)
  +    throws CascadingException {
  +        if (!(job instanceof CronJob) && !(job instanceof Runnable) && !(job instanceof Job)) {
  +            throw new CascadingException("Job object is neither an instance of " + CronJob.class.getName() + "," +
  +                                         Runnable.class.getName() + " nor " + Job.class.getName());
  +        }
  +        final JobDataMap jobDataMap = new JobDataMap();
  +        jobDataMap.put(DATA_MAP_OBJECT, job);
  +        
  +        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)
  @@ -743,5 +773,6 @@
               }
           }
       }
  +
   
   }
  
  
  
  1.7       +17 -1     cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron/JobScheduler.java
  
  Index: JobScheduler.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron/JobScheduler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JobScheduler.java	5 Mar 2004 13:01:49 -0000	1.6
  +++ JobScheduler.java	8 Mar 2004 13:43:42 -0000	1.7
  @@ -113,6 +113,22 @@
       void addPeriodicJob(String name, String jobrole, long period, boolean canRunConcurrently, Parameters params,
                           Map objects)
       throws CascadingException;
  +    
  +    /**
  +     * Schedule a periodic job. The job is started the first time when the period has passed.  Note that if a job with
  +     * the same name has already beed added it is overwritten.
  +     *
  +     * @param name the name of the job
  +     * @param job The job object itself. It must implement either CronJob, Runnable or might also be an implementation
  +     *        specific class (i.e. org.quartz.Job)
  +     * @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 setup CronJob
  +     * @param objects A Map with additional object to setup CronJob
  +     */
  +    void addPeriodicJob(String name, Object job, long period, boolean canRunConcurrently, Parameters params,
  +                        Map objects)
  +    throws CascadingException;
   
       /**
        * Fire a job once immediately