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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations