Search in sources :

Example 6 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project elastic-job by dangdangdotcom.

the class DaemonTaskScheduler method initializeScheduler.

private Scheduler initializeScheduler() throws SchedulerException {
    StdSchedulerFactory factory = new StdSchedulerFactory();
    factory.initialize(getBaseQuartzProperties());
    return factory.getScheduler();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 7 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project elastic-job by dangdangdotcom.

the class JobScheduler method createScheduler.

private Scheduler createScheduler(final boolean isMisfire) {
    Scheduler result;
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(getBaseQuartzProperties(isMisfire));
        result = factory.getScheduler();
        result.getListenerManager().addTriggerListener(jobExecutor.getSchedulerFacade().newJobTriggerListener());
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
    return result;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Example 8 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project camel by apache.

the class QuartzComponent method createSchedulerFactory.

protected SchedulerFactory createSchedulerFactory() throws SchedulerException {
    SchedulerFactory answer;
    Properties prop = loadProperties();
    if (prop != null) {
        // force disabling update checker (will do online check over the internet)
        prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
        // camel context name will be a suffix to use one scheduler per context
        String instName = createInstanceName(prop);
        prop.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instName);
        // enable jmx unless configured to not do so
        if (enableJmx && !prop.containsKey("org.quartz.scheduler.jmx.export")) {
            LOG.info("Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX.");
            prop.put("org.quartz.scheduler.jmx.export", "true");
        }
        answer = new StdSchedulerFactory(prop);
    } else {
        // read default props to be able to use a single scheduler per camel context
        // if we need more than one scheduler per context use setScheduler(Scheduler) 
        // or setFactory(SchedulerFactory) methods
        // must use classloader from StdSchedulerFactory to work even in OSGi
        InputStream is = StdSchedulerFactory.class.getClassLoader().getResourceAsStream("org/quartz/quartz.properties");
        if (is == null) {
            throw new SchedulerException("Quartz properties file not found in classpath: org/quartz/quartz.properties");
        }
        prop = new Properties();
        try {
            prop.load(is);
        } catch (IOException e) {
            throw new SchedulerException("Error loading Quartz properties file from classpath: org/quartz/quartz.properties", e);
        } finally {
            IOHelper.close(is);
        }
        // camel context name will be a suffix to use one scheduler per context
        String instName = createInstanceName(prop);
        prop.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instName);
        // force disabling update checker (will do online check over the internet)
        prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
        // enable jmx unless configured to not do so
        if (enableJmx && !prop.containsKey("org.quartz.scheduler.jmx.export")) {
            prop.put("org.quartz.scheduler.jmx.export", "true");
            LOG.info("Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX.");
        }
        answer = new StdSchedulerFactory(prop);
    }
    if (LOG.isDebugEnabled()) {
        String name = prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
        LOG.debug("Creating SchedulerFactory: {} with properties: {}", name, prop);
    }
    return answer;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) InputStream(java.io.InputStream) IOException(java.io.IOException) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 9 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project camel by apache.

the class QuartzComponentTest method testQuartzComponentCustomScheduler.

@Test
public void testQuartzComponentCustomScheduler() throws Exception {
    QuartzComponent comp = new QuartzComponent();
    comp.setCamelContext(context);
    SchedulerFactory fac = new StdSchedulerFactory();
    comp.setFactory(fac);
    assertSame(fac, comp.getFactory());
    Scheduler sch = fac.getScheduler();
    comp.setScheduler(sch);
    assertSame(sch, comp.getScheduler());
    comp.start();
    comp.stop();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Scheduler(org.quartz.Scheduler) SchedulerFactory(org.quartz.SchedulerFactory) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Test(org.junit.Test)

Example 10 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project camel by apache.

the class QuartzComponentTest method testQuartzComponentCustomScheduler.

@Test
public void testQuartzComponentCustomScheduler() throws Exception {
    QuartzComponent comp = new QuartzComponent();
    comp.setCamelContext(context);
    SchedulerFactory fac = new StdSchedulerFactory();
    comp.setSchedulerFactory(fac);
    assertSame(fac, comp.getSchedulerFactory());
    Scheduler sch = fac.getScheduler();
    comp.setScheduler(sch);
    assertSame(sch, comp.getScheduler());
    comp.start();
    comp.stop();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Scheduler(org.quartz.Scheduler) SchedulerFactory(org.quartz.SchedulerFactory) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Test(org.junit.Test)

Aggregations

StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)16 SchedulerFactory (org.quartz.SchedulerFactory)7 SchedulerException (org.quartz.SchedulerException)6 Properties (java.util.Properties)5 InputStream (java.io.InputStream)4 Scheduler (org.quartz.Scheduler)4 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 Test (org.junit.Test)2 CronTrigger (org.quartz.CronTrigger)2 JobDetail (org.quartz.JobDetail)2 Trigger (org.quartz.Trigger)2 SimpleThreadPool (org.quartz.simpl.SimpleThreadPool)2 JobSystemException (com.dangdang.ddframe.job.exception.JobSystemException)1 TaskManagerConfiguration (com.evolveum.midpoint.task.quartzimpl.TaskManagerConfiguration)1 Inject (com.google.inject.Inject)1 Provides (com.google.inject.Provides)1 FileInputStream (java.io.FileInputStream)1 ResourceBundle (java.util.ResourceBundle)1 JobExecutionException (org.quartz.JobExecutionException)1