Search in sources :

Example 1 with JobContext

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Serializable(java.io.Serializable) Logger(org.slf4j.Logger) JobExecutionException(org.quartz.JobExecutionException) JobContext(org.apache.sling.commons.scheduler.JobContext) Job(org.quartz.Job) JobDataMap(org.quartz.JobDataMap) Map(java.util.Map)

Aggregations

Serializable (java.io.Serializable)1 Map (java.util.Map)1 JobContext (org.apache.sling.commons.scheduler.JobContext)1 Job (org.quartz.Job)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1 Logger (org.slf4j.Logger)1