use of org.apache.sling.commons.scheduler.JobContext in project sling by apache.
the class QuartzJobExecutor method execute.
/**
* @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
*/
@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
final JobDataMap data = context.getJobDetail().getJobDataMap();
final JobDesc desc = new JobDesc(data);
final Logger logger = (Logger) data.get(QuartzScheduler.DATA_MAP_LOGGER);
// check run on information
if (!shouldRun(logger, desc)) {
return;
}
String origThreadName = Thread.currentThread().getName();
try {
Thread.currentThread().setName(origThreadName + "-" + desc.name);
logger.debug("Executing job {}", desc);
if (desc.job instanceof org.apache.sling.commons.scheduler.Job) {
@SuppressWarnings("unchecked") final Map<String, Serializable> configuration = (Map<String, Serializable>) data.get(QuartzScheduler.DATA_MAP_CONFIGURATION);
final JobContext jobCtx = new JobContextImpl(desc.name, configuration);
((org.apache.sling.commons.scheduler.Job) desc.job).execute(jobCtx);
} else if (desc.job instanceof Runnable) {
((Runnable) desc.job).run();
} else {
logger.error("Scheduled job {} is neither a job nor a runnable: {}", desc);
}
} catch (final Throwable t) {
// if this is a quartz exception, rethrow it
if (t instanceof JobExecutionException) {
throw (JobExecutionException) t;
}
// there is nothing we can do here, so we just log
logger.error("Exception during job execution of " + desc + " : " + t.getMessage(), t);
} finally {
Thread.currentThread().setName(origThreadName);
}
}
Aggregations