Search in sources :

Example 11 with Trigger

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

the class QuartzEndpointConfigureTest method testConfigureGroupAndName.

@Test
public void testConfigureGroupAndName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myName?trigger.repeatCount=3");
    Trigger trigger = endpoint.getTrigger();
    assertEquals("getName()", "myName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
    // default job name
    assertEquals("getJobName", "quartz-" + endpoint.getId(), endpoint.getJobName());
    SimpleTrigger simpleTrigger = assertIsInstanceOf(SimpleTrigger.class, trigger);
    assertEquals("getRepeatCount()", 3, simpleTrigger.getRepeatCount());
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 12 with Trigger

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

the class QuartzMessage method populateInitialHeaders.

@Override
protected void populateInitialHeaders(Map<String, Object> map) {
    super.populateInitialHeaders(map);
    if (jobExecutionContext != null) {
        map.put("calendar", jobExecutionContext.getCalendar());
        map.put("fireTime", jobExecutionContext.getFireTime());
        map.put("jobDetail", jobExecutionContext.getJobDetail());
        map.put("jobInstance", jobExecutionContext.getJobInstance());
        map.put("jobRunTime", jobExecutionContext.getJobRunTime());
        map.put("mergedJobDataMap", jobExecutionContext.getMergedJobDataMap());
        map.put("nextFireTime", jobExecutionContext.getNextFireTime());
        map.put("previousFireTime", jobExecutionContext.getPreviousFireTime());
        map.put("refireCount", jobExecutionContext.getRefireCount());
        map.put("result", jobExecutionContext.getResult());
        map.put("scheduledFireTime", jobExecutionContext.getScheduledFireTime());
        map.put("scheduler", jobExecutionContext.getScheduler());
        Trigger trigger = jobExecutionContext.getTrigger();
        map.put("trigger", trigger);
        map.put("triggerName", trigger.getKey().getName());
        map.put("triggerGroup", trigger.getKey().getGroup());
    }
}
Also used : Trigger(org.quartz.Trigger)

Example 13 with Trigger

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

the class CronScheduledRoutePolicy method createTrigger.

@Override
protected Trigger createTrigger(Action action, Route route) throws Exception {
    Trigger trigger = null;
    CronScheduleBuilder scheduleBuilder = null;
    String triggerPrefix = null;
    if (action == Action.START) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStartTime());
        triggerPrefix = TRIGGER_START;
    } else if (action == Action.STOP) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStopTime());
        triggerPrefix = TRIGGER_STOP;
    } else if (action == Action.SUSPEND) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteSuspendTime());
        triggerPrefix = TRIGGER_SUSPEND;
    } else if (action == Action.RESUME) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteResumeTime());
        triggerPrefix = TRIGGER_RESUME;
    }
    if (scheduleBuilder != null) {
        if (timeZone != null) {
            scheduleBuilder.inTimeZone(timeZone);
        }
        TriggerKey triggerKey = new TriggerKey(triggerPrefix + route.getId(), TRIGGER_GROUP + route.getId());
        trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
    }
    return trigger;
}
Also used : TriggerKey(org.quartz.TriggerKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) Trigger(org.quartz.Trigger)

Example 14 with Trigger

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

the class QuartzCronRouteTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);
    assertMockEndpointsSatisfied();
    Trigger trigger = mock.getReceivedExchanges().get(0).getIn().getHeader("trigger", Trigger.class);
    Assert.assertThat(trigger instanceof CronTrigger, CoreMatchers.is(true));
    JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE).equals("cron"), CoreMatchers.is(true));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION).equals("0/2 * * * * ?"), CoreMatchers.is(true));
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 15 with Trigger

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

the class QuartzEndpointConfigureTest method testConfigureGroupAndName.

@Test
public void testConfigureGroupAndName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2://myGroup/myName?trigger.repeatCount=3&trigger.repeatInterval=1000");
    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()", "myName", triggerKey.getName());
    assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
    assertEquals("getJobName", "myName", jobDetail.getKey().getName());
    assertEquals("getJobGroup", "myGroup", jobDetail.getKey().getGroup());
    SimpleTrigger simpleTrigger = assertIsInstanceOf(SimpleTrigger.class, trigger);
    assertEquals("getRepeatCount()", 3, simpleTrigger.getRepeatCount());
}
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) SimpleTrigger(org.quartz.SimpleTrigger) 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