From bc7d12e1a35e85d4a1cf18e55c3110328f163338 Mon Sep 17 00:00:00 2001 From: robokaso Date: Fri, 3 Oct 2008 13:40:37 +0000 Subject: [PATCH] IN PROGRESS - BATCH-825: Modify JobLauncher contract to not throw exception on job failure. removed onErrorInJob --- .../batch/core/JobExecutionListener.java | 9 +-------- .../springframework/batch/core/job/SimpleJob.java | 7 ++----- .../listener/CompositeExecutionJobListener.java | 14 -------------- .../core/listener/JobExecutionListenerSupport.java | 6 ------ .../batch/core/job/SimpleJobTests.java | 4 ++-- 5 files changed, 5 insertions(+), 35 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java index 41c083184..ba1f730e2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecutionListener.java @@ -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. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java index c62b35aeb..352be91f0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java @@ -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; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java index c11ee86c4..c786152ad 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeExecutionJobListener.java @@ -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 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}. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java index 91d872185..67540a16d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobExecutionListenerSupport.java @@ -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) */ diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index 63af89891..fbed4e876 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -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!");