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");
}
}
}
}
}
}
}
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);
}
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());
}
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);
}
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);
}
Aggregations