Exemplo n.º 1
0
  /**
   * Schedule a job with a unix-like cron expression.
   *
   * @param job the job to schedule
   * @param cronExpression the cron expression to use. For a complete tutorial about cron
   *     expressions, please refer to <a
   *     href="http://quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger">quartz
   *     reference documentation</a>.
   */
  public void scheduleCron(final org.easybatch.core.job.Job job, final String cronExpression)
      throws JobSchedulerException {
    checkNotNull(job, "job");
    checkNotNull(cronExpression, "cronExpression");

    String executionId = job.getExecutionId();
    String jobName = JOB_NAME_PREFIX + executionId;
    String triggerName = TRIGGER_NAME_PREFIX + executionId;

    Trigger trigger =
        newTrigger()
            .withIdentity(triggerName)
            .withSchedule(cronSchedule(cronExpression))
            .forJob(jobName)
            .build();

    JobDetail jobDetail = getJobDetail(job, jobName);

    try {
      LOGGER.log(
          Level.INFO,
          "Scheduling job {0} with cron expression {1}",
          new Object[] {job, cronExpression});
      scheduler.scheduleJob(jobDetail, trigger);
    } catch (SchedulerException e) {
      throw new JobSchedulerException("Unable to schedule job " + job, e);
    }
  }
Exemplo n.º 2
0
  /**
   * Schedule a job to start at a fixed point of time and repeat with interval period.
   *
   * @param job the job to schedule
   * @param startTime the start time
   * @param interval the repeat interval in seconds
   */
  public void scheduleAtWithInterval(
      final org.easybatch.core.job.Job job, final Date startTime, final int interval)
      throws JobSchedulerException {
    checkNotNull(job, "job");
    checkNotNull(startTime, "startTime");

    String executionId = job.getExecutionId();
    String jobName = JOB_NAME_PREFIX + executionId;
    String triggerName = TRIGGER_NAME_PREFIX + executionId;

    ScheduleBuilder scheduleBuilder =
        simpleSchedule().withIntervalInSeconds(interval).repeatForever();

    Trigger trigger =
        newTrigger()
            .withIdentity(triggerName)
            .startAt(startTime)
            .withSchedule(scheduleBuilder)
            .forJob(jobName)
            .build();

    JobDetail jobDetail = getJobDetail(job, jobName);

    try {
      LOGGER.log(
          Level.INFO,
          "Scheduling job {0} to start at {1} and every {2} second(s)",
          new Object[] {job, startTime, interval});
      scheduler.scheduleJob(jobDetail, trigger);
    } catch (SchedulerException e) {
      throw new JobSchedulerException("Unable to schedule job " + job, e);
    }
  }
Exemplo n.º 3
0
 /**
  * Check if the given job is scheduled.
  *
  * @param job the job to check
  * @return true if the job is scheduled, false else
  * @throws JobSchedulerException thrown if an exception occurs while checking if the job is
  *     scheduled
  */
 public boolean isScheduled(final org.easybatch.core.job.Job job) throws JobSchedulerException {
   try {
     return scheduler.checkExists(
         TriggerKey.triggerKey(TRIGGER_NAME_PREFIX + job.getExecutionId()));
   } catch (SchedulerException e) {
     throw new JobSchedulerException("Unable to check if the job " + job + " is scheduled", e);
   }
 }
Exemplo n.º 4
0
 /**
  * Unschedule the given job.
  *
  * @param job the job to unschedule
  * @throws JobSchedulerException thrown if an exception occurs during job unscheduling
  */
 public void unschedule(final org.easybatch.core.job.Job job) throws JobSchedulerException {
   LOGGER.log(Level.INFO, "Unscheduling job {0} ", job);
   try {
     scheduler.unscheduleJob(TriggerKey.triggerKey(TRIGGER_NAME_PREFIX + job.getExecutionId()));
   } catch (SchedulerException e) {
     throw new JobSchedulerException("Unable to unschedule job " + job, e);
   }
 }
Exemplo n.º 5
0
  /**
   * Schedule a job to start at a fixed point of time.
   *
   * @param job the job to schedule
   * @param startTime the start time
   */
  public void scheduleAt(final org.easybatch.core.job.Job job, final Date startTime)
      throws JobSchedulerException {
    checkNotNull(job, "job");
    checkNotNull(startTime, "startTime");

    String executionId = job.getExecutionId();
    String jobName = JOB_NAME_PREFIX + executionId;
    String triggerName = TRIGGER_NAME_PREFIX + executionId;

    Trigger trigger =
        newTrigger().withIdentity(triggerName).startAt(startTime).forJob(jobName).build();

    JobDetail jobDetail = getJobDetail(job, jobName);

    try {
      LOGGER.log(Level.INFO, "Scheduling job {0} to start at {1}", new Object[] {job, startTime});
      scheduler.scheduleJob(jobDetail, trigger);
    } catch (SchedulerException e) {
      throw new JobSchedulerException("Unable to schedule job " + job, e);
    }
  }