Search in sources :

Example 66 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("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 67 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("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 68 with CronTrigger

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

the class QuartzStatefulJobRouteTest 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(StatefulCamelJob.class), 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 69 with CronTrigger

use of org.quartz.CronTrigger in project jforum2 by rafaelsteil.

the class POPJobStarter method startJob.

public static void startJob() throws SchedulerException {
    boolean isEnabled = SystemGlobals.getBoolValue(ConfigKeys.MAIL_POP3_INTEGRATION_ENABLED);
    if (!isStarted && isEnabled) {
        String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
        String cronExpression = SystemGlobals.getValue("org.quartz.context.mailintegration.cron.expression");
        scheduler = new StdSchedulerFactory(filename).getScheduler();
        Trigger trigger = null;
        try {
            trigger = new CronTrigger(POPListener.class.getName(), "pop3Integration", cronExpression);
            logger.info("Starting POP3 integration expression " + cronExpression);
            scheduler.scheduleJob(new JobDetail(POPListener.class.getName(), "pop3Integration", POPListener.class), trigger);
            scheduler.start();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    isStarted = true;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) ParseException(java.text.ParseException)

Example 70 with CronTrigger

use of org.quartz.CronTrigger in project iaf by ibissource.

the class SchedulerAdapter method triggerToXmlBuilder.

public XmlBuilder triggerToXmlBuilder(Scheduler theScheduler, String triggerName, String groupName) {
    XmlBuilder xbRoot = new XmlBuilder("triggerDetail");
    try {
        Trigger trigger = theScheduler.getTrigger(triggerName, groupName);
        xbRoot.addAttribute("fullName", trigger.getFullName());
        xbRoot.addAttribute("triggerName", trigger.getName());
        xbRoot.addAttribute("triggerGroup", trigger.getGroup());
        String cn = trigger.getCalendarName();
        xbRoot.addAttribute("calendarName", (cn == null ? "none" : cn));
        Date date;
        try {
            date = trigger.getEndTime();
            xbRoot.addAttribute("endTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getFinalFireTime();
            xbRoot.addAttribute("finalFireTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getPreviousFireTime();
            xbRoot.addAttribute("previousFireTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getNextFireTime();
            xbRoot.addAttribute("nextFireTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getStartTime();
            xbRoot.addAttribute("startTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        xbRoot.addAttribute("misfireInstruction", Integer.toString(trigger.getMisfireInstruction()));
        if (trigger instanceof CronTrigger) {
            xbRoot.addAttribute("triggerType", "cron");
            xbRoot.addAttribute("cronExpression", ((CronTrigger) trigger).getCronExpression());
        } else if (trigger instanceof SimpleTrigger) {
            xbRoot.addAttribute("triggerType", "simple");
            xbRoot.addAttribute("repeatInterval", ((SimpleTrigger) trigger).getRepeatInterval());
        } else {
            xbRoot.addAttribute("triggerType", "unknown");
        }
        xbRoot.addAttribute("jobGroup", trigger.getJobGroup());
        xbRoot.addAttribute("jobName", trigger.getJobName());
        xbRoot.addAttribute("isVolatile", (trigger.isVolatile() ? "True" : "False"));
    } catch (SchedulerException se) {
        log.error(se);
    }
    return xbRoot;
}
Also used : CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) SimpleTrigger(org.quartz.SimpleTrigger) Date(java.util.Date) SchedulerException(org.quartz.SchedulerException)

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