use of org.apache.karaf.scheduler.SchedulerError in project karaf by apache.
the class QuartzScheduler method trigger.
@Override
public boolean trigger(String jobName) throws SchedulerError {
final org.quartz.Scheduler s = this.scheduler;
if (jobName != null && s != null) {
try {
final JobKey key = JobKey.jobKey(jobName);
final JobDetail jobdetail = s.getJobDetail(key);
if (jobdetail != null) {
this.scheduler.triggerJob(key, jobdetail.getJobDataMap());
return true;
}
} catch (SchedulerException ex) {
throw new SchedulerError(ex);
}
}
return false;
}
use of org.apache.karaf.scheduler.SchedulerError in project karaf by apache.
the class QuartzScheduler method schedule.
/**
* Schedule a job
* @see org.apache.karaf.scheduler.Scheduler#schedule(java.lang.Object, org.apache.karaf.scheduler.ScheduleOptions)
* @throws SchedulerError if the job can't be scheduled
* @throws IllegalArgumentException If the preconditions are not met
*/
public void schedule(final Object job, final ScheduleOptions options) throws IllegalArgumentException, SchedulerError {
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;
// as this method might be called from unbind and during
// unbind a deactivate could happen, we check the scheduler first
final org.quartz.Scheduler s = this.scheduler;
if (s == null) {
throw new IllegalStateException("Scheduler is not available anymore.");
}
final String name;
if (opts.name != null) {
// if there is already a job with the name, remove it first
try {
final JobKey key = JobKey.jobKey(opts.name);
final JobDetail jobdetail = s.getJobDetail(key);
if (jobdetail != null) {
s.deleteJob(key);
this.logger.debug("Unscheduling job with name {}", opts.name);
}
} catch (final SchedulerException ignored) {
// ignore
}
name = opts.name;
} else {
name = job.getClass().getName() + ':' + UUID.randomUUID();
opts.name = name;
}
final Trigger trigger = opts.compile().withIdentity(name).build();
// create the data map
final JobDataMap jobDataMap = this.initDataMap(name, job, opts);
final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);
this.logger.debug("Scheduling job {} with name {} and trigger {}", job, name, trigger);
try {
s.scheduleJob(detail, trigger);
} catch (SchedulerException ex) {
throw new SchedulerError(ex);
}
}
use of org.apache.karaf.scheduler.SchedulerError in project openk9 by smclab.
the class DriverManagerActivator method _schedule.
private Mono<Void> _schedule(Datasource datasource) {
return Mono.create(sink -> {
try {
Map<String, ScheduleOptions> jobs = _scheduler.getJobs();
String jobName = _PREFIX + datasource.getName();
ScheduleOptions scheduleOptions = jobs.get(jobName);
if (scheduleOptions != null) {
_scheduler.unschedule(jobName);
}
_scheduler.schedule(_createJob(datasource.getDriverServiceName(), datasource.getDatasourceId()), _scheduler.EXPR(datasource.getScheduling()).name(jobName));
_scheduler.trigger(jobName);
sink.success();
} catch (SchedulerError schedulerError) {
sink.error(schedulerError);
}
});
}
use of org.apache.karaf.scheduler.SchedulerError in project karaf by apache.
the class QuartzScheduler method reschedule.
@Override
public void reschedule(String jobName, ScheduleOptions options) throws SchedulerError {
final org.quartz.Scheduler s = this.scheduler;
if (jobName == null) {
throw new IllegalArgumentException("Job name is mandatory");
}
JobKey key = JobKey.jobKey(jobName);
if (key == null) {
throw new IllegalStateException("No job found with name " + jobName);
}
try {
JobDetail detail = s.getJobDetail(key);
final String contextKey = key.toString();
JobDataMap karafContext = ((KarafStdScheduler) s).getStorage().get(contextKey);
Object job = karafContext.get(QuartzScheduler.DATA_MAP_OBJECT);
s.deleteJob(key);
final InternalScheduleOptions opts = (InternalScheduleOptions) options;
Trigger trigger = opts.compile().withIdentity(jobName).build();
JobDataMap jobDataMap = this.initDataMap(jobName, job, opts);
detail = createJobDetail(jobName, jobDataMap, opts.canRunConcurrently);
logger.debug("Update job scheduling {} with name {} and trigger {}", job, jobName, trigger);
s.scheduleJob(detail, trigger);
} catch (SchedulerException e) {
throw new SchedulerError(e);
}
}
use of org.apache.karaf.scheduler.SchedulerError in project karaf by apache.
the class QuartzScheduler method getJobs.
@Override
public Map<String, ScheduleOptions> getJobs() throws SchedulerError {
try {
Map<String, ScheduleOptions> jobs = new HashMap<>();
org.quartz.Scheduler s = this.scheduler;
if (s != null) {
for (String group : s.getJobGroupNames()) {
for (JobKey key : s.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
JobDetail detail = s.getJobDetail(key);
ScheduleOptions options = (ScheduleOptions) detail.getJobDataMap().get(DATA_MAP_OPTIONS);
jobs.put(key.getName(), options);
}
}
}
return jobs;
} catch (SchedulerException ex) {
throw new SchedulerError(ex);
}
}
Aggregations