Example usage for org.springframework.scheduling.quartz SchedulerFactoryBean setQuartzProperties

List of usage examples for org.springframework.scheduling.quartz SchedulerFactoryBean setQuartzProperties

Introduction

In this page you can find the example usage for org.springframework.scheduling.quartz SchedulerFactoryBean setQuartzProperties.

Prototype

public void setQuartzProperties(Properties quartzProperties) 

Source Link

Document

Set Quartz properties, like "org.quartz.threadPool.class".

Usage

From source file:com.athina.queue.manager.quartz.QuartzConfiguration.java

private SchedulerFactoryBean buildSchedulerFactory(JobFactory jobFactory, Optional<DataSource> dataSource,
        Properties properties) {//from  w  w w.  j a v  a 2s. c o  m
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setJobFactory(jobFactory);
    schedulerFactoryBean.setDataSource(dataSource.orElse(null));
    schedulerFactoryBean.setQuartzProperties(properties);
    return schedulerFactoryBean;
}

From source file:com.orange.clara.pivotaltrackermirror.config.QuartzConfig.java

@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, JobFactory jobFactory)
        throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    // this allows to update triggers in DB when updating settings in config file:
    factory.setOverwriteExistingJobs(true);
    factory.setDataSource(dataSource);/*  w ww  .j  a v a  2 s  .  c om*/
    factory.setJobFactory(jobFactory);
    factory.setQuartzProperties(quartzProperties());

    return factory;
}

From source file:com.logsniffer.app.SchedulerAppConfig.java

/**
 * Defines a clustered Quartz Scheduler configured by properties from
 * {@link #acBackendProperties}./*from w  ww  .j a va2s  . c o m*/
 * 
 * @return Quart scheduler
 */
@Bean
public SchedulerFactoryBean schedulerFactory() {
    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
    schedulerFactory.setAutoStartup(true);
    schedulerFactory.setDataSource(dataSource);
    schedulerFactory.setWaitForJobsToCompleteOnShutdown(true);
    schedulerFactory.setOverwriteExistingJobs(true);
    schedulerFactory.setSchedulerName("LogsnifferScheduler");
    Properties quartzProperties = new Properties(logSnifferProperties);
    quartzProperties.setProperty("org.quartz.scheduler.instanceIdGenerator.class",
            SafeSimpleInstanceIdGenerator.class.getName());
    schedulerFactory.setQuartzProperties(quartzProperties);
    return schedulerFactory;
}

From source file:org.hsweb.web.service.impl.SchedulerAutoConfiguration.java

@Bean
public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setApplicationContext(applicationContext);
    schedulerFactoryBean.setAutoStartup(schedulerProperties.isAutoStartup());
    schedulerFactoryBean.setDataSource(dataSource);
    schedulerFactoryBean.setTransactionManager(platformTransactionManager);
    schedulerFactoryBean.setOverwriteExistingJobs(schedulerProperties.isOverwriteExistingJobs());
    schedulerFactoryBean.setSchedulerFactoryClass(StdSchedulerFactory.class);
    schedulerFactoryBean.setBeanName(schedulerProperties.getBeanName());
    schedulerFactoryBean.setJobFactory(jobFactory);
    schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(schedulerProperties.isWaitOnShutdown());
    schedulerFactoryBean.setQuartzProperties(schedulerProperties.getProperties());
    return schedulerFactoryBean;
}

From source file:com.github.dbourdette.glass.SpringConfig.java

@Bean
public Scheduler quartzScheduler(ApplicationContext context) throws Exception {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();

    factory.setApplicationContext(context);
    factory.setExposeSchedulerInRepository(true);
    factory.setApplicationContextSchedulerContextKey(APPLICATION_CONTEXT_KEY);
    factory.setJobFactory(glassJobFactory);

    Properties properties = new Properties();
    properties.setProperty("org.quartz.threadPool.class", SimpleThreadPool.class.getName());
    properties.setProperty("org.quartz.threadPool.threadCount", "15");
    properties.setProperty("org.quartz.threadPool.threadPriority", "4");

    if (configuration().isInMemory()) {
        properties.setProperty("org.quartz.jobStore.class", RAMJobStore.class.getName());
    } else {/* w w w . java  2  s  .  c om*/
        factory.setDataSource(dataSource());

        properties.setProperty("org.quartz.jobStore.tablePrefix", configuration().getTablePrefix());
        properties.setProperty("org.quartz.jobStore.isClustered", "false");
        properties.setProperty("org.quartz.jobStore.driverDelegateClass",
                configuration().getDriverDelegateClass());
    }

    factory.setQuartzProperties(properties);

    factory.afterPropertiesSet();

    Scheduler scheduler = factory.getObject();

    scheduler.getListenerManager().addJobListener(glassJobListener);
    scheduler.getListenerManager().addSchedulerListener(glassSchedulerListener);

    scheduler.start();

    return scheduler;
}

From source file:org.apache.fineract.infrastructure.jobs.service.JobRegisterServiceImpl.java

private Scheduler createScheduler(final String name, final int noOfThreads, JobListener... jobListeners)
        throws Exception {
    final SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    schedulerFactoryBean.setSchedulerName(name);
    schedulerFactoryBean.setGlobalJobListeners(jobListeners);
    final TriggerListener[] globalTriggerListeners = { globalSchedulerTriggerListener };
    schedulerFactoryBean.setGlobalTriggerListeners(globalTriggerListeners);
    final Properties quartzProperties = new Properties();
    quartzProperties.put(SchedulerFactoryBean.PROP_THREAD_COUNT, Integer.toString(noOfThreads));
    schedulerFactoryBean.setQuartzProperties(quartzProperties);
    schedulerFactoryBean.afterPropertiesSet();
    schedulerFactoryBean.start();/*from   w ww . ja  v a 2  s. com*/
    return schedulerFactoryBean.getScheduler();
}

From source file:org.finra.dm.service.config.ServiceSpringModuleConfig.java

/**
 * 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.
 *///www .  j ava 2s  .  c  om
@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("dmScheduler");

    // Setup the scheduler to use Springs dataSource and transactionManager.
    quartzScheduler.setDataSource(dmDataSource);
    quartzScheduler.setTransactionManager(dmTransactionManager);

    // Create the Quartz tables for JUnits.
    if (shouldCreateQuartzTables()) {
        ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
        resourceDatabasePopulator.addScript(new ClassPathResource("createQuartzTables.sql"));
        DatabasePopulatorUtils.execute(resourceDatabasePopulator, dmDataSource); // This is what the DataSourceInitializer does.
    }

    // 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, "dmSystemJobScheduler");
    quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID,
            StdSchedulerFactory.AUTO_GENERATE_INSTANCE_ID);
    quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_SKIP_UPDATE_CHECK, "true");

    // 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.
    quartzScheduler.setJobDetails(jobDetails.toArray(new JobDetail[jobDetails.size()]));
    quartzScheduler.setTriggers(triggers.toArray(new CronTrigger[triggers.size()]));

    return quartzScheduler;
}

From source file:org.finra.herd.service.config.ServiceSpringModuleConfig.java

/**
 * 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.
 *//*w ww.  j ava 2  s.  co m*/
@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 Springs 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"));
        DatabasePopulatorUtils.execute(resourceDatabasePopulator, herdDataSource); // This is what the DataSourceInitializer does.
    }

    // 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;
}