Search in sources :

Example 36 with JobDataMap

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

the class AbstractBaseJob method execute.

@Override
public void execute(JobExecutionContext jobContext) throws JobExecutionException {
    JobDataMap jobDataMap = jobContext.getJobDetail().getJobDataMap();
    if (logger.isDebugEnabled()) {
        String itemName = jobDataMap.getString("itemName");
        if (itemName != null) {
            logger.debug("Starting Astro {} for item {}", this.getClass().getSimpleName(), itemName);
        } else {
            logger.debug("Starting Astro {}", this.getClass().getSimpleName());
        }
    }
    executeJob(jobDataMap);
}
Also used : JobDataMap(org.quartz.JobDataMap)

Example 37 with JobDataMap

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

the class JobScheduler method scheduleIntervalJob.

/**
     * Schedules the IntervalJob with the specified interval and starts it
     * immediately.
     */
public void scheduleIntervalJob() {
    AstroConfig config = context.getConfig();
    String jobName = IntervalJob.class.getSimpleName();
    Date start = new Date(System.currentTimeMillis() + (config.getInterval()) * 1000);
    Trigger trigger = newTrigger().withIdentity(jobName + "-Trigger", JOB_GROUP).startAt(start).withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(config.getInterval())).build();
    schedule(jobName, IntervalJob.class, trigger, new JobDataMap());
    logger.info("Scheduled astro job with interval of {} seconds", config.getInterval());
}
Also used : JobDataMap(org.quartz.JobDataMap) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) AstroConfig(org.openhab.binding.astro.internal.common.AstroConfig) Date(java.util.Date)

Example 38 with JobDataMap

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

the class JobScheduler method scheduleItem.

/**
     * Schedules a item job at the specified date/time from the calendar object.
     */
public void scheduleItem(Calendar calendar, String itemName) {
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put("itemName", itemName);
    schedule(calendar, itemName, jobDataMap, ItemJob.class);
}
Also used : JobDataMap(org.quartz.JobDataMap)

Example 39 with JobDataMap

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

the class JobScheduler method scheduleSeasonJob.

/**
     * Schedules next Season job.
     */
public void scheduleSeasonJob(Season season) {
    Calendar nextSeason = season.getNextSeason();
    if (nextSeason == null) {
        nextSeason = DateTimeUtils.getFirstDayOfNextYear();
    }
    schedule(nextSeason, "Season", new JobDataMap(), SeasonJob.class);
}
Also used : JobDataMap(org.quartz.JobDataMap) Calendar(java.util.Calendar)

Example 40 with JobDataMap

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

the class QuartzManuallyTriggerJobTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    QuartzComponent component = context.getComponent("quartz2", QuartzComponent.class);
    Scheduler scheduler = component.getScheduler();
    // collect all jobKeys of this route (ideally only one).
    ArrayList<JobKey> jobKeys = new ArrayList<JobKey>();
    for (String group : scheduler.getJobGroupNames()) {
        for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
            jobKeys.add(jobKey);
        }
    }
    JobDataMap jobDataMap = scheduler.getJobDetail(jobKeys.get(0)).getJobDataMap();
    // trigger job manually
    scheduler.triggerJob(jobKeys.get(0), jobDataMap);
    assertMockEndpointsSatisfied();
}
Also used : JobKey(org.quartz.JobKey) JobDataMap(org.quartz.JobDataMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

JobDataMap (org.quartz.JobDataMap)56 Trigger (org.quartz.Trigger)21 SchedulerException (org.quartz.SchedulerException)20 JobDetail (org.quartz.JobDetail)18 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 Scheduler (org.quartz.Scheduler)10 JobExecutionException (org.quartz.JobExecutionException)9 ApplicationContext (org.springframework.context.ApplicationContext)9 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6 TriggerBean (org.akaza.openclinica.bean.admin.TriggerBean)6 Command (org.openhab.core.types.Command)5 SchedulerContext (org.quartz.SchedulerContext)5 SimpleTrigger (org.quartz.SimpleTrigger)5 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 Locale (java.util.Locale)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4