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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations