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