@Component public class MailListenerBeanPostProcessor implements BeanPostProcessor { @Autowired private MailListener listener; @Override public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { return bean; } @Override public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { if (bean instanceof AbstractJob) { final AbstractJob job = (AbstractJob) bean; job.registerJobExecutionListener(listener); } return bean; } }
private void registerJobExecutionEventListener(Object bean) { if (bean instanceof AbstractJob && this.applicationContext.containsBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER)) { JobExecutionListener jobExecutionEventsListener = (JobExecutionListener) this.applicationContext.getBean( BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER); AbstractJob job = (AbstractJob) bean; job.registerJobExecutionListener( jobExecutionEventsListener); } }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if(jobNames.size() > 0 && !jobNames.contains(beanName)) { return bean; } int length = this.applicationContext .getBeanNamesForType(TaskBatchExecutionListener.class).length; if(bean instanceof AbstractJob) { if(length != 1) { throw new IllegalStateException("The application context is required to " + "have exactly 1 instance of the TaskBatchExecutionListener but has " + length); } ((AbstractJob) bean).registerJobExecutionListener( this.applicationContext.getBean(TaskBatchExecutionListener.class)); } return bean; }
protected void injectStatusListener(final Job job, final ApplicationContext applicationContext) { if (job instanceof AbstractJob) { AbstractJob abstractJob = (AbstractJob) job; JobExecutionListener listener = new ProcessJobExecutionListener(this, applicationContext); abstractJob.registerJobExecutionListener(listener); abstractJob.registerJobExecutionListener(new TriggerStateHolderAwareJobExecutionListener(this.stateHolder, applicationContext)); abstractJob.registerJobExecutionListener(new ProblemHandlerAwareJobExecutionListener(applicationContext)); } }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if(jobNames.size() > 0 && !jobNames.contains(beanName)) { return bean; } int length = this.applicationContext .getBeanNamesForType(TaskBatchExecutionListener.class).length; if(bean instanceof AbstractJob) { if(length != 1) { throw new IllegalStateException("The application context is required to " + "have exactly 1 instance of the TaskBatchExecutionListener but has " + length); } ((AbstractJob) bean).registerJobExecutionListener( this.applicationContext.getBean(TaskBatchExecutionListener.class)); } return bean; }
public void addListenerToJob(AbstractJob job) { if (addProtocolListener) { job.registerJobExecutionListener(protocolListener); } job.registerJobExecutionListener(runningExecutionTrackerListener); if (addLoggingListener) { job.registerJobExecutionListener(loggingListener); job.registerJobExecutionListener(loggingAfterJobListener); for (String stepName : job.getStepNames()) { AbstractStep step = (AbstractStep) job.getStep(stepName); step.registerStepExecutionListener(loggingListener); } } if (listenerProviders != null) { for (ListenerProvider listenerProvider : listenerProviders) { for (JobExecutionListener jobExecutionListener : listenerProvider.jobExecutionListeners()) { job.registerJobExecutionListener(jobExecutionListener); } for (StepExecutionListener stepExecutionListener : listenerProvider.stepExecutionListeners()) { for (String stepName : job.getStepNames()) { AbstractStep step = (AbstractStep) job.getStep(stepName); step.registerStepExecutionListener(stepExecutionListener); } } } } }
public void addListenerToJob(AbstractJob job) { if (addProtocolListener) { job.registerJobExecutionListener(protocolListener); } job.registerJobExecutionListener(runningExecutionTrackerListener); if (addLoggingListener) { job.registerJobExecutionListener(loggingListener); job.registerJobExecutionListener(loggingAfterJobListener); for (String stepName : job.getStepNames()) { AbstractStep step = (AbstractStep) job.getStep(stepName); step.registerStepExecutionListener(loggingListener); } } if (listenerProviders != null) { for (ListenerProvider listenerProvider : listenerProviders) { for (JobExecutionListener jobExecutionListener : listenerProvider.jobExecutionListeners()) { job.registerJobExecutionListener(jobExecutionListener); } for (StepExecutionListener stepExecutionListener : listenerProvider.stepExecutionListeners()) { for (String stepName : job.getStepNames()) { AbstractStep step = (AbstractStep) job.getStep(stepName); step.registerStepExecutionListener(stepExecutionListener); } } } } }