OPEN - issue BATCH-378: RepeatListener is confusing and too generic to use for 'intercepting' a step
http://jira.springframework.org/browse/BATCH-378 Open StepListsner with StepExecution.
This commit is contained in:
@@ -83,7 +83,8 @@ public class TaskletStep implements Step, InitializingBean, BeanNameAware {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.Step#getStartLimit()
|
||||
*/
|
||||
public int getStartLimit() {
|
||||
@@ -99,7 +100,8 @@ public class TaskletStep implements Step, InitializingBean, BeanNameAware {
|
||||
this.startLimit = startLimit;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.domain.Step#isAllowStartIfComplete()
|
||||
*/
|
||||
public boolean isAllowStartIfComplete() {
|
||||
@@ -180,8 +182,14 @@ public class TaskletStep implements Step, InitializingBean, BeanNameAware {
|
||||
Exception fatalException = null;
|
||||
try {
|
||||
|
||||
listener.open(stepExecution.getJobParameters());
|
||||
exitStatus = tasklet.execute();
|
||||
listener.open(stepExecution);
|
||||
exitStatus = tasklet.execute();
|
||||
try {
|
||||
exitStatus = exitStatus.and(listener.close());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Encountered an error on listener close.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
jobRepository.saveOrUpdateExecutionContext(stepExecution);
|
||||
@@ -193,23 +201,21 @@ public class TaskletStep implements Step, InitializingBean, BeanNameAware {
|
||||
}
|
||||
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
logger.error("Encountered an error running the tasklet");
|
||||
updateStatus(stepExecution, BatchStatus.FAILED);
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Encountered an error running the tasklet");
|
||||
updateStatus(stepExecution, BatchStatus.FAILED);
|
||||
try {
|
||||
exitStatus = exitStatus.and(listener.onError(e));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("Encountered an error on listener close.", ex);
|
||||
}
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
throw new BatchCriticalException(e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
exitStatus = exitStatus.and(listener.close());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("Encountered an error on listener close.", e);
|
||||
}
|
||||
stepExecution.setExitStatus(exitStatus);
|
||||
stepExecution.setEndTime(new Date());
|
||||
try {
|
||||
|
||||
@@ -105,7 +105,7 @@ public class TaskletStepTests extends TestCase {
|
||||
public void testSuccessfulExecutionWithListener() throws Exception {
|
||||
TaskletStep step = new TaskletStep(new StubTasklet(false, false), new JobRepositorySupport());
|
||||
step.setListener(new StepListenerSupport() {
|
||||
public void open(JobParameters context) {
|
||||
public void open(StepExecution context) {
|
||||
list.add("open");
|
||||
}
|
||||
public ExitStatus close() {
|
||||
|
||||
Reference in New Issue
Block a user