use of org.quartz.Trigger in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureAnotherCronExpression.
@Test
public void testConfigureAnotherCronExpression() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?cron=0+0+*+*+*+?");
Scheduler scheduler = endpoint.getComponent().getScheduler();
TriggerKey triggerKey = endpoint.getTriggerKey();
Trigger trigger = scheduler.getTrigger(triggerKey);
JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
assertEquals("getName()", "myTimerName", triggerKey.getName());
assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
assertEquals("getJobName", "myTimerName", jobDetail.getKey().getName());
assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
assertIsInstanceOf(CronTrigger.class, trigger);
CronTrigger cronTrigger = (CronTrigger) trigger;
assertEquals("cron expression", "0 0 * * * ?", cronTrigger.getCronExpression());
}
use of org.quartz.Trigger in project camel by apache.
the class ScheduledRoutePolicy method scheduleRoute.
public void scheduleRoute(Action action, Route route) throws Exception {
JobDetail jobDetail = createJobDetail(action, route);
Trigger trigger = createTrigger(action, route);
updateScheduledRouteDetails(action, jobDetail, trigger, route);
loadCallbackDataIntoSchedulerContext(jobDetail, action, route);
boolean isClustered = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class).isClustered();
if (isClustered) {
// check to see if the same job has already been setup through another node of the cluster
JobDetail existingJobDetail = getScheduler().getJobDetail(jobDetail.getKey());
if (jobDetail.equals(existingJobDetail)) {
if (LOG.isInfoEnabled()) {
LOG.info("Skipping to schedule the job: {} for action: {} on route {} as the job: {} already existing inside the cluster", new Object[] { jobDetail.getKey(), action, route.getId(), existingJobDetail.getKey() });
}
// skip scheduling the same job again as one is already existing for the same routeId and action
return;
}
}
getScheduler().scheduleJob(jobDetail, trigger);
if (LOG.isInfoEnabled()) {
LOG.info("Scheduled trigger: {} for action: {} on route {}", new Object[] { trigger.getKey(), action, route.getId() });
}
}
use of org.quartz.Trigger in project camel by apache.
the class QuartzNameCollisionTest method testRemoveJob.
/**
* Confirm the quartz trigger is removed on route stop.
*/
@Test
public void testRemoveJob() throws Exception {
camel1 = new DefaultCamelContext();
camel1.setName("camel-1");
camel1.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").id("route-1").to("log:one", "mock:one");
}
});
camel1.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("quartz://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").id("route-2").to("log:one", "mock:one");
}
});
camel1.start();
QuartzComponent component = (QuartzComponent) camel1.getComponent("quartz");
Scheduler scheduler = component.getScheduler();
Trigger trigger = scheduler.getTrigger("myTimerName", "myGroup");
Assert.assertNotNull(trigger);
camel1.stopRoute("route-1");
int triggerState = component.getScheduler().getTriggerState("myTimerName", "myGroup");
Assert.assertNotNull(trigger);
Assert.assertEquals(Trigger.STATE_PAUSED, triggerState);
}
use of org.quartz.Trigger in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureJobName.
@Test
public void testConfigureJobName() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myTimerName?job.name=hadrian&cron=0+0+*+*+*+?");
Scheduler scheduler = endpoint.getComponent().getScheduler();
TriggerKey triggerKey = endpoint.getTriggerKey();
Trigger trigger = scheduler.getTrigger(triggerKey);
JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey("hadrian", triggerKey.getGroup()));
assertEquals("getName()", "myTimerName", triggerKey.getName());
assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
assertEquals("getJobName", "hadrian", jobDetail.getKey().getName());
assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
assertIsInstanceOf(CronTrigger.class, trigger);
}
use of org.quartz.Trigger in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureNoDoubleSlashQuestionCron.
@Test
public void testConfigureNoDoubleSlashQuestionCron() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2:myGroup/myTimerName?cron=0+0+*+*+*+?");
Scheduler scheduler = endpoint.getComponent().getScheduler();
TriggerKey triggerKey = endpoint.getTriggerKey();
Trigger trigger = scheduler.getTrigger(triggerKey);
JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(triggerKey.getName(), triggerKey.getGroup()));
assertEquals("getName()", "myTimerName", triggerKey.getName());
assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
assertEquals("getJobName", "myTimerName", jobDetail.getKey().getName());
assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
assertIsInstanceOf(CronTrigger.class, trigger);
CronTrigger cronTrigger = (CronTrigger) trigger;
assertEquals("cron expression", "0 0 * * * ?", cronTrigger.getCronExpression());
}
Aggregations