Package org.quartz

Examples of org.quartz.Scheduler


        trigger.setName(endpoint.getEndpointURI().toString() + "-" + event.getId());
        trigger.setGroup(groupName);
        trigger.setJobName(jobDetail.getName());
        trigger.setJobGroup(jobGroupName);

        Scheduler scheduler = ((QuartzConnector) this.getConnector()).getQuartzScheduler();

        // Minimize the the time window capturing the start time and scheduling the job.
        long start = System.currentTimeMillis();
        if (startDelay != null)
        {
            start += Long.parseLong(startDelay);
        }
        trigger.setStartTime(new Date(start));

        scheduler.scheduleJob(jobDetail, trigger);
    }
View Full Code Here


    }
  }
 
  public void schedulerShutDown() {

    Scheduler sched = null;
    try {
      sched = StdSchedulerFactory.getDefaultScheduler();
      sched.shutdown();
    } catch (SchedulerException e1) {

      e1.printStackTrace();
    }
  }
View Full Code Here

  }
 
  public void schedulerRestart() {

    StdSchedulerFactory ssf = null;
    Scheduler sched = null;
   
      try {
        ssf = new StdSchedulerFactory();
      sched = ssf.getScheduler();
      sched.start();
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
   
    try {
      JobDetail jd = new JobDetail("waitJob", "groupJob", WaitJob.class);
      CronTrigger cronTrigger = new CronTrigger("waitTrigger", "groupTrigger");
      cronTrigger.setCronExpression("0 * * * * ?");
     
      sched.scheduleJob(jd, cronTrigger);
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
View Full Code Here

public class SchedulerUtil {
 
  public static Calendar getCalendarByCronExpression(String cronExpression) throws Exception {
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();
   
    JobDetail jd = sched.getJobDetail("tempJobDetail", "tempGroupJobDetail");
    if (jd != null) {
      sched.unscheduleJob("tempJobDetail", "tempGroupJobDetail");
      sched.deleteJob("tempJobDetail" , "tempGroupJobDetail");
    }
   
    CronTrigger cronTrigger = new CronTrigger("tempCronTrigger", "tempGroupTrigger");
    cronTrigger.setCronExpression(cronExpression);
   
    Date firstRunTime = (Date) sched.scheduleJob(new JobDetail("tempJobDetail", "tempGroupJobDetail", TempJob.class), cronTrigger);
    Calendar c = new GregorianCalendar();
    c.setTime(firstRunTime);
    c.set(Calendar.MILLISECOND, 0);
   
    sched.unscheduleJob("tempJobDetail", "tempGroupJobDetail");
    sched.deleteJob("tempJobDetail" , "tempGroupJobDetail");
   
    return c;
  }
View Full Code Here

    props.setProperty(PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getCanonicalName());
    props.setProperty(PROP_THREAD_POOL_PREFIX + ".threadCount", NUM_THREADS.get().toString());
    props.setProperty(PROP_THREAD_POOL_PREFIX + ".makeThreadsDaemons", Boolean.TRUE.toString());

    props.setProperty(PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON, Boolean.TRUE.toString());
    Scheduler scheduler = new StdSchedulerFactory(props).getScheduler();
    scheduler.setJobFactory(jobFactory);
    return scheduler;
  }
View Full Code Here

  @Test
  public void testCronSchedulerLifecycle() throws Exception {
    control.replay();

    Scheduler scheduler = injector.getInstance(Scheduler.class);
    assertTrue(!scheduler.isStarted());

    boot();
    Service cronLifecycle = injector.getInstance(CronLifecycle.class);

    assertTrue(cronLifecycle.isRunning());
    assertTrue(scheduler.isStarted());

    shutdown.getValue().execute();

    assertTrue(!cronLifecycle.isRunning());
    assertTrue(scheduler.isShutdown());
  }
View Full Code Here

  public void testJobsAreScheduled() throws Exception {
    auroraCronJob.execute(isA(JobExecutionContext.class));

    control.replay();
    final CronJobManager cronJobManager = injector.getInstance(CronJobManager.class);
    final Scheduler scheduler = injector.getInstance(Scheduler.class);

    storage.write(new Storage.MutateWork.NoResult.Quiet() {
      @Override
      public void execute(Storage.MutableStoreProvider storeProvider) {
        storeProvider.getJobStore().saveAcceptedJob(
            cronJobManager.getManagerKey(),
            CRON_JOB);
      }
    });

    final CountDownLatch cronRan = new CountDownLatch(1);
    scheduler.getListenerManager().addTriggerListener(new CountDownWhenComplete(cronRan));
    boot();

    cronRan.await();

    shutdown.getValue().execute();
View Full Code Here

                    sessionValidationInterval);

            JobDetail detail = new JobDetail(JOB_NAME, Scheduler.DEFAULT_GROUP, QuartzSessionValidationJob.class);
            detail.getJobDataMap().put(QuartzSessionValidationJob.SESSION_MANAGER_KEY, sessionManager);

            Scheduler scheduler = getScheduler();

            scheduler.scheduleJob(detail, trigger);
            if (schedulerImplicitlyCreated) {
                scheduler.start();
                if (log.isDebugEnabled()) {
                    log.debug("Successfully started implicitly created Quartz Scheduler instance.");
                }
            }
            this.enabled = true;
View Full Code Here

    public void disableSessionValidation() {
        if (log.isDebugEnabled()) {
            log.debug("Stopping Quartz session validation job...");
        }

        Scheduler scheduler;
        try {
            scheduler = getScheduler();
            if (scheduler == null) {
                if (log.isWarnEnabled()) {
                    log.warn("getScheduler() method returned a null Quartz scheduler, which is unexpected.  Please " +
                            "check your configuration and/or implementation.  Returning quietly since there is no " +
                            "validation job to remove (scheduler does not exist).");
                }
                return;
            }
        } catch (SchedulerException e) {
            if (log.isWarnEnabled()) {
                log.warn("Unable to acquire Quartz Scheduler.  Ignoring and returning (already stopped?)", e);
            }
            return;
        }

        try {
            scheduler.unscheduleJob(JOB_NAME, Scheduler.DEFAULT_GROUP);
            if (log.isDebugEnabled()) {
                log.debug("Quartz session validation job stopped successfully.");
            }
        } catch (SchedulerException e) {
            if (log.isDebugEnabled()) {
                log.debug("Could not cleanly remove SessionValidationJob from Quartz scheduler.  " +
                        "Ignoring and stopping.", e);
            }
        }

        this.enabled = false;

        if (schedulerImplicitlyCreated) {
            try {
                scheduler.shutdown();
            } catch (SchedulerException e) {
                if (log.isWarnEnabled()) {
                    log.warn("Unable to cleanly shutdown implicitly created Quartz Scheduler instance.", e);
                }
            } finally {
View Full Code Here

    protected SchedulerFactory createSchedulerFactory() {
        return new StdSchedulerFactory();
    }

    protected Scheduler createScheduler() throws SchedulerException {
        Scheduler scheduler = getFactory().getScheduler();
        scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT, getCamelContext());
        return scheduler;
    }
View Full Code Here

TOP

Related Classes of org.quartz.Scheduler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.