Search in sources :

Example 76 with TriggerKey

use of org.quartz.TriggerKey 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());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 77 with TriggerKey

use of org.quartz.TriggerKey in project camel by apache.

the class ScheduledRoutePolicy method resumeRouteTrigger.

public void resumeRouteTrigger(Action action, String routeId) throws SchedulerException {
    TriggerKey triggerKey = retrieveTriggerKey(action, routeId);
    getScheduler().resumeTrigger(triggerKey);
    LOG.debug("Scheduled trigger: {} is resumed", triggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey)

Example 78 with TriggerKey

use of org.quartz.TriggerKey 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);
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 79 with TriggerKey

use of org.quartz.TriggerKey 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());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 80 with TriggerKey

use of org.quartz.TriggerKey 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("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").id("route-1").to("log:one", "mock:one");
        }
    });
    camel1.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").id("route-2").to("log:one", "mock:one");
        }
    });
    camel1.start();
    QuartzComponent component = (QuartzComponent) camel1.getComponent("quartz2");
    Scheduler scheduler = component.getScheduler();
    TriggerKey triggerKey = TriggerKey.triggerKey("myTimerName", "myGroup");
    Trigger trigger = scheduler.getTrigger(triggerKey);
    Assert.assertNotNull(trigger);
    camel1.stopRoute("route-1");
    Trigger.TriggerState triggerState = component.getScheduler().getTriggerState(triggerKey);
    Assert.assertNotNull(trigger);
    Assert.assertEquals(Trigger.TriggerState.PAUSED, triggerState);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(org.quartz.Scheduler) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Aggregations

TriggerKey (org.quartz.TriggerKey)112 Trigger (org.quartz.Trigger)49 JobKey (org.quartz.JobKey)30 SchedulerException (org.quartz.SchedulerException)30 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Test (org.junit.Test)18 Scheduler (org.quartz.Scheduler)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4