use of org.quartz.Scheduler 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);
}
}
use of org.quartz.Scheduler in project camel by apache.
the class QuartzComponentTest method testQuartzComponentCustomScheduler.
@Test
public void testQuartzComponentCustomScheduler() throws Exception {
QuartzComponent comp = new QuartzComponent();
comp.setCamelContext(context);
SchedulerFactory fac = new StdSchedulerFactory();
comp.setFactory(fac);
assertSame(fac, comp.getFactory());
Scheduler sch = fac.getScheduler();
comp.setScheduler(sch);
assertSame(sch, comp.getScheduler());
comp.start();
comp.stop();
}
use of org.quartz.Scheduler in project camel by apache.
the class QuartzEndpoint method pauseTrigger.
public void pauseTrigger() throws Exception {
Scheduler scheduler = getComponent().getScheduler();
boolean isClustered = scheduler.getMetaData().isJobStoreClustered();
if (jobPaused.get() || isClustered) {
return;
}
jobPaused.set(true);
if (!scheduler.isShutdown()) {
LOG.info("Pausing trigger {}", triggerKey);
scheduler.pauseTrigger(triggerKey);
}
}
use of org.quartz.Scheduler in project camel by apache.
the class QuartzEndpoint method removeJobInScheduler.
private void removeJobInScheduler() throws Exception {
Scheduler scheduler = getComponent().getScheduler();
if (scheduler == null) {
return;
}
if (deleteJob) {
boolean isClustered = scheduler.getMetaData().isJobStoreClustered();
if (!scheduler.isShutdown() && !isClustered) {
LOG.info("Deleting job {}", triggerKey);
scheduler.unscheduleJob(triggerKey);
jobAdded.set(false);
}
} else if (pauseJob) {
pauseTrigger();
}
// Decrement camel job count for this endpoint
AtomicInteger number = (AtomicInteger) scheduler.getContext().get(QuartzConstants.QUARTZ_CAMEL_JOBS_COUNT);
if (number != null) {
number.decrementAndGet();
}
}
use of org.quartz.Scheduler in project camel by apache.
the class QuartzEndpoint method addJobInScheduler.
private void addJobInScheduler() throws Exception {
// Add or use existing trigger to/from scheduler
Scheduler scheduler = getComponent().getScheduler();
JobDetail jobDetail;
Trigger oldTrigger = scheduler.getTrigger(triggerKey);
boolean triggerExisted = oldTrigger != null;
if (triggerExisted && !isRecoverableJob()) {
ensureNoDupTriggerKey();
}
jobDetail = createJobDetail();
Trigger trigger = createTrigger(jobDetail);
QuartzHelper.updateJobDataMap(getCamelContext(), jobDetail, getEndpointUri(), isUsingFixedCamelContextName());
if (triggerExisted) {
// Reschedule job if trigger settings were changed
if (hasTriggerChanged(oldTrigger, trigger)) {
scheduler.rescheduleJob(triggerKey, trigger);
}
} else {
try {
// Schedule it now. Remember that scheduler might not be started it, but we can schedule now.
scheduler.scheduleJob(jobDetail, trigger);
} catch (ObjectAlreadyExistsException ex) {
// some other VM might may have stored the job & trigger in DB in clustered mode, in the mean time
if (!(getComponent().isClustered())) {
throw ex;
} else {
trigger = scheduler.getTrigger(triggerKey);
if (trigger == null) {
throw new SchedulerException("Trigger could not be found in quartz scheduler.");
}
}
}
}
if (LOG.isInfoEnabled()) {
LOG.info("Job {} (triggerType={}, jobClass={}) is scheduled. Next fire date is {}", new Object[] { trigger.getKey(), trigger.getClass().getSimpleName(), jobDetail.getJobClass().getSimpleName(), trigger.getNextFireTime() });
}
// Increase camel job count for this endpoint
AtomicInteger number = (AtomicInteger) scheduler.getContext().get(QuartzConstants.QUARTZ_CAMEL_JOBS_COUNT);
if (number != null) {
number.incrementAndGet();
}
jobAdded.set(true);
}
Aggregations