Search in sources :

Example 81 with JobDetail

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

the class AbstractOutputSchedule method getJobDetail.

/**
    * Gets the job detail.
    *
    * @param outputInvoker the output invoker
    * @return the job detail
    */
protected JobDetail getJobDetail() {
    JobBuilder jobBuilder = JobBuilder.newJob(OutputJob.class);
    JobDetail jobDetail = jobBuilder.build();
    jobDetail.getJobDataMap().put(OUTPUT_JOB_NAME, this);
    return jobDetail;
}
Also used : JobDetail(org.quartz.JobDetail) JobBuilder(org.quartz.JobBuilder)

Example 82 with JobDetail

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

the class HDanywhereBinding method execute.

@Override
protected void execute() {
    if (isProperlyConfigured()) {
        Scheduler sched = null;
        try {
            sched = StdSchedulerFactory.getDefaultScheduler();
        } catch (SchedulerException e) {
            logger.error("An exception occurred while getting a reference to the Quartz Scheduler");
        }
        for (HDanywhereBindingProvider provider : providers) {
            HashMap<String, Integer> compiledList = provider.getIntervalList();
            if (compiledList != null) {
                Iterator<String> pbcIterator = compiledList.keySet().iterator();
                while (pbcIterator.hasNext()) {
                    String aHost = pbcIterator.next();
                    boolean jobExists = false;
                    // enumerate each job group
                    try {
                        for (String group : sched.getJobGroupNames()) {
                            // enumerate each job in group
                            for (JobKey jobKey : sched.getJobKeys(jobGroupEquals(group))) {
                                if (jobKey.getName().equals(aHost)) {
                                    jobExists = true;
                                    break;
                                }
                            }
                        }
                    } catch (SchedulerException e1) {
                        logger.error("An exception occurred while querying the Quartz Scheduler ({})", e1.getMessage());
                    }
                    if (!jobExists) {
                        // set up the Quartz jobs
                        JobDataMap map = new JobDataMap();
                        map.put("host", aHost);
                        map.put("binding", this);
                        JobDetail job = newJob(HDanywhereBinding.PollJob.class).withIdentity(aHost, "HDanywhere-" + provider.toString()).usingJobData(map).build();
                        Trigger trigger = newTrigger().withIdentity(aHost, "HDanywhere-" + provider.toString()).startNow().withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(compiledList.get(aHost))).build();
                        try {
                            sched.scheduleJob(job, trigger);
                        } catch (SchedulerException e) {
                            logger.error("An exception occurred while scheduling a Quartz Job");
                        }
                    }
                }
            }
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) HDanywhereBindingProvider(org.openhab.binding.hdanywhere.HDanywhereBindingProvider) Scheduler(org.quartz.Scheduler) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger)

Example 83 with JobDetail

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

the class JobScheduler method schedule.

/**
     * Schedules a job at the specified date/time, deletes a previously
     * scheduled job.
     */
private void schedule(Calendar calendar, String jobName, JobDataMap jobDataMap, Class<? extends Job> jobClass) {
    if (System.currentTimeMillis() < calendar.getTimeInMillis()) {
        try {
            JobKey jobKey = new JobKey(jobName, JOB_GROUP);
            if (scheduler.getJobDetail(jobKey) != null) {
                scheduler.deleteJob(jobKey);
            }
            Trigger trigger = newTrigger().withIdentity(jobName + "-Trigger", JOB_GROUP).startAt(calendar.getTime()).build();
            JobDetail jobDetail = newJob(jobClass).withIdentity(jobKey).usingJobData(jobDataMap).build();
            scheduler.scheduleJob(jobDetail, trigger);
            logger.debug("Scheduled job with name {} at {}", jobName, sdf.format(calendar.getTime()));
        } catch (SchedulerException ex) {
            logger.error(ex.getMessage(), ex);
        }
    } else {
        logger.debug("Skipping job with name {} for today, starttime is in the past", jobName);
    }
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException)

Example 84 with JobDetail

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

the class FritzboxBinding method updated.

/**
     * {@inheritDoc}
     */
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        String ip = Objects.toString(config.get("ip"), null);
        if (StringUtils.isNotBlank(ip)) {
            if (!ip.equals(FritzboxBinding.ip)) {
                // only do something if the ip has changed
                FritzboxBinding.ip = ip;
                conditionalDeActivate();
                // and thus blocks the monitor thread
                try {
                    Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
                    JobKey jobKey = jobKey("Reconnect", "FritzBox");
                    TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox");
                    if (sched.checkExists(jobKey)) {
                        logger.debug("Daily reconnection job already exists");
                    } else {
                        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronSchedule);
                        JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build();
                        CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
                        sched.scheduleJob(job, trigger);
                        logger.debug("Scheduled a daily reconnection to FritzBox on {}:{}", ip, MONITOR_PORT);
                    }
                } catch (SchedulerException e) {
                    logger.warn("Could not create daily reconnection job", e);
                }
            }
        }
        String password = Objects.toString(config.get("password"), null);
        if (StringUtils.isNotBlank(password)) {
            FritzboxBinding.password = password;
        }
        String username = Objects.toString(config.get("user"), null);
        if (StringUtils.isNotBlank(username)) {
            FritzboxBinding.username = username;
        }
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 85 with JobDetail

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

the class CallMonitor method setupReconnectJob.

/***
     * reset the connection to fbox periodically
     */
public void setupReconnectJob() {
    try {
        // String cronPattern = "0 0 0 * * ?"; //every day
        // String cronPattern = "0 * * * * ?"; //every minute
        // every 2 hrs
        String cronPattern = "0 0 0/2 * * ?";
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        JobKey jobKey = jobKey("Reconnect", "FritzBox");
        TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox");
        if (sched.checkExists(jobKey)) {
            logger.debug("reconnection job already exists");
        } else {
            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronPattern);
            JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build();
            CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
            sched.scheduleJob(job, trigger);
            logger.debug("Scheduled reconnection job to FritzBox: {}", cronPattern);
        }
    } catch (SchedulerException e) {
        logger.warn("Could not create daily reconnection job", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

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