use of org.quartz.CronScheduleBuilder in project camel by apache.
the class CronScheduledRoutePolicy method createTrigger.
@Override
protected Trigger createTrigger(Action action, Route route) throws Exception {
Trigger trigger = null;
CronScheduleBuilder scheduleBuilder = null;
String triggerPrefix = null;
if (action == Action.START) {
scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStartTime());
triggerPrefix = TRIGGER_START;
} else if (action == Action.STOP) {
scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStopTime());
triggerPrefix = TRIGGER_STOP;
} else if (action == Action.SUSPEND) {
scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteSuspendTime());
triggerPrefix = TRIGGER_SUSPEND;
} else if (action == Action.RESUME) {
scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteResumeTime());
triggerPrefix = TRIGGER_RESUME;
}
if (scheduleBuilder != null) {
if (timeZone != null) {
scheduleBuilder.inTimeZone(timeZone);
}
TriggerKey triggerKey = new TriggerKey(triggerPrefix + route.getId(), TRIGGER_GROUP + route.getId());
trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
}
return trigger;
}
use of org.quartz.CronScheduleBuilder in project Dempsy by Dempsy.
the class CronOutputSchedule method getCronTrigger.
/**
* Gets the cron trigger.
*
* @param cronExpression the cron expression
* @return the cron trigger
*/
private Trigger getCronTrigger(String cronExpression) {
CronScheduleBuilder cronScheduleBuilder = null;
Trigger cronTrigger = null;
try {
cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
cronScheduleBuilder.withMisfireHandlingInstructionFireAndProceed();
TriggerBuilder<Trigger> cronTtriggerBuilder = TriggerBuilder.newTrigger();
cronTtriggerBuilder.withSchedule(cronScheduleBuilder);
cronTrigger = cronTtriggerBuilder.build();
} catch (ParseException pe) {
logger.error("Error occurred while builiding the cronTrigger : " + pe.getMessage(), pe);
}
return cronTrigger;
}
use of org.quartz.CronScheduleBuilder 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.CronScheduleBuilder 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