RESOLVED - issue BATCH-456: JobListener.afterJob() should be called regardless of success or failure

Added onInterrupt callback.
This commit is contained in:
dsyer
2008-03-14 17:43:41 +00:00
parent f3faf8f795
commit ff85f455de
3 changed files with 27 additions and 4 deletions

View File

@@ -29,17 +29,26 @@ public interface JobListener {
/**
* Initialise the state of the listener with the {@link JobExecution} from
* the current scope.
* @param jobExecution
* @param jobExecution the current {@link JobExecution}
*/
void beforeJob(JobExecution jobExecution);
/**
* Callback after successful completion of a job.
* @param jobExecution the current {@link JobExecution}
*/
void afterJob(JobExecution jobExecution);
/**
* Callback on job failure.
* Callback on job failure owing to the throwable provided.
* @param jobExecution the current {@link JobExecution}
* @param e the exception that caused the job to terminate
*/
void onError(JobExecution jobExecution, Throwable e);
/**
* Callback when a job is interrupted or stopped manually.
* @param jobExecution the current {@link JobExecution}
*/
void onInterrupt(JobExecution jobExecution);
}

View File

@@ -73,4 +73,11 @@ public class CompositeJobListener implements JobListener {
}
public void onInterrupt(JobExecution jobExecution) {
for (Iterator iterator = listeners.listIterator(); iterator.hasNext();) {
JobListener listener = (JobListener) iterator.next();
listener.onInterrupt(jobExecution);
}
}
}

View File

@@ -36,9 +36,16 @@ public class JobListenerSupport implements JobListener {
public void beforeJob(JobExecution jobExecution) {
}
/* (non-Javadoc)
* @see org.springframework.batch.core.JobListener#onError(org.springframework.batch.core.JobExecution, java.lang.Throwable)
*/
public void onError(JobExecution jobExecution, Throwable e) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.springframework.batch.core.JobListener#onInterrupt(org.springframework.batch.core.JobExecution)
*/
public void onInterrupt(JobExecution jobExecution) {
}
}