Search in sources :

Example 51 with JobDataMap

use of org.quartz.JobDataMap in project oxCore by GluuFederation.

the class QuartzSchedulerManager method schedule.

public void schedule(@Observes TimerEvent timerEvent) {
    checkInitialized();
    JobDataMap dataMap = new JobDataMap();
    dataMap.put(TimerJob.KEY_TIMER_EVENT, timerEvent);
    String uuid = UUID.randomUUID().toString();
    JobDetail timerJob = JobBuilder.newJob(TimerJob.class).withIdentity(TimerJob.class.getSimpleName() + "_" + uuid, TimerJob.TIMER_JOB_GROUP).usingJobData(dataMap).build();
    TimerSchedule timerSchedule = timerEvent.getSchedule();
    Date triggerStartTime = new Date(System.currentTimeMillis() + timerSchedule.getDelay() * 1000L);
    Trigger timerTrigger = TriggerBuilder.newTrigger().withIdentity(uuid, TimerJob.TIMER_JOB_GROUP).startAt(triggerStartTime).withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(timerSchedule.getInterval())).build();
    try {
        scheduler.scheduleJob(timerJob, timerTrigger);
    } catch (SchedulerException ex) {
        throw new IllegalStateException("Failed to schedule Timer Event", ex);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) TimerSchedule(org.xdi.service.timer.schedule.TimerSchedule) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) Date(java.util.Date)

Example 52 with JobDataMap

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

the class QuartzScheduler method initDataMap.

/**
     * Initialize the data map for the job executor.
     */
private JobDataMap initDataMap(final String jobName, final Object job, final InternalScheduleOptions options) {
    final JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put(DATA_MAP_OBJECT, job);
    jobDataMap.put(DATA_MAP_NAME, jobName);
    jobDataMap.put(DATA_MAP_LOGGER, this.logger);
    jobDataMap.put(DATA_MAP_OPTIONS, options);
    return jobDataMap;
}
Also used : JobDataMap(org.quartz.JobDataMap)

Example 53 with JobDataMap

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

the class QuartzScheduler method initDataMap.

/**
     * Initialize the data map for the job executor.
     * @param jobName
     * @param job
     * @param config
     * @param concurent
     * @return
     */
private JobDataMap initDataMap(final Long bundleId, final Long serviceId, final String jobName, final Object job, final InternalScheduleOptions options) {
    final JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put(DATA_MAP_OBJECT, job);
    if (options.providedName != null) {
        jobDataMap.put(DATA_MAP_PROVIDED_NAME, options.providedName);
    }
    jobDataMap.put(DATA_MAP_NAME, jobName);
    jobDataMap.put(DATA_MAP_LOGGER, this.logger);
    if (bundleId != null) {
        jobDataMap.put(DATA_MAP_BUNDLE_ID, bundleId);
    }
    if (serviceId != null) {
        jobDataMap.put(DATA_MAP_SERVICE_ID, serviceId);
    }
    if (options.configuration != null) {
        jobDataMap.put(DATA_MAP_CONFIGURATION, options.configuration);
    }
    if (options.runOn != null) {
        if (options.runOn.length > 1 || (!Scheduler.VALUE_RUN_ON_LEADER.equals(options.runOn[0]) && !Scheduler.VALUE_RUN_ON_SINGLE.equals(options.runOn[0]))) {
            logger.warn("Job {} ({}) is scheduled to run on specific Sling Instances. This feature is deprecated. Please don't use it anymore.", jobName, job);
        }
        jobDataMap.put(DATA_MAP_RUN_ON, options.runOn);
    }
    return jobDataMap;
}
Also used : JobDataMap(org.quartz.JobDataMap)

Example 54 with JobDataMap

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

the class QuartzScheduler method scheduleJob.

/**
     * Internal method to schedule a job
     * @throws SchedulerException if the job can't be scheduled
     * @throws IllegalArgumentException If the preconditions are not met
     */
private void scheduleJob(final Long bundleId, final Long serviceId, final Object job, final ScheduleOptions options) throws SchedulerException {
    this.checkJob(job);
    if (!(options instanceof InternalScheduleOptions)) {
        throw new IllegalArgumentException("Options has not been created via schedule or is null.");
    }
    final InternalScheduleOptions opts = (InternalScheduleOptions) options;
    if (opts.argumentException != null) {
        throw opts.argumentException;
    }
    // as this method might be called from unbind and during
    // unbind a deactivate could happen, we check the scheduler first
    final SchedulerProxy proxy = this.getScheduler(opts.threadPoolName);
    if (proxy == null) {
        throw new IllegalStateException("Scheduler is not available anymore.");
    }
    synchronized (proxy) {
        opts.providedName = opts.name;
        final String name;
        if (opts.name != null) {
            // if there is already a job with the name, remove it first
            this.unschedule(bundleId, opts.name);
            name = opts.name;
        } else {
            name = job.getClass().getName() + ':' + UUID.randomUUID();
        }
        final Trigger trigger = opts.trigger.withIdentity(name).build();
        // create the data map
        final JobDataMap jobDataMap = this.initDataMap(bundleId, serviceId, name, job, opts);
        final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);
        this.logger.debug("Scheduling job {} with name {} and trigger {}", new Object[] { job, name, trigger });
        proxy.getScheduler().scheduleJob(detail, trigger);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger)

Example 55 with JobDataMap

use of org.quartz.JobDataMap in project ddf by codice.

the class CommandJobTest method getJobExecutionContext.

private JobExecutionContext getJobExecutionContext(String command) {
    JobExecutionContext context = mock(JobExecutionContext.class);
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put(CommandJob.COMMAND_KEY, command);
    when(context.getMergedJobDataMap()).thenReturn(jobDataMap);
    return context;
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionContext(org.quartz.JobExecutionContext)

Aggregations

JobDataMap (org.quartz.JobDataMap)59 Trigger (org.quartz.Trigger)21 JobDetail (org.quartz.JobDetail)20 SchedulerException (org.quartz.SchedulerException)20 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