Example usage for org.springframework.batch.core.job AbstractJob registerJobExecutionListener

List of usage examples for org.springframework.batch.core.job AbstractJob registerJobExecutionListener

Introduction

In this page you can find the example usage for org.springframework.batch.core.job AbstractJob registerJobExecutionListener.

Prototype

public void registerJobExecutionListener(JobExecutionListener listener) 

Source Link

Document

Register a single listener for the JobExecutionListener callbacks.

Usage

From source file:de.codecentric.batch.listener.AddListenerToJobService.java

public void addListenerToJob(AbstractJob job) {
    if (addProtocolListener) {
        job.registerJobExecutionListener(protocolListener);
    }//from   ww w .java 2s.  co  m
    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);
                }
            }
        }
    }
}