IN PROGRESS - issue BATCH-456: JobListener.afterJob() should be called regardless of success or failure
http://jira.springframework.org/browse/BATCH-456 added JobListener#onError(JobExecution, Throwable) called when job failed (not when interrupted)
This commit is contained in:
@@ -37,4 +37,9 @@ public interface JobListener {
|
||||
* Callback after successful completion of a job.
|
||||
*/
|
||||
void afterJob(JobExecution jobExecution);
|
||||
|
||||
/**
|
||||
* Callback on job failure.
|
||||
*/
|
||||
void onError(JobExecution jobExecution, Throwable e);
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ public class SimpleJob extends AbstractJob {
|
||||
}
|
||||
catch (Throwable t) {
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
listener.onError(execution, t);
|
||||
rethrow(t);
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -51,24 +51,26 @@ public class CompositeJobListener implements JobListener {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#close()
|
||||
*/
|
||||
public void afterJob(JobExecution jobExecution) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) {
|
||||
JobListener listener = (JobListener) iterator.next();
|
||||
listener.afterJob(jobExecution);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.core.domain.JobParameters)
|
||||
*/
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) {
|
||||
JobListener listener = (JobListener) iterator.next();
|
||||
listener.beforeJob(jobExecution);
|
||||
}
|
||||
}
|
||||
|
||||
public void onError(JobExecution jobExecution, Throwable e) {
|
||||
for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) {
|
||||
JobListener listener = (JobListener) iterator.next();
|
||||
listener.onError(jobExecution, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,9 @@ public class JobListenerSupport implements JobListener {
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
}
|
||||
|
||||
public void onError(JobExecution jobExecution, Throwable e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user