Search in sources :

Example 61 with CronTrigger

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

the class QuartzComponent method createCronTrigger.

protected CronTrigger createCronTrigger(String path) throws ParseException {
    CronTrigger cron = new CronTrigger();
    cron.setCronExpression(path);
    return cron;
}
Also used : CronTrigger(org.quartz.CronTrigger)

Example 62 with CronTrigger

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

the class QuartzEndpointConfigureTest method testConfigureAnotherCronExpression.

@Test
public void testConfigureAnotherCronExpression() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myTimerName?cron=0+0+*+*+*+?");
    CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
    assertEquals("getName()", "myTimerName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
    assertEquals("cron expression", "0 0 * * * ?", trigger.getCronExpression());
    // default job name
    assertEquals("getJobName", "quartz-" + endpoint.getId(), endpoint.getJobName());
}
Also used : CronTrigger(org.quartz.CronTrigger) Test(org.junit.Test)

Example 63 with CronTrigger

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

the class QuartzEndpointConfigureTest method testConfigureJobName.

@Test
public void testConfigureJobName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myTimerName?job.name=hadrian&cron=0+0+*+*+*+?");
    CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
    assertEquals("getName()", "myTimerName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
    assertEquals("cron expression", "0 0 * * * ?", trigger.getCronExpression());
    assertEquals("getJobName", "hadrian", endpoint.getJobName());
}
Also used : CronTrigger(org.quartz.CronTrigger) Test(org.junit.Test)

Example 64 with CronTrigger

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

the class QuartzEndpointConfigureTest method testConfigureNoDoubleSlashQuestionCron.

@Test
public void testConfigureNoDoubleSlashQuestionCron() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz:myGroup/myTimerName?cron=0+0+*+*+*+?");
    CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
    assertEquals("getName()", "myTimerName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
    assertEquals("cron expression", "0 0 * * * ?", trigger.getCronExpression());
}
Also used : CronTrigger(org.quartz.CronTrigger) Test(org.junit.Test)

Example 65 with CronTrigger

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

the class QuartzEndpoint method createTrigger.

private Trigger createTrigger(JobDetail jobDetail) throws Exception {
    Trigger result;
    Date startTime = new Date();
    if (getComponent().getScheduler().isStarted()) {
        startTime = new Date(System.currentTimeMillis() + triggerStartDelay);
    }
    if (cron != null) {
        LOG.debug("Creating CronTrigger: {}", cron);
        String timeZone = (String) triggerParameters.get("timeZone");
        if (timeZone != null) {
            if (ObjectHelper.isNotEmpty(customCalendar)) {
                result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed().inTimeZone(TimeZone.getTimeZone(timeZone))).modifiedByCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR).build();
            } else {
                result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed().inTimeZone(TimeZone.getTimeZone(timeZone))).build();
            }
            jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE, timeZone);
        } else {
            if (ObjectHelper.isNotEmpty(customCalendar)) {
                result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed()).modifiedByCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR).build();
            } else {
                result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed()).build();
            }
        }
        // enrich job map with details
        jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
        jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, cron);
    } else {
        LOG.debug("Creating SimpleTrigger.");
        int repeat = SimpleTrigger.REPEAT_INDEFINITELY;
        String repeatString = (String) triggerParameters.get("repeatCount");
        if (repeatString != null) {
            repeat = EndpointHelper.resolveParameter(getCamelContext(), repeatString, Integer.class);
            // need to update the parameters
            triggerParameters.put("repeatCount", repeat);
        }
        // default use 1 sec interval
        long interval = 1000;
        String intervalString = (String) triggerParameters.get("repeatInterval");
        if (intervalString != null) {
            interval = EndpointHelper.resolveParameter(getCamelContext(), intervalString, Long.class);
            // need to update the parameters
            triggerParameters.put("repeatInterval", interval);
        }
        TriggerBuilder<SimpleTrigger> triggerBuilder;
        if (ObjectHelper.isNotEmpty(customCalendar)) {
            triggerBuilder = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow().withRepeatCount(repeat).withIntervalInMilliseconds(interval)).modifiedByCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR);
        } else {
            triggerBuilder = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow().withRepeatCount(repeat).withIntervalInMilliseconds(interval));
        }
        if (fireNow) {
            triggerBuilder = triggerBuilder.startNow();
        }
        result = triggerBuilder.build();
        // enrich job map with details
        jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "simple");
        jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER, repeat);
        jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL, interval);
    }
    if (triggerParameters != null && triggerParameters.size() > 0) {
        LOG.debug("Setting user extra triggerParameters {}", triggerParameters);
        setProperties(result, triggerParameters);
    }
    LOG.debug("Created trigger={}", result);
    return result;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger) Date(java.util.Date) UriEndpoint(org.apache.camel.spi.UriEndpoint) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint)

Aggregations

CronTrigger (org.quartz.CronTrigger)103 JobDetail (org.quartz.JobDetail)42 Trigger (org.quartz.Trigger)36 SimpleTrigger (org.quartz.SimpleTrigger)29 SchedulerException (org.quartz.SchedulerException)28 Test (org.junit.Test)24 Scheduler (org.quartz.Scheduler)19 TriggerKey (org.quartz.TriggerKey)19 Date (java.util.Date)14 JobKey (org.quartz.JobKey)12 JobDataMap (org.quartz.JobDataMap)11 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 CronScheduleBuilder (org.quartz.CronScheduleBuilder)8 ParseException (java.text.ParseException)7 HashMap (java.util.HashMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 JobExecutionException (org.quartz.JobExecutionException)6 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)5 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)5