Search in sources :

Example 41 with JobDataMap

use of org.quartz.JobDataMap 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 42 with JobDataMap

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

the class AbstractBaseJob method execute.

@Override
public void execute(JobExecutionContext jobContext) throws JobExecutionException {
    JobDataMap jobDataMap = jobContext.getJobDetail().getJobDataMap();
    if (logger.isDebugEnabled()) {
        String itemName = jobDataMap.getString("itemName");
        if (itemName != null) {
            logger.debug("Starting Astro {} for item {}", this.getClass().getSimpleName(), itemName);
        } else {
            logger.debug("Starting Astro {}", this.getClass().getSimpleName());
        }
    }
    executeJob(jobDataMap);
}
Also used : JobDataMap(org.quartz.JobDataMap)

Example 43 with JobDataMap

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

the class JobScheduler method scheduleIntervalJob.

/**
     * Schedules the IntervalJob with the specified interval and starts it
     * immediately.
     */
public void scheduleIntervalJob() {
    AstroConfig config = context.getConfig();
    String jobName = IntervalJob.class.getSimpleName();
    Date start = new Date(System.currentTimeMillis() + (config.getInterval()) * 1000);
    Trigger trigger = newTrigger().withIdentity(jobName + "-Trigger", JOB_GROUP).startAt(start).withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(config.getInterval())).build();
    schedule(jobName, IntervalJob.class, trigger, new JobDataMap());
    logger.info("Scheduled astro job with interval of {} seconds", config.getInterval());
}
Also used : JobDataMap(org.quartz.JobDataMap) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) AstroConfig(org.openhab.binding.astro.internal.common.AstroConfig) Date(java.util.Date)

Example 44 with JobDataMap

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

the class JobScheduler method scheduleItem.

/**
     * Schedules a item job at the specified date/time from the calendar object.
     */
public void scheduleItem(Calendar calendar, String itemName) {
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put("itemName", itemName);
    schedule(calendar, itemName, jobDataMap, ItemJob.class);
}
Also used : JobDataMap(org.quartz.JobDataMap)

Example 45 with JobDataMap

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

the class JobScheduler method scheduleSeasonJob.

/**
     * Schedules next Season job.
     */
public void scheduleSeasonJob(Season season) {
    Calendar nextSeason = season.getNextSeason();
    if (nextSeason == null) {
        nextSeason = DateTimeUtils.getFirstDayOfNextYear();
    }
    schedule(nextSeason, "Season", new JobDataMap(), SeasonJob.class);
}
Also used : JobDataMap(org.quartz.JobDataMap) Calendar(java.util.Calendar)

Aggregations

JobDataMap (org.quartz.JobDataMap)59 Trigger (org.quartz.Trigger)21 JobDetail (org.quartz.JobDetail)20 SchedulerException (org.quartz.SchedulerException)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 Scheduler (org.quartz.Scheduler)10 JobExecutionException (org.quartz.JobExecutionException)9 ApplicationContext (org.springframework.context.ApplicationContext)9 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6 TriggerBean (org.akaza.openclinica.bean.admin.TriggerBean)6 Command (org.openhab.core.types.Command)5 SchedulerContext (org.quartz.SchedulerContext)5 SimpleTrigger (org.quartz.SimpleTrigger)5 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 Locale (java.util.Locale)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4