IN PROGRESS - BATCH-825: Modify JobLauncher contract to not throw exception on job failure.
removed onErrorInJob
This commit is contained in:
@@ -34,17 +34,10 @@ public interface JobExecutionListener {
|
||||
void beforeJob(JobExecution jobExecution);
|
||||
|
||||
/**
|
||||
* Callback after successful completion of a job.
|
||||
* Callback after completion of a job, both successful and failed.
|
||||
* @param jobExecution the current {@link JobExecution}
|
||||
*/
|
||||
void afterJob(JobExecution jobExecution);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -112,12 +112,9 @@ public class SimpleJob extends AbstractJob {
|
||||
|
||||
//This is temporary, given the changes to how exceptions are handled, there really should only be an afterJob method
|
||||
//but it's being left as is until the listener contract can be discussed.
|
||||
if(execution.getStatus() == BatchStatus.COMPLETED){
|
||||
if(execution.getStatus() != BatchStatus.STOPPED){
|
||||
getCompositeListener().afterJob(execution);
|
||||
}
|
||||
else if(execution.getStatus() == BatchStatus.FAILED){
|
||||
getCompositeListener().onError(execution, currentStepExecution.getFailureExceptions().get(0));
|
||||
}
|
||||
else if(execution.getStatus() == BatchStatus.STOPPED){
|
||||
getCompositeListener().onInterrupt(execution);
|
||||
}
|
||||
@@ -131,7 +128,7 @@ public class SimpleJob extends AbstractJob {
|
||||
catch (Throwable t) {
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
execution.addFailureException(t);
|
||||
getCompositeListener().onError(execution, t);
|
||||
getCompositeListener().afterJob(execution);
|
||||
}
|
||||
finally {
|
||||
ExitStatus status = ExitStatus.FAILED;
|
||||
|
||||
@@ -72,20 +72,6 @@ public class CompositeExecutionJobListener implements JobExecutionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the registered listeners in reverse order, respecting and
|
||||
* prioritising those that implement {@link Ordered}.
|
||||
* @see org.springframework.batch.core.JobExecutionListener#onError(org.springframework.batch.core.JobExecution,
|
||||
* java.lang.Throwable)
|
||||
*/
|
||||
public void onError(JobExecution jobExecution, Throwable e) {
|
||||
for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) {
|
||||
JobExecutionListener listener = iterator.next();
|
||||
listener.onError(jobExecution, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the registered listeners in reverse order, respecting and
|
||||
* prioritising those that implement {@link Ordered}.
|
||||
|
||||
@@ -36,12 +36,6 @@ public class JobExecutionListenerSupport implements JobExecutionListener {
|
||||
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) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.JobListener#onInterrupt(org.springframework.batch.core.JobExecution)
|
||||
*/
|
||||
|
||||
@@ -240,8 +240,8 @@ public class SimpleJobTests extends TestCase {
|
||||
|
||||
public void testFailedWithListener() throws Exception {
|
||||
job.setJobExecutionListeners(new JobExecutionListenerSupport[] { new JobExecutionListenerSupport() {
|
||||
public void onError(JobExecution jobExecution, Throwable t) {
|
||||
list.add(t);
|
||||
public void afterJob(JobExecution jobExecution) {
|
||||
list.add("afterJob");
|
||||
}
|
||||
} });
|
||||
final RuntimeException exception = new RuntimeException("Foo!");
|
||||
|
||||
Reference in New Issue
Block a user