use of org.quartz.SchedulerFactory in project spring-framework by spring-projects.
the class QuartzSupportTests method schedulerFactoryBeanWithApplicationContext.
@Test
public void schedulerFactoryBeanWithApplicationContext() throws Exception {
TestBean tb = new TestBean("tb", 99);
StaticApplicationContext ac = new StaticApplicationContext();
final Scheduler scheduler = mock(Scheduler.class);
SchedulerContext schedulerContext = new SchedulerContext();
given(scheduler.getContext()).willReturn(schedulerContext);
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean() {
@Override
protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) {
return scheduler;
}
};
schedulerFactoryBean.setJobFactory(null);
Map<String, Object> schedulerContextMap = new HashMap<>();
schedulerContextMap.put("testBean", tb);
schedulerFactoryBean.setSchedulerContextAsMap(schedulerContextMap);
schedulerFactoryBean.setApplicationContext(ac);
schedulerFactoryBean.setApplicationContextSchedulerContextKey("appCtx");
try {
schedulerFactoryBean.afterPropertiesSet();
schedulerFactoryBean.start();
Scheduler returnedScheduler = schedulerFactoryBean.getObject();
assertEquals(tb, returnedScheduler.getContext().get("testBean"));
assertEquals(ac, returnedScheduler.getContext().get("appCtx"));
} finally {
schedulerFactoryBean.destroy();
}
verify(scheduler).start();
verify(scheduler).shutdown(false);
}
use of org.quartz.SchedulerFactory 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.SchedulerFactory in project deltaspike by apache.
the class AbstractQuartzScheduler method start.
@Override
public void start() {
if (this.scheduler != null) {
throw new UnsupportedOperationException("the scheduler is started already");
}
SchedulerFactory schedulerFactory = null;
try {
Properties properties = new Properties();
properties.put(StdSchedulerFactory.PROP_SCHED_JOB_FACTORY_CLASS, CdiAwareJobFactory.class.getName());
try {
ResourceBundle config = loadCustomQuartzConfig();
Enumeration<String> keys = config.getKeys();
String key;
while (keys.hasMoreElements()) {
key = keys.nextElement();
properties.put(key, config.getString(key));
}
} catch (Exception e1) {
LOG.info("no custom quartz-config file found. falling back to the default config provided by quartz.");
InputStream inputStream = null;
try {
inputStream = ClassUtils.getClassLoader(null).getResourceAsStream("org/quartz/quartz.properties");
properties.load(inputStream);
} catch (Exception e2) {
LOG.warning("failed to load quartz default-config");
schedulerFactory = new StdSchedulerFactory();
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
if (schedulerFactory == null) {
schedulerFactory = new StdSchedulerFactory(properties);
}
} catch (Exception e) {
LOG.log(Level.WARNING, "fallback to default scheduler-factory", e);
schedulerFactory = new StdSchedulerFactory();
}
try {
this.scheduler = schedulerFactory.getScheduler();
if (SchedulerBaseConfig.LifecycleIntegration.START_SCOPES_PER_JOB) {
this.scheduler.getListenerManager().addJobListener(new InjectionAwareJobListener());
}
if (!this.scheduler.isStarted()) {
this.scheduler.startDelayed(SchedulerBaseConfig.LifecycleIntegration.DELAYED_START_IN_SECONDS);
}
} catch (SchedulerException e) {
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
use of org.quartz.SchedulerFactory in project searchcode-server by boyter.
the class Singleton method getScheduler.
public static synchronized Scheduler getScheduler() {
try {
if (scheduler == null || scheduler.isShutdown()) {
try {
SchedulerFactory sf = new StdSchedulerFactory();
scheduler = sf.getScheduler();
} catch (SchedulerException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
}
} catch (SchedulerException e) {
}
return scheduler;
}
use of org.quartz.SchedulerFactory 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();
}
Aggregations