Search in sources :

Example 6 with SchedulerFactory

use of org.quartz.SchedulerFactory 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 7 with SchedulerFactory

use of org.quartz.SchedulerFactory 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 8 with SchedulerFactory

use of org.quartz.SchedulerFactory 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)

Example 9 with SchedulerFactory

use of org.quartz.SchedulerFactory in project spring-framework by spring-projects.

the class SchedulerFactoryBean method afterPropertiesSet.

//---------------------------------------------------------------------
// Implementation of InitializingBean interface
//---------------------------------------------------------------------
@Override
public void afterPropertiesSet() throws Exception {
    if (this.dataSource == null && this.nonTransactionalDataSource != null) {
        this.dataSource = this.nonTransactionalDataSource;
    }
    if (this.applicationContext != null && this.resourceLoader == null) {
        this.resourceLoader = this.applicationContext;
    }
    // Create SchedulerFactory instance...
    SchedulerFactory schedulerFactory = BeanUtils.instantiateClass(this.schedulerFactoryClass);
    initSchedulerFactory(schedulerFactory);
    if (this.resourceLoader != null) {
        // Make given ResourceLoader available for SchedulerFactory configuration.
        configTimeResourceLoaderHolder.set(this.resourceLoader);
    }
    if (this.taskExecutor != null) {
        // Make given TaskExecutor available for SchedulerFactory configuration.
        configTimeTaskExecutorHolder.set(this.taskExecutor);
    }
    if (this.dataSource != null) {
        // Make given DataSource available for SchedulerFactory configuration.
        configTimeDataSourceHolder.set(this.dataSource);
    }
    if (this.nonTransactionalDataSource != null) {
        // Make given non-transactional DataSource available for SchedulerFactory configuration.
        configTimeNonTransactionalDataSourceHolder.set(this.nonTransactionalDataSource);
    }
    // Get Scheduler instance from SchedulerFactory.
    try {
        this.scheduler = createScheduler(schedulerFactory, this.schedulerName);
        populateSchedulerContext();
        if (!this.jobFactorySet && !(this.scheduler instanceof RemoteScheduler)) {
            // Use AdaptableJobFactory as default for a local Scheduler, unless when
            // explicitly given a null value through the "jobFactory" bean property.
            this.jobFactory = new AdaptableJobFactory();
        }
        if (this.jobFactory != null) {
            if (this.jobFactory instanceof SchedulerContextAware) {
                ((SchedulerContextAware) this.jobFactory).setSchedulerContext(this.scheduler.getContext());
            }
            this.scheduler.setJobFactory(this.jobFactory);
        }
    } finally {
        if (this.resourceLoader != null) {
            configTimeResourceLoaderHolder.remove();
        }
        if (this.taskExecutor != null) {
            configTimeTaskExecutorHolder.remove();
        }
        if (this.dataSource != null) {
            configTimeDataSourceHolder.remove();
        }
        if (this.nonTransactionalDataSource != null) {
            configTimeNonTransactionalDataSourceHolder.remove();
        }
    }
    registerListeners();
    registerJobsAndTriggers();
}
Also used : RemoteScheduler(org.quartz.impl.RemoteScheduler) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Aggregations

SchedulerFactory (org.quartz.SchedulerFactory)9 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)8 SchedulerException (org.quartz.SchedulerException)4 InputStream (java.io.InputStream)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 Scheduler (org.quartz.Scheduler)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)1 ResourceBundle (java.util.ResourceBundle)1 JobExecutionException (org.quartz.JobExecutionException)1 SchedulerContext (org.quartz.SchedulerContext)1 RemoteScheduler (org.quartz.impl.RemoteScheduler)1 SimpleThreadPool (org.quartz.simpl.SimpleThreadPool)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 TestBean (org.springframework.tests.sample.beans.TestBean)1