Search in sources :

Example 56 with CronTrigger

use of org.quartz.CronTrigger in project pentaho-platform by pentaho.

the class QuartzSchedulerTest method testSetTimezone.

@Test
public void testSetTimezone() throws Exception {
    CronTrigger cronTrigger = new CronTrigger();
    cronTrigger.setCronExpression(new CronExpression("0 15 10 ? * 6L 2002-2018"));
    String currentTimezoneId = TimeZone.getDefault().getID();
    new QuartzScheduler().setTimezone(cronTrigger, currentTimezoneId);
    assertNotNull(cronTrigger.getTimeZone());
    assertEquals(currentTimezoneId, cronTrigger.getTimeZone().getID());
}
Also used : CronTrigger(org.quartz.CronTrigger) CronExpression(org.quartz.CronExpression) Test(org.junit.Test)

Example 57 with CronTrigger

use of org.quartz.CronTrigger in project weicoder by wdcode.

the class CronTriggerSupport method toTabularData.

public static TabularData toTabularData(List<? extends CronTrigger> triggers) {
    TabularData tData = new TabularDataSupport(TABULAR_TYPE);
    if (triggers != null) {
        ArrayList<CompositeData> list = new ArrayList<CompositeData>();
        for (CronTrigger trigger : triggers) {
            list.add(toCompositeData(trigger));
        }
        tData.putAll(list.toArray(new CompositeData[list.size()]));
    }
    return tData;
}
Also used : CronTrigger(org.quartz.CronTrigger) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) TabularData(javax.management.openmbean.TabularData)

Example 58 with CronTrigger

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

the class MpdBinding method scheduleReconnect.

private void scheduleReconnect() {
    Scheduler sched;
    try {
        sched = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(ReconnectJob.class).withIdentity("Reconnect", MPD_SCHEDULER_GROUP).build();
        CronTrigger trigger = newTrigger().withIdentity("Reconnect", MPD_SCHEDULER_GROUP).withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?")).build();
        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled a daily reconnect of all MPDs");
    } catch (SchedulerException se) {
        logger.warn("Scheduling MPD reconnect failed", se);
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 59 with CronTrigger

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

the class FritzboxBinding method updated.

/**
     * {@inheritDoc}
     */
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        String ip = Objects.toString(config.get("ip"), null);
        if (StringUtils.isNotBlank(ip)) {
            if (!ip.equals(FritzboxBinding.ip)) {
                // only do something if the ip has changed
                FritzboxBinding.ip = ip;
                conditionalDeActivate();
                // and thus blocks the monitor thread
                try {
                    Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
                    JobKey jobKey = jobKey("Reconnect", "FritzBox");
                    TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox");
                    if (sched.checkExists(jobKey)) {
                        logger.debug("Daily reconnection job already exists");
                    } else {
                        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronSchedule);
                        JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build();
                        CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
                        sched.scheduleJob(job, trigger);
                        logger.debug("Scheduled a daily reconnection to FritzBox on {}:{}", ip, MONITOR_PORT);
                    }
                } catch (SchedulerException e) {
                    logger.warn("Could not create daily reconnection job", e);
                }
            }
        }
        String password = Objects.toString(config.get("password"), null);
        if (StringUtils.isNotBlank(password)) {
            FritzboxBinding.password = password;
        }
        String username = Objects.toString(config.get("user"), null);
        if (StringUtils.isNotBlank(username)) {
            FritzboxBinding.username = username;
        }
    }
}
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 60 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)

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