Refactored launching to allow exit codes to be returned to the launcher.

This commit is contained in:
lucasward
2007-08-21 05:12:03 +00:00
parent ace8b6dddd
commit d9132be8be
49 changed files with 310 additions and 308 deletions

View File

@@ -20,6 +20,7 @@ package org.springframework.batch.sample.module;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Hacked {@link Tasklet} that throws exception on a given record number
@@ -36,7 +37,7 @@ public class ExceptionRestartableTasklet extends RestartableItemProviderTasklet
/* (non-Javadoc)
* @see Tasklet#execute()
*/
public boolean execute() throws Exception {
public ExitStatus execute() throws Exception {
counter++;
if (counter == throwExceptionOnRecordNumber) {

View File

@@ -19,6 +19,7 @@ package org.springframework.batch.sample.module;
import java.util.Properties;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.statistics.StatisticsProvider;
import org.springframework.batch.support.PropertiesConverter;
@@ -41,10 +42,10 @@ public class InfiniteLoopTasklet implements Tasklet, StatisticsProvider {
super();
}
public boolean execute() throws Exception {
public ExitStatus execute() throws Exception {
Thread.sleep(500);
count++;
return true;
return ExitStatus.CONTINUABLE;
}
/* (non-Javadoc)

View File

@@ -20,14 +20,14 @@
</property>
</bean>
<bean id="batchContainer" class="org.springframework.batch.execution.facade.SimpleJobExecutorFacade">
<bean id="jobExecutorFacade" class="org.springframework.batch.execution.facade.SimpleJobExecutorFacade">
<property name="jobRepository" ref="simpleJobRepository" />
<property name="jobConfigurationLocator" ref="jobConfigurationRegistry"/>
<property name="jobExecutor" ref="jobExecutor" />
</bean>
<bean class="org.springframework.batch.execution.bootstrap.SimpleJobLauncher">
<property name="batchContainer" ref="batchContainer" />
<property name="jobExecutorFacade" ref="jobExecutorFacade" />
</bean>
<bean id="jobConfigurationRegistry" class="org.springframework.batch.execution.configuration.MapJobConfigurationRegistry"/>

View File

@@ -17,6 +17,7 @@ package org.springframework.batch.sample;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.execution.bootstrap.JobLauncher;
import org.springframework.batch.execution.bootstrap.SynchronousJobLauncher;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
@@ -25,7 +26,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
*/
public abstract class AbstractBatchLauncherTests extends AbstractDependencyInjectionSpringContextTests {
protected JobLauncher launcher;
protected SynchronousJobLauncher launcher;
private JobConfiguration jobConfiguration;
/**
@@ -36,7 +37,7 @@ public abstract class AbstractBatchLauncherTests extends AbstractDependencyInjec
return jobConfiguration.getName();
}
public void setBatchContainerLauncher(JobLauncher launcher) {
public void setBatchContainerLauncher(SynchronousJobLauncher launcher) {
this.launcher = launcher;
}

View File

@@ -31,7 +31,7 @@ public abstract class AbstractLifecycleSpringContextTests extends AbstractBatchL
public void testLifecycle() throws Exception {
validatePreConditions();
launcher.start(getJobName());
launcher.run(getJobName());
launcher.stop();
validatePostConditions();
}

View File

@@ -40,7 +40,7 @@ public class GracefulShutdownFunctionalTest extends AbstractBatchLauncherTests {
Thread jobThread = new Thread(){
public void run(){
try {
launcher.start(getJobName());
launcher.run(getJobName());
}
catch (RepeatException e) {
if (!(e.getCause() instanceof InterruptedException)) {

View File

@@ -81,7 +81,7 @@ public class RestartFunctionalTests extends AbstractBatchLauncherTests {
// load the application context and launch the job
private void runJob() throws Exception, Exception {
launcher.start(getJobName());
launcher.run(getJobName());
}
}