Search in sources :

Example 1 with JobContext

use of org.apache.karaf.scheduler.JobContext in project karaf by apache.

the class QuartzJobExecutor method execute.

/**
     * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
     */
public void execute(final JobExecutionContext context) throws JobExecutionException {
    final JobDataMap data = context.getJobDetail().getJobDataMap();
    final Object job = data.get(QuartzScheduler.DATA_MAP_OBJECT);
    final Logger logger = (Logger) data.get(QuartzScheduler.DATA_MAP_LOGGER);
    try {
        logger.debug("Executing job {} with name {}", job, data.get(QuartzScheduler.DATA_MAP_NAME));
        if (job instanceof org.apache.karaf.scheduler.Job) {
            @SuppressWarnings("unchecked") final InternalScheduleOptions options = (InternalScheduleOptions) data.get(QuartzScheduler.DATA_MAP_OPTIONS);
            final String name = (String) data.get(QuartzScheduler.DATA_MAP_NAME);
            final JobContext jobCtx = new JobContextImpl(name, options.configuration);
            ((org.apache.karaf.scheduler.Job) job).execute(jobCtx);
        } else if (job instanceof Runnable) {
            ((Runnable) job).run();
        } else {
            logger.error("Scheduled job {} is neither a job nor a runnable.", job);
        }
    } catch (final Throwable t) {
        // there is nothing we can do here, so we just log
        logger.error("Exception during job execution of " + job + " : " + t.getMessage(), t);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Logger(org.slf4j.Logger) JobContext(org.apache.karaf.scheduler.JobContext) Job(org.quartz.Job)

Aggregations

JobContext (org.apache.karaf.scheduler.JobContext)1 Job (org.quartz.Job)1 JobDataMap (org.quartz.JobDataMap)1 Logger (org.slf4j.Logger)1