use of org.quartz.JobKey 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.JobKey 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);
}
}
use of org.quartz.JobKey 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;
}
}
}
use of org.quartz.JobKey in project openhab1-addons by openhab.
the class CallMonitor method shutdownReconnectJob.
/***
* cancel the reconnect job
*/
public void shutdownReconnectJob() {
Scheduler sched = null;
try {
sched = StdSchedulerFactory.getDefaultScheduler();
JobKey jobKey = jobKey("Reconnect", "FritzBox");
if (sched.checkExists(jobKey)) {
logger.debug("Found reconnection job. Shutting down...");
sched.deleteJob(jobKey);
}
} catch (SchedulerException e) {
logger.warn("Error shutting down reconnect job: {}", e.getLocalizedMessage());
}
}
use of org.quartz.JobKey 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);
}
}
Aggregations