Search in sources :

Example 1 with TaskManagerConfiguration

use of com.evolveum.midpoint.task.quartzimpl.TaskManagerConfiguration in project midpoint by Evolveum.

the class LocalNodeManager method initializeScheduler.

/*
    * =============== SCHEDULER-LEVEL ACTIONS ===============
    *
    * (used internally by TaskManager)
    */
/**
     * Prepares Quartz scheduler. Configures its properties (based on Task Manager configuration) and creates the instance.
     * Does not start the scheduler, because this is done during post initialization.
     *
     * @throws com.evolveum.midpoint.task.api.TaskManagerInitializationException
     */
void initializeScheduler() throws TaskManagerInitializationException {
    TaskManagerConfiguration configuration = taskManager.getConfiguration();
    Properties quartzProperties = new Properties();
    if (configuration.isJdbcJobStore()) {
        quartzProperties.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
        quartzProperties.put("org.quartz.jobStore.driverDelegateClass", configuration.getJdbcDriverDelegateClass());
        createQuartzDbSchema(configuration);
        String MY_DS = "myDS";
        quartzProperties.put("org.quartz.jobStore.dataSource", MY_DS);
        if (configuration.getDataSource() != null) {
            quartzProperties.put("org.quartz.dataSource." + MY_DS + ".jndiURL", configuration.getDataSource());
        } else {
            quartzProperties.put("org.quartz.dataSource." + MY_DS + ".driver", configuration.getJdbcDriver());
            quartzProperties.put("org.quartz.dataSource." + MY_DS + ".URL", configuration.getJdbcUrl());
            quartzProperties.put("org.quartz.dataSource." + MY_DS + ".user", configuration.getJdbcUser());
            quartzProperties.put("org.quartz.dataSource." + MY_DS + ".password", configuration.getJdbcPassword());
        }
        quartzProperties.put("org.quartz.jobStore.isClustered", configuration.isClustered() ? "true" : "false");
    } else {
        quartzProperties.put("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
    }
    quartzProperties.put("org.quartz.scheduler.instanceName", "midPointScheduler");
    quartzProperties.put("org.quartz.scheduler.instanceId", taskManager.getNodeId());
    quartzProperties.put("org.quartz.scheduler.skipUpdateCheck", "true");
    quartzProperties.put("org.quartz.threadPool.threadCount", Integer.toString(configuration.getThreads()));
    // in test mode we set idleWaitTime to a lower value, because on some occasions
    // the Quartz scheduler "forgots" to fire a trigger immediately after creation,
    // and the default delay of 10s is too much for most of the tests.
    int schedulerLoopTime;
    if (configuration.isTestMode()) {
        if (configuration.isJdbcJobStore()) {
            schedulerLoopTime = 5000;
        } else {
            schedulerLoopTime = 2000;
        }
    } else {
        schedulerLoopTime = 10000;
    }
    quartzProperties.put("org.quartz.scheduler.idleWaitTime", Integer.toString(schedulerLoopTime));
    quartzProperties.put("org.quartz.scheduler.jmx.export", "true");
    if (configuration.isTestMode()) {
        LOGGER.info("ReusableQuartzScheduler is set: the task manager threads will NOT be stopped on shutdown. Also, scheduler threads will run as daemon ones.");
        quartzProperties.put("org.quartz.scheduler.makeSchedulerThreadDaemon", "true");
        quartzProperties.put("org.quartz.threadPool.makeThreadsDaemons", "true");
    }
    // initialize the scheduler (without starting it)
    try {
        LOGGER.trace("Quartz scheduler properties: {}", quartzProperties);
        StdSchedulerFactory sf = new StdSchedulerFactory();
        sf.initialize(quartzProperties);
        getGlobalExecutionManager().setQuartzScheduler(sf.getScheduler());
    } catch (SchedulerException e) {
        throw new TaskManagerInitializationException("Cannot initialize the Quartz scheduler", e);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) TaskManagerConfiguration(com.evolveum.midpoint.task.quartzimpl.TaskManagerConfiguration)

Aggregations

TaskManagerConfiguration (com.evolveum.midpoint.task.quartzimpl.TaskManagerConfiguration)1 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)1