RESOLVED - issue BATCH-421: Different set methods for listeners on implementation classes

http://jira.springframework.org/browse/BATCH-421
This commit is contained in:
dsyer
2008-03-06 08:20:01 +00:00
parent efe07a3096
commit 2844579dae
3 changed files with 25 additions and 12 deletions

View File

@@ -34,8 +34,8 @@ import org.springframework.batch.repeat.ExitStatus;
/**
* Simple implementation of (@link Job} interface providing the ability to run a
* {@link JobExecution}. Sequentially executes a job by iterating it's life of
* steps.
* {@link JobExecution}. Sequentially executes a job by iterating through its
* list of steps.
*
* @author Lucas Ward
* @author Dave Syer
@@ -46,11 +46,25 @@ public class SimpleJob extends AbstractJob {
private CompositeJobListener listener = new CompositeJobListener();
public void setListeners(JobListener[] listeners) {
/**
* Public setter for injecting {@link JobListener}s. They will all be given
* the {@link JobListener} callbacks at the appropriate point in the job.
*
* @param listeners the listeners to set.
*/
public void setJobListeners(JobListener[] listeners) {
for (int i = 0; i < listeners.length; i++) {
this.listener.register(listeners[i]);
}
}
/**
* Register a single listener for the {@link JobListener} callbacks.
* @param listener a {@link JobListener}
*/
public void registerListener(JobListener listener) {
this.listener.register(listener);
}
/**
* Run the specified job by looping through the steps and delegating to the
@@ -79,7 +93,6 @@ public class SimpleJob extends AbstractJob {
listener.beforeJob(execution);
for (Iterator i = steps.iterator(); i.hasNext();) {
Step step = (Step) i.next();
@@ -91,7 +104,7 @@ public class SimpleJob extends AbstractJob {
currentStepExecution = execution.createStepExecution(step);
step.execute(currentStepExecution);
}
}
@@ -119,10 +132,10 @@ public class SimpleJob extends AbstractJob {
status = ExitStatus.NOOP.addExitDescription("No steps configured for this job.");
}
}
else if(currentStepExecution != null){
else if (currentStepExecution != null) {
status = currentStepExecution.getExitStatus();
}
execution.setEndTime(new Date());
execution.setExitStatus(status);
jobRepository.saveOrUpdate(execution);

View File

@@ -43,11 +43,11 @@ public class CompositeJobListener implements JobListener {
/**
* Register additional listener.
*
* @param stepListener
* @param jobListener
*/
public void register(JobListener stepListener) {
if (!listeners.contains(stepListener)) {
listeners.add(stepListener);
public void register(JobListener jobListener) {
if (!listeners.contains(jobListener)) {
listeners.add(jobListener);
}
}

View File

@@ -177,7 +177,7 @@ public class SimpleJobTests extends TestCase {
}
public void testRunNormallyWithListener() throws Exception {
job.setListeners(new JobListenerSupport[] {new JobListenerSupport() {
job.setJobListeners(new JobListenerSupport[] {new JobListenerSupport() {
public void beforeJob(JobExecution jobExecution) {
list.add("before");
}