Search in sources :

Example 81 with Trigger

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());
}
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 82 with Trigger

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() });
    }
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) QuartzComponent(org.apache.camel.component.quartz2.QuartzComponent)

Example 83 with Trigger

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);
}
Also used : Trigger(org.quartz.Trigger) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(org.quartz.Scheduler) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 84 with Trigger

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);
}
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 85 with 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());
}
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)

Aggregations

Trigger (org.quartz.Trigger)104 JobDetail (org.quartz.JobDetail)51 SchedulerException (org.quartz.SchedulerException)40 CronTrigger (org.quartz.CronTrigger)29 Test (org.junit.Test)23 Scheduler (org.quartz.Scheduler)22 JobDataMap (org.quartz.JobDataMap)21 SimpleTrigger (org.quartz.SimpleTrigger)20 TriggerKey (org.quartz.TriggerKey)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)19 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4 ProtoTrigger (co.cask.cdap.proto.ProtoTrigger)3