use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project herd by FINRAOS.
the class ServiceSpringModuleConfig method quartzScheduler.
/**
* Gets a Quartz scheduler factory bean that can return a Quartz scheduler.
*
* @return the Quartz scheduler factory bean.
* @throws Exception if the bean couldn't be created.
*/
@Bean
public SchedulerFactoryBean quartzScheduler() throws Exception {
SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
AutowiringQuartzSpringBeanJobFactory jobFactory = new AutowiringQuartzSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
quartzScheduler.setJobFactory(jobFactory);
// Name our scheduler.
quartzScheduler.setSchedulerName("herdScheduler");
// Setup the scheduler to use Spring’s dataSource and transactionManager.
quartzScheduler.setDataSource(herdDataSource);
quartzScheduler.setTransactionManager(herdTransactionManager);
// Create the Quartz tables for JUnits.
if (shouldCreateQuartzTables()) {
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
resourceDatabasePopulator.addScript(new ClassPathResource("createQuartzTables.sql"));
// This is what the DataSourceInitializer does.
DatabasePopulatorUtils.execute(resourceDatabasePopulator, herdDataSource);
}
// Set quartz properties. Please note that Spring uses LocalDataSourceJobStore extension of JobStoreCMT.
Properties quartzProperties = new Properties();
quartzScheduler.setQuartzProperties(quartzProperties);
// Configure Main Main Scheduler Properties. The "instance" parameters are needed to manage cluster instances.
quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "herdSystemJobScheduler");
quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, StdSchedulerFactory.AUTO_GENERATE_INSTANCE_ID);
// Configure ThreadPool.
quartzProperties.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, "org.quartz.simpl.SimpleThreadPool");
quartzProperties.setProperty("org.quartz.threadPool.threadCount", configurationHelper.getProperty(ConfigurationValue.SYSTEM_JOBS_THREAD_POOL_THREAD_COUNT));
quartzProperties.setProperty("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true");
// Configure JobStore.
quartzProperties.setProperty("org.quartz.jobStore.tablePrefix", "QRTZ_");
quartzProperties.setProperty("org.quartz.jobStore.isClustered", "true");
quartzProperties.setProperty(ConfigurationValue.QUARTZ_JOBSTORE_DRIVER_DELEGATE_CLASS.getKey(), getQuartzDatabaseDelegateClass());
// Build a list of system jobs to be scheduled.
Map<String, AbstractSystemJob> systemJobs = applicationContext.getBeansOfType(AbstractSystemJob.class);
List<JobDetail> jobDetails = new ArrayList<>();
List<CronTrigger> triggers = new ArrayList<>();
for (Map.Entry<String, AbstractSystemJob> entry : systemJobs.entrySet()) {
// Prepare job detail and trigger for the system job.
String jobName = entry.getKey();
AbstractSystemJob systemJob = entry.getValue();
JobDetail jobDetail = newJob(systemJob.getClass()).withIdentity(jobName).storeDurably().requestRecovery().build();
TriggerKey jobTriggerKey = TriggerKey.triggerKey(jobName + AbstractSystemJob.CRON_TRIGGER_SUFFIX);
CronTrigger trigger = newTrigger().withIdentity(jobTriggerKey).forJob(jobName).usingJobData(systemJob.getJobDataMap()).withSchedule(cronSchedule(systemJob.getCronExpression())).build();
// Add this system job to the list of jobs/triggers to be scheduled.
jobDetails.add(jobDetail);
triggers.add(trigger);
}
// Schedule the system jobs and set a flag to overwrite already registered jobs that would be read in from the database (persistent job store).
quartzScheduler.setOverwriteExistingJobs(true);
quartzScheduler.setJobDetails(jobDetails.toArray(new JobDetail[jobDetails.size()]));
quartzScheduler.setTriggers(triggers.toArray(new CronTrigger[triggers.size()]));
return quartzScheduler;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project syncope by apache.
the class SchedulerShutdown method destroy.
@Override
public void destroy() throws Exception {
SchedulerFactoryBean scheduler = ctx.getBean(SchedulerFactoryBean.class);
scheduler.getScheduler().shutdown();
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project motech by motech.
the class MotechSchedulerFactoryBean method init.
/**
* Creates the Spring {@code SchedulerFactoryBean}.
*/
@PostConstruct
public void init() {
schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setQuartzProperties(schedulerProperties);
schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(getBooleanWithDefault(schedulerProperties.getProperty("scheduler.waitForJobsToCompleteOnShutdown"), true));
schedulerFactoryBean.setApplicationContextSchedulerContextKey("applicationContext");
schedulerFactoryBean.setApplicationContext(applicationContext);
try {
schedulerFactoryBean.afterPropertiesSet();
schedulerFactoryBean.getScheduler().start();
} catch (Exception e) {
throw new SchedulerInstantiationException("Failed to instantiate scheduler with configuration from quartz.properties", e);
}
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project springBoot-learn-demo by nbfujx.
the class SchedulerConfig method schedulerFactoryBean.
@Bean(name = "SchedulerFactory")
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setQuartzProperties(quartzProperties());
return factory;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project netxms by netxms.
the class AppContextConfig method quartzScheduler.
@Bean
public SchedulerFactoryBean quartzScheduler() {
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
final Properties mergedProperties = new Properties();
mergedProperties.putAll(loadProperties("org/quartz/quartz.properties"));
ServerSettings.DataSourceConfig dataSourceConfig = settings.getDataSourceConfig(ServerSettings.DC_ID_SCHEDULER);
Properties properties = new Properties();
properties.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
properties.put("org.quartz.jobStore.driverDelegateClass", dataSourceConfig.getQuartzDriverDelegate());
properties.put("org.quartz.jobStore.dataSource", "myDS");
properties.put("org.quartz.dataSource.myDS.driver", dataSourceConfig.getDriver());
properties.put("org.quartz.dataSource.myDS.URL", dataSourceConfig.getUrl());
properties.put("org.quartz.dataSource.myDS.user", dataSourceConfig.getUsername());
properties.put("org.quartz.dataSource.myDS.password", dataSourceConfig.getPassword());
properties.put("org.quartz.dataSource.myDS.maxConnections", "20");
properties.put("org.quartz.scheduler.skipUpdateCheck", "true");
mergedProperties.putAll(properties);
schedulerFactory.setQuartzProperties(mergedProperties);
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
schedulerFactory.setJobFactory(jobFactory);
return schedulerFactory;
}
Aggregations