use of org.quartz.impl.StdSchedulerFactory in project jmxtrans by jmxtrans.
the class JmxTransModule method scheduler.
@Provides
@Inject
Scheduler scheduler(JmxTransConfiguration configuration, GuiceJobFactory jobFactory) throws SchedulerException, IOException {
StdSchedulerFactory serverSchedFact = new StdSchedulerFactory();
try (InputStream stream = openQuartzConfiguration(configuration)) {
serverSchedFact.initialize(stream);
}
Scheduler scheduler = serverSchedFact.getScheduler();
scheduler.setJobFactory(jobFactory);
return scheduler;
}
use of org.quartz.impl.StdSchedulerFactory in project camel by apache.
the class QuartzComponent method createSchedulerFactory.
private 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");
prop.put("org.terracotta.quartz.skipUpdateCheck", "true");
// camel context name will be a suffix to use one scheduler per context
if (isPrefixInstanceName()) {
String instName = createInstanceName(prop);
prop.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instName);
}
if (isInterruptJobsOnShutdown()) {
prop.setProperty(StdSchedulerFactory.PROP_SCHED_INTERRUPT_JOBS_ON_SHUTDOWN, "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);
} 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
if (isPrefixInstanceName()) {
// 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");
prop.put("org.terracotta.quartz.skipUpdateCheck", "true");
if (isInterruptJobsOnShutdown()) {
prop.setProperty(StdSchedulerFactory.PROP_SCHED_INTERRUPT_JOBS_ON_SHUTDOWN, "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 siddhi by wso2.
the class CronWindowProcessor method scheduleCronJob.
private void scheduleCronJob(String cronString, String elementId) {
try {
SchedulerFactory schedFact = new StdSchedulerFactory();
scheduler = schedFact.getScheduler();
jobName = "EventRemoverJob_" + elementId;
JobKey jobKey = new JobKey(jobName, jobGroup);
if (scheduler.checkExists(jobKey)) {
scheduler.deleteJob(jobKey);
}
scheduler.start();
JobDataMap dataMap = new JobDataMap();
dataMap.put("windowProcessor", this);
JobDetail job = org.quartz.JobBuilder.newJob(CronWindowProcessor.class).withIdentity(jobName, jobGroup).usingJobData(dataMap).build();
Trigger trigger = org.quartz.TriggerBuilder.newTrigger().withIdentity("EventRemoverTrigger_" + elementId, jobGroup).withSchedule(CronScheduleBuilder.cronSchedule(cronString)).build();
scheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
log.error("Error while instantiating quartz scheduler", e);
}
}
use of org.quartz.impl.StdSchedulerFactory in project engine by craftercms.
the class SchedulingUtils method createScheduler.
public static Scheduler createScheduler(String schedulerName) throws SchedulerException {
Properties props = new Properties();
props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, schedulerName);
props.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
props.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
SchedulerFactory schedulerFactory = new StdSchedulerFactory(props);
return schedulerFactory.getScheduler();
}
use of org.quartz.impl.StdSchedulerFactory in project nutzboot by nutzam.
the class QuartzStarter method getIocLoader.
public IocLoader getIocLoader() {
if (!conf.has("cron.pkgs")) {
conf.put("cron.pkgs", appContext.getPackage());
}
QuartzIocLoader loader = new QuartzIocLoader();
if (appContext.getClassLoader().getResource("quartz.properties") != null) {
log.debug("found quartz.properties, use it");
return loader;
}
// 通过nutzboot的配置信息来初始化
Properties properties = new Properties();
for (String key : conf.keySet()) {
if (key.startsWith("quartz.")) {
properties.put("org." + key, conf.get(key));
}
}
// 设置一下默认值
/*
org.quartz.scheduler.instanceName = NutzbookScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.scheduler.skipUpdateCheck=true
*/
properties.putIfAbsent("org.quartz.scheduler.instanceName", "NutzbootScheduler");
properties.putIfAbsent("org.quartz.threadPool.threadCount", "8");
properties.putIfAbsent("org.quartz.scheduler.skipUpdateCheck", "true");
startupDelay = conf.getInt("quartz.startupDelay", 0);
try {
StdSchedulerFactory factory = new StdSchedulerFactory(properties);
scheduler = factory.getScheduler();
scheduler.setJobFactory(new NutQuartzJobFactory(appContext.getIoc()));
((Ioc2) appContext.getIoc()).getIocContext().save("app", "scheduler", new ObjectProxy(scheduler));
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
return loader;
}
Aggregations