Search in sources :

Example 31 with JobDetail

use of org.quartz.JobDetail in project openhab1-addons by openhab.

the class FHTBinding method scheduleJob.

/**
     * The user may configure this binding to update the internal clock of
     * FHT80b devices via rf command. The method takes care of scheduling this
     * job.
     */
private JobKey scheduleJob(Class<? extends Job> jobClass, String cronExpression) {
    JobKey jobKey = null;
    try {
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        JobDetail detail = JobBuilder.newJob(jobClass).withIdentity("FHT " + jobClass.getSimpleName(), "cul").build();
        detail.getJobDataMap().put(FHTBinding.class.getName(), this);
        CronTrigger trigger = TriggerBuilder.newTrigger().forJob(detail).withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
        jobKey = detail.getKey();
        sched.scheduleJob(detail, trigger);
    } catch (SchedulerException e) {
        logger.error("Can't schedule time update job", e);
    }
    return jobKey;
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 32 with JobDetail

use of org.quartz.JobDetail in project openhab1-addons by openhab.

the class MapDBPersistenceService method scheduleJob.

/**
     * Schedules new quartz scheduler jobs for committing transactions and
     * backing up the database
     */
private void scheduleJob() {
    try {
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        // schedule commit-job
        JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build();
        SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(commitInterval)).build();
        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval);
    } catch (SchedulerException e) {
        logger.warn("Could not create Job: {}", e.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 33 with JobDetail

use of org.quartz.JobDetail in project openhab1-addons by openhab.

the class GCalPersistenceService method scheduleUploadJob.

/**
     * Schedules new quartz scheduler job for uploading calendar entries to Google
     */
private void scheduleUploadJob() {
    try {
        scheduler = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(SynchronizationJob.class).withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP).build();
        SimpleTrigger trigger = newTrigger().withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(uploadInterval)).build();
        scheduler.scheduleJob(job, trigger);
        logger.debug("Scheduled Google Calendar Upload-Job with interval '{}'", uploadInterval);
    } catch (SchedulerException e) {
        logger.warn("Could not create Google Calendar Upload-Job: {}", e.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) SimpleTrigger(org.quartz.SimpleTrigger)

Example 34 with JobDetail

use of org.quartz.JobDetail in project openhab1-addons by openhab.

the class Db4oPersistenceService method scheduleJob.

/**
     * Schedules new quartz scheduler jobs for committing transactions and
     * backing up the database
     */
private void scheduleJob() {
    try {
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        // schedule commit-job
        JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build();
        SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(commitInterval)).build();
        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval);
        // schedule backup-job
        JobDetail backupJob = newJob(BackupJob.class).withIdentity("Backup_DB", SCHEDULER_GROUP).build();
        CronTrigger backupTrigger = newTrigger().withIdentity("Backup_DB", SCHEDULER_GROUP).withSchedule(CronScheduleBuilder.cronSchedule(backupInterval)).build();
        sched.scheduleJob(backupJob, backupTrigger);
        logger.debug("Scheduled Backup-Job with cron expression '{}'", backupInterval);
    } catch (SchedulerException e) {
        logger.warn("Could not create Job: {}", e.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 35 with JobDetail

use of org.quartz.JobDetail in project OpenClinica by OpenClinica.

the class XsltTransformJob method postErrorMessage.

private void postErrorMessage(String message, JobExecutionContext context) {
    String SCHEDULER = "schedulerFactoryBean";
    try {
        ApplicationContext appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
        StdScheduler scheduler = (StdScheduler) appContext.getBean(SCHEDULER);
        JobDetail jobDetail = context.getJobDetail();
        JobDataMap dataMap = jobDetail.getJobDataMap();
        dataMap.put("failMessage", message);
        jobDetail.getJobBuilder().usingJobData(dataMap);
        // replace the job with the extra data
        scheduler.addJob(jobDetail, true);
    } catch (SchedulerException e) {
        throw new IllegalStateException("Error processing post error message", e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) StdScheduler(org.quartz.impl.StdScheduler)

Aggregations

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4