/**
* @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);
// check run on information
final String[] runOn = (String[])data.get(QuartzScheduler.DATA_MAP_RUN_ON);
if ( runOn != null ) {
if ( runOn.length == 1 && Scheduler.VALUE_RUN_ON_LEADER.equals(runOn[0])
|| runOn.length == 1 && Scheduler.VALUE_RUN_ON_SINGLE.equals(runOn[0]) ) {
if ( DISCOVERY_INFO_AVAILABLE.get() ) {
if ( !IS_LEADER.get() ) {
logger.debug("Excluding job {} with name {} and config {}.",
new Object[] {job, data.get(QuartzScheduler.DATA_MAP_NAME), runOn[0]});
return;
}
} else {
logger.warn("No discovery info available. Executing job {} with name {} and config {} anyway.",
new Object[] {job, data.get(QuartzScheduler.DATA_MAP_NAME), runOn[0]});
}
} else { // sling IDs
final String myId = SLING_ID;
boolean schedule = false;
if ( myId == null ) {
logger.warn("No Sling ID available. Executing job {} with name {} and config {} anyway.",
new Object[] {job, data.get(QuartzScheduler.DATA_MAP_NAME), Arrays.toString(runOn)});
schedule = true;
} else {
for(final String id : runOn ) {
if ( myId.equals(id) ) {
schedule = true;
break;
}
}
}
if ( !schedule ) {
logger.debug("Excluding job {} with name {} and config {}.",
new Object[] {job, data.get(QuartzScheduler.DATA_MAP_NAME), Arrays.toString(runOn)});
return;
}
}
}
try {
logger.debug("Executing job {} with name {}", job, data.get(QuartzScheduler.DATA_MAP_NAME));
if (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 String name = (String) data.get(QuartzScheduler.DATA_MAP_NAME);
final JobContext jobCtx = new JobContextImpl(name, configuration);
((org.apache.sling.commons.scheduler.Job) job).execute(jobCtx);
} else if (job instanceof Runnable) {
((Runnable) job).run();