use of org.exist.scheduler.JobDescription in project exist by eXist-db.
the class QuartzSchedulerImpl method setupConfiguredJobs.
/**
* Set's up all the jobs that are listed in conf.xml and loaded through org.exist.util.Configuration.
*/
@Override
public void setupConfiguredJobs() {
final JobConfig[] jobList = (JobConfig[]) config.getProperty(JobConfig.PROPERTY_SCHEDULER_JOBS);
if (jobList == null) {
return;
}
for (final JobConfig jobConfig : jobList) {
JobDescription job = null;
if (jobConfig.getResourceName().startsWith("/db/") || jobConfig.getResourceName().indexOf(':') > 0) {
if (jobConfig.getType().equals(JobType.SYSTEM)) {
LOG.error("System jobs may only be written in Java");
} else {
// create an XQuery job
final Subject guestUser = brokerPool.getSecurityManager().getGuestSubject();
job = new UserXQueryJob(jobConfig.getJobName(), jobConfig.getResourceName(), guestUser);
try {
// check if a job with the same name is already registered
if (getScheduler().getJobDetail(new JobKey(job.getName(), UserJob.JOB_GROUP)) != null) {
// yes, try to make the job's name unique
job.setName(job.getName() + job.hashCode());
}
} catch (final SchedulerException e) {
LOG.error("Unable to set job name: {}", e.getMessage(), e);
}
}
} else {
// create a Java job
try {
final Class<?> jobClass = Class.forName(jobConfig.getResourceName());
final Object jobObject = jobClass.newInstance();
if (jobConfig.getType().equals(JobType.SYSTEM)) {
if (jobObject instanceof SystemTask) {
final SystemTask task = (SystemTask) jobObject;
task.configure(config, jobConfig.getParameters());
job = new SystemTaskJobImpl(jobConfig.getJobName(), task);
} else {
LOG.error("System jobs must extend SystemTask");
// throw exception? will be handled nicely
}
} else {
if (jobObject instanceof JobDescription) {
job = (JobDescription) jobObject;
if (jobConfig.getJobName() != null) {
job.setName(jobConfig.getJobName());
}
} else {
LOG.error("Startup job {} must extend org.exist.scheduler.StartupJob", jobConfig.getJobName());
// throw exception? will be handled nicely
}
}
} catch (final Exception e) {
// Throwable?
LOG.error("Unable to schedule '{}' job {}: {}", jobConfig.getType(), jobConfig.getResourceName(), e.getMessage(), e);
}
}
// if there is a job, schedule it
if (job != null) {
// trigger is Cron or period?
if (jobConfig.getSchedule().indexOf(' ') > -1) {
// schedule job with Cron trigger
createCronJob(jobConfig.getSchedule(), job, jobConfig.getParameters());
} else {
// schedule job with periodic trigger
createPeriodicJob(Long.parseLong(jobConfig.getSchedule()), job, jobConfig.getDelay(), jobConfig.getParameters(), jobConfig.getRepeat(), jobConfig.unscheduleOnException());
}
}
}
}
Aggregations