Search in sources :

Example 11 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 12 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 13 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)

Example 14 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project jforum2 by rafaelsteil.

the class POPJobStarter method startJob.

public static void startJob() throws SchedulerException {
    boolean isEnabled = SystemGlobals.getBoolValue(ConfigKeys.MAIL_POP3_INTEGRATION_ENABLED);
    if (!isStarted && isEnabled) {
        String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
        String cronExpression = SystemGlobals.getValue("org.quartz.context.mailintegration.cron.expression");
        scheduler = new StdSchedulerFactory(filename).getScheduler();
        Trigger trigger = null;
        try {
            trigger = new CronTrigger(POPListener.class.getName(), "pop3Integration", cronExpression);
            logger.info("Starting POP3 integration expression " + cronExpression);
            scheduler.scheduleJob(new JobDetail(POPListener.class.getName(), "pop3Integration", POPListener.class), trigger);
            scheduler.start();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    isStarted = true;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) ParseException(java.text.ParseException)

Example 15 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project jforum2 by rafaelsteil.

the class SummaryScheduler method startJob.

/**
	 * Starts the summary Job. Conditions to start: Is not started yet and is enabled on the file
	 * SystemGlobasl.properties. The to enable it is "summary.enabled"
	 * (ConfigKeys.SUMMARY_IS_ENABLED).
	 * 
	 * @throws SchedulerException
	 * @throws IOException
	 */
public static void startJob() throws SchedulerException {
    boolean isEnabled = SystemGlobals.getBoolValue(ConfigKeys.SUMMARY_IS_ENABLED);
    if (!isStarted && isEnabled) {
        String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
        String cronExpression = SystemGlobals.getValue("org.quartz.context.summary.cron.expression");
        scheduler = new StdSchedulerFactory(filename).getScheduler();
        Trigger trigger = null;
        try {
            trigger = new CronTrigger(SummaryJob.class.getName(), "summaryJob", cronExpression);
            logger.info("Starting quartz summary expression " + cronExpression);
            scheduler.scheduleJob(new JobDetail(SummaryJob.class.getName(), "summaryJob", SummaryJob.class), trigger);
            scheduler.start();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    isStarted = true;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) ParseException(java.text.ParseException)

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