private static Method method;
@Override
public void execute(final JobExecutionContext execution) throws JobExecutionException {
MessageEndpoint endpoint = null;
JobExecutionException ex = null;
try {
final JobDataMap jobDataMap = execution.getJobDetail().getJobDataMap();
final Data data = Data.class.cast(jobDataMap.get(Data.class.getName()));
final Job job = data.job;
if (null == method) {
method = job.getClass().getMethod("execute", JobExecutionContext.class);
}
endpoint = (MessageEndpoint) job;
endpoint.beforeDelivery(method);
job.execute(execution);
} catch (final NoSuchMethodException e) {
throw new IllegalStateException(e);
} catch (final ResourceException e) {
ex = new JobExecutionException(e);
} catch (final Throwable t) {
ex = new JobExecutionException(new Exception(t));
} finally {
if (null != endpoint) {
try {
endpoint.afterDelivery();
} catch (final ResourceException e) {
ex = new JobExecutionException(e);
}
}
}