Search in sources :

Example 31 with CronTrigger

use of org.quartz.CronTrigger in project openhab1-addons by openhab.

the class CallMonitor method setupReconnectJob.

/***
     * reset the connection to fbox periodically
     */
public void setupReconnectJob() {
    try {
        // String cronPattern = "0 0 0 * * ?"; //every day
        // String cronPattern = "0 * * * * ?"; //every minute
        // every 2 hrs
        String cronPattern = "0 0 0/2 * * ?";
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        JobKey jobKey = jobKey("Reconnect", "FritzBox");
        TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox");
        if (sched.checkExists(jobKey)) {
            logger.debug("reconnection job already exists");
        } else {
            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronPattern);
            JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build();
            CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
            sched.scheduleJob(job, trigger);
            logger.debug("Scheduled reconnection job to FritzBox: {}", cronPattern);
        }
    } catch (SchedulerException e) {
        logger.warn("Could not create daily reconnection job", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 32 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 33 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 34 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 35 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)

Aggregations

CronTrigger (org.quartz.CronTrigger)43 JobDetail (org.quartz.JobDetail)21 Test (org.junit.Test)17 Trigger (org.quartz.Trigger)15 SchedulerException (org.quartz.SchedulerException)13 Scheduler (org.quartz.Scheduler)12 SimpleTrigger (org.quartz.SimpleTrigger)12 TriggerKey (org.quartz.TriggerKey)7 JobKey (org.quartz.JobKey)5 Date (java.util.Date)4 CamelContext (org.apache.camel.CamelContext)4 JobDataMap (org.quartz.JobDataMap)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 CronScheduleBuilder (org.quartz.CronScheduleBuilder)2 JobExecutionException (org.quartz.JobExecutionException)2