RESOLVED - BATCH-825: Modify JobLauncher contract to not throw exception on job failure.

removed onInterrupt from JobExecutionListener
This commit is contained in:
robokaso
2008-10-06 07:45:19 +00:00
parent 63f437528c
commit 5f070affb7
5 changed files with 17 additions and 39 deletions

View File

@@ -39,9 +39,4 @@ public interface JobExecutionListener {
*/
void afterJob(JobExecution jobExecution);
/**
* Callback when a job is interrupted or stopped manually.
* @param jobExecution the current {@link JobExecution}
*/
void onInterrupt(JobExecution jobExecution);
}

View File

@@ -19,6 +19,8 @@ package org.springframework.batch.core.job;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
@@ -41,6 +43,8 @@ import org.springframework.batch.repeat.ExitStatus;
*/
public class SimpleJob extends AbstractJob {
private static final Log logger = LogFactory.getLog(SimpleJob.class);
/**
* Run the specified job by looping through the steps and delegating to the
* {@link Step}.
@@ -49,7 +53,7 @@ public class SimpleJob extends AbstractJob {
* @throws StartLimitExceededException if start limit of one of the steps
* was exceeded
*/
public void execute(JobExecution execution){
public void execute(JobExecution execution) {
JobInstance jobInstance = execution.getJobInstance();
@@ -82,7 +86,8 @@ public class SimpleJob extends AbstractJob {
updateStatus(execution, BatchStatus.STARTED);
currentStepExecution = execution.createStepExecution(step.getName());
StepExecution lastStepExecution = getJobRepository().getLastStepExecution(jobInstance, step.getName());
StepExecution lastStepExecution = getJobRepository().getLastStepExecution(jobInstance,
step.getName());
boolean isRestart = (lastStepExecution != null && !lastStepExecution.getStatus().equals(
BatchStatus.COMPLETED)) ? true : false;
@@ -96,8 +101,8 @@ public class SimpleJob extends AbstractJob {
step.execute(currentStepExecution);
if(currentStepExecution.getStatus() == BatchStatus.FAILED ||
currentStepExecution.getStatus() == BatchStatus.STOPPED ){
if (currentStepExecution.getStatus() == BatchStatus.FAILED
|| currentStepExecution.getStatus() == BatchStatus.STOPPED) {
break;
}
}
@@ -110,25 +115,14 @@ public class SimpleJob extends AbstractJob {
updateStatus(execution, currentStepExecution.getStatus());
//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.STOPPED){
getCompositeListener().afterJob(execution);
}
else if(execution.getStatus() == BatchStatus.STOPPED){
getCompositeListener().onInterrupt(execution);
}
}
catch (JobInterruptedException e) {
execution.setStatus(BatchStatus.STOPPED);
execution.addFailureException(e);
getCompositeListener().onInterrupt(execution);
}
catch (Throwable t) {
execution.setStatus(BatchStatus.FAILED);
execution.addFailureException(t);
getCompositeListener().afterJob(execution);
}
finally {
ExitStatus status = ExitStatus.FAILED;
@@ -148,6 +142,13 @@ public class SimpleJob extends AbstractJob {
execution.setEndTime(new Date());
execution.setExitStatus(status);
getJobRepository().update(execution);
try {
getCompositeListener().afterJob(execution);
}
catch (Exception e) {
logger.error("Exception encountered in afterStep callback", e);
}
}
}

View File

@@ -72,16 +72,4 @@ 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#onInterrupt(org.springframework.batch.core.JobExecution)
*/
public void onInterrupt(JobExecution jobExecution) {
for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) {
JobExecutionListener listener = iterator.next();
listener.onInterrupt(jobExecution);
}
}
}

View File

@@ -36,10 +36,4 @@ public class JobExecutionListenerSupport implements JobExecutionListener {
public void beforeJob(JobExecution jobExecution) {
}
/* (non-Javadoc)
* @see org.springframework.batch.core.JobListener#onInterrupt(org.springframework.batch.core.JobExecution)
*/
public void onInterrupt(JobExecution jobExecution) {
}
}

View File

@@ -334,7 +334,7 @@ public class SimpleJobTests extends TestCase {
JobExecutionListener listener = createMock(JobExecutionListener.class);
listener.beforeJob(jobExecution);
listener.onInterrupt(jobExecution);
listener.afterJob(jobExecution);
replay(listener);
job.setJobExecutionListeners(new JobExecutionListener[] { listener });