use of org.quartz.TriggerKey in project ddf by codice.
the class ScheduledCommandTask method newTask.
@Override
public void newTask() {
LOGGER.trace("Creating new Task.");
long identifier = System.currentTimeMillis();
this.jobKey = new JobKey("job" + identifier, CommandJob.class.getSimpleName());
this.triggerKey = new TriggerKey("trigger" + identifier, CommandJob.class.getSimpleName());
JobDetail jobDetail = createJob();
Trigger trigger = createTrigger();
if (trigger == null) {
return;
}
try {
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
LOGGER.info("Error with scheduling of task.", e);
}
}
use of org.quartz.TriggerKey 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.TriggerKey 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.TriggerKey in project opennms by OpenNMS.
the class DefaultSchedulerServiceIT method testScheduleAndRemove.
@Test
public void testScheduleAndRemove() throws SchedulerException {
expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true);
replay(m_reportWrapperService);
MockRequestContext context = new MockRequestContext();
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setInstanceId("testScheduleAndRemoveTrigger");
assertEquals("success", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions, CRON_EXPRESSION, context));
verify(m_reportWrapperService);
Set<TriggerKey> triggers = m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP));
assertEquals(1, triggers.size());
assertEquals("testScheduleAndRemoveTrigger", triggers.iterator().next().getName());
m_schedulerService.removeTrigger("testScheduleAndRemoveTrigger");
assertEquals(0, m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP)).size());
}
use of org.quartz.TriggerKey in project opennms by OpenNMS.
the class DefaultSchedulerServiceIT method testMultipleTriggers.
@Test
public void testMultipleTriggers() throws SchedulerException {
expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true).times(2);
replay(m_reportWrapperService);
MockRequestContext context = new MockRequestContext();
// this trigger fires every 10 minutes starting at 0 minutes past the hour
DeliveryOptions deliveryOptions1 = new DeliveryOptions();
deliveryOptions1.setInstanceId("trigger1");
assertEquals("success", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions1, "0 0/10 * * * ?", context));
// this trigger fires every 10 minutes starting at 5 minutes past the hour
DeliveryOptions deliveryOptions2 = new DeliveryOptions();
deliveryOptions2.setInstanceId("trigger2");
assertEquals("success", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions2, "0 5/10 * * * ?", context));
verify(m_reportWrapperService);
final List<String> triggers = m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP)).stream().map(TriggerKey::getName).collect(Collectors.toList());
assertEquals(2, triggers.size());
assertTrue(triggers.contains("trigger1"));
assertTrue(triggers.contains("trigger2"));
m_schedulerService.removeTrigger("trigger1");
m_schedulerService.removeTrigger("trigger2");
assertEquals(0, m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP)).size());
}
Aggregations