OPEN - issue BATCH-324: Step as factory for StepExecutor

http://jira.springframework.org/browse/BATCH-324

Substantial re-org of core domain packages to align concerns
This commit is contained in:
dsyer
2008-01-29 16:36:16 +00:00
parent d4d09d2ad8
commit f9619e345e
57 changed files with 333 additions and 384 deletions

View File

@@ -21,9 +21,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobLocator;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.repository.JobLocator;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.core.runtime.JobParametersFactory;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.batch.execution.step.simple.SimpleExitCodeExceptionClassifier;

View File

@@ -22,11 +22,11 @@ import java.util.Properties;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobLocator;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.NoSuchJobException;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobLocator;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.batch.core.runtime.JobParametersFactory;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.batch.support.PropertiesConverter;

View File

@@ -19,10 +19,10 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.springframework.batch.core.domain.DuplicateJobException;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobLocator;
import org.springframework.batch.core.domain.JobRegistry;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.JobLocator;
import org.springframework.batch.core.repository.JobRegistry;
import org.springframework.beans.BeansException;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.DisposableBean;

View File

@@ -21,11 +21,11 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.springframework.batch.core.domain.DuplicateJobException;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobRegistry;
import org.springframework.batch.core.domain.ListableJobRegistry;
import org.springframework.batch.core.domain.NoSuchJobException;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.JobRegistry;
import org.springframework.batch.core.repository.ListableJobRegistry;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.util.Assert;
/**

View File

@@ -24,15 +24,15 @@ import org.springframework.batch.common.ExceptionClassifier;
import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobExecutor;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.execution.step.simple.SimpleExitCodeExceptionClassifier;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
@@ -54,7 +54,7 @@ public class DefaultJobExecutor implements JobExecutor {
* Run the specified job by looping through the steps and delegating to the
* {@link StepExecutor}.
*
* @see org.springframework.batch.core.executor.JobExecutor#run(org.springframework.batch.core.domain.Job,
* @see org.springframework.batch.core.domain.JobExecutor#run(org.springframework.batch.core.domain.Job,
* org.springframework.batch.core.domain.JobExecution)
*/
public ExitStatus run(Job job, JobExecution execution)
@@ -85,8 +85,7 @@ public class DefaultJobExecutor implements JobExecutor {
updateStatus(execution, BatchStatus.STARTED);
StepExecutor stepExecutor = step.createStepExecutor();
StepExecution stepExecution = execution.createStepExecution(stepInstance);
status = stepExecutor.process(step,
stepExecution);
status = stepExecutor.process(stepExecution);
}
}

View File

@@ -19,9 +19,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobExecutor;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.repeat.ExitStatus;

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
@@ -113,7 +113,7 @@ public abstract class AbstractStep extends StepSupport {
*/
public StepExecutor createStepExecutor() {
assertMandatoryProperties();
SimpleStepExecutor executor = new SimpleStepExecutor();
SimpleStepExecutor executor = new SimpleStepExecutor(this);
executor.setRepository(jobRepository);
executor.applyConfiguration(this);
executor.setTasklet(tasklet);

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.repeat.RepeatOperations;
/**

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.repeat.RepeatOperations;
/**

View File

@@ -18,8 +18,8 @@ package org.springframework.batch.execution.step.simple;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.repeat.ExitStatus;
/**

View File

@@ -23,11 +23,11 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.scope.SimpleStepContext;
import org.springframework.batch.execution.scope.StepContext;
@@ -96,6 +96,15 @@ public class SimpleStepExecutor implements StepExecutor {
private Tasklet tasklet;
private AbstractStep step;
/**
* Package private constructor so the factory can create a the executor.
*/
SimpleStepExecutor(AbstractStep abstractStep) {
this.step = abstractStep;
}
/**
* Public setter for the {@link StatisticsService}. This will be used to
* create the {@link StepContext}, and hence any component that is a
@@ -163,9 +172,9 @@ public class SimpleStepExecutor implements StepExecutor {
* @throws StepInterruptedException if the step or a chunk is interrupted
* @throws RuntimeException if there is an exception during a chunk
* execution
* @see StepExecutor#process(Step, StepExecution)
* @see StepExecutor#process(StepExecution)
*/
public ExitStatus process(final Step step, final StepExecution stepExecution) throws BatchCriticalException,
public ExitStatus process(final StepExecution stepExecution) throws BatchCriticalException,
StepInterruptedException {
final StepInstance stepInstance = stepExecution.getStep();

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.repeat.RepeatContext;
/**

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.repeat.RepeatContext;
/**

View File

@@ -20,8 +20,8 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.batch.repeat.ExitStatus;

View File

@@ -19,9 +19,9 @@ import java.util.Collection;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.DuplicateJobException;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.NoSuchJobException;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.beans.FatalBeanException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

View File

@@ -19,9 +19,9 @@ import java.util.Collection;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.DuplicateJobException;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.NoSuchJobException;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.batch.execution.configuration.MapJobRegistry;
/**

View File

@@ -28,11 +28,11 @@ import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobDao;
@@ -61,8 +61,7 @@ public class DefaultJobExecutorTests extends TestCase {
private List list = new ArrayList();
StepExecutor defaultStepLifecycle = new StubStepExecutor() {
public ExitStatus process(Step configuration,
StepExecution stepExecution) throws StepInterruptedException,
public ExitStatus process(StepExecution stepExecution) throws StepInterruptedException,
BatchCriticalException {
list.add("default");
return ExitStatus.FINISHED;
@@ -70,8 +69,7 @@ public class DefaultJobExecutorTests extends TestCase {
};
StepExecutor configurationStepLifecycle = new StubStepExecutor() {
public ExitStatus process(Step configuration,
StepExecution stepExecution) throws StepInterruptedException,
public ExitStatus process(StepExecution stepExecution) throws StepInterruptedException,
BatchCriticalException {
list.add("special");
return ExitStatus.FINISHED;
@@ -193,8 +191,7 @@ public class DefaultJobExecutorTests extends TestCase {
final StepInterruptedException exception = new StepInterruptedException(
"Interrupt!");
defaultStepLifecycle = new StubStepExecutor() {
public ExitStatus process(Step configuration,
StepExecution stepExecution)
public ExitStatus process(StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
throw exception;
}
@@ -214,8 +211,7 @@ public class DefaultJobExecutorTests extends TestCase {
stepConfiguration2.setStartLimit(5);
final RuntimeException exception = new RuntimeException("Foo!");
defaultStepLifecycle = new StubStepExecutor() {
public ExitStatus process(Step configuration,
StepExecution stepExecution)
public ExitStatus process(StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
throw exception;
}
@@ -289,8 +285,7 @@ public class DefaultJobExecutorTests extends TestCase {
public void applyConfiguration(Step configuration) {
}
public ExitStatus process(Step configuration,
StepExecution stepExecution) throws StepInterruptedException,
public ExitStatus process(StepExecution stepExecution) throws StepInterruptedException,
BatchCriticalException {
return null;
}

View File

@@ -21,8 +21,8 @@ import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobExecutor;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.repeat.ExitStatus;

View File

@@ -35,7 +35,6 @@ import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.step.simple.AbstractStep;
import org.springframework.batch.execution.step.simple.RepeatOperationsStep;
import org.springframework.batch.execution.step.simple.SimpleStep;
import org.springframework.batch.execution.step.simple.SimpleStepExecutor;
import org.springframework.batch.execution.tasklet.ItemOrientedTasklet;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemRecoverer;
@@ -66,12 +65,9 @@ public class SimpleJobTests extends TestCase {
private DefaultJobExecutor jobExecutor = new DefaultJobExecutor();;
private SimpleStepExecutor stepLifecycle = new SimpleStepExecutor();
protected void setUp() throws Exception {
super.setUp();
jobExecutor.setJobRepository(repository);
stepLifecycle.setRepository(repository);
}
private Tasklet getTasklet(String arg) throws Exception {

View File

@@ -27,7 +27,7 @@ import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;

View File

@@ -82,7 +82,7 @@ public class RepeatOperationsStepTests extends TestCase {
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
try {
executor.process(configuration, stepExecution);
executor.process(stepExecution);
fail("Expected RuntimeException");
} catch (NullPointerException e) {
// expected
@@ -122,7 +122,7 @@ public class RepeatOperationsStepTests extends TestCase {
StepExecution stepExecution = new StepExecution(new StepInstance(
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
executor.process(configuration, stepExecution);
executor.process(stepExecution);
assertEquals(2, list.size());
assertEquals(1, steps.size());
}

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
import org.springframework.batch.repeat.ExitStatus;
import junit.framework.TestCase;

View File

@@ -122,7 +122,7 @@ public class SimpleStepExecutorTests extends TestCase {
StepExecution stepExecution = new StepExecution(step,
jobExecutionContext);
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
assertEquals(1, processed.size());
assertEquals(1, stepExecution.getTaskCount().intValue());
}
@@ -169,7 +169,7 @@ public class SimpleStepExecutorTests extends TestCase {
}
});
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
assertEquals(1, processed.size());
}
@@ -197,7 +197,7 @@ public class SimpleStepExecutorTests extends TestCase {
}
});
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
assertEquals(1, processed.size());
}
@@ -212,7 +212,7 @@ public class SimpleStepExecutorTests extends TestCase {
StepExecution stepExecution = new StepExecution(step,
jobExecutionContext);
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
assertEquals(1, processed.size());
}
@@ -240,7 +240,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Exception ex) {
assertEquals(stepExecution.getRollbackCount(), new Integer(1));
@@ -272,7 +272,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Exception ex) {
ExitStatus status = stepExecution.getExitStatus();
@@ -294,7 +294,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Throwable t) {
fail();
@@ -319,7 +319,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Throwable t) {
fail();
@@ -344,7 +344,7 @@ public class SimpleStepExecutorTests extends TestCase {
jobExecutionContext);
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Throwable t) {
fail();
@@ -371,7 +371,7 @@ public class SimpleStepExecutorTests extends TestCase {
StepExecution stepExecution = new StepExecution(step, jobExecution);
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Throwable t) {
fail();
@@ -442,7 +442,7 @@ public class SimpleStepExecutorTests extends TestCase {
});
try {
stepExecutor.process(stepConfiguration, stepExecution);
stepExecutor.process(stepExecution);
}
catch (Throwable t) {
fail();

View File

@@ -60,7 +60,7 @@ public class SimpleStepTests extends TestCase {
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
try {
executor.process(configuration, stepExecution);
executor.process(stepExecution);
fail("Expected RuntimeException");
} catch (NullPointerException e) {
throw e;

View File

@@ -26,9 +26,9 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepExecutor;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.repository.SimpleJobRepository;
@@ -90,7 +90,7 @@ public class StepExecutorInterruptionTests extends TestCase {
Thread processingThread = new Thread() {
public void run() {
try {
executor.process(stepConfiguration, stepExecution);
executor.process(stepExecution);
}
catch (StepInterruptedException e) {
// do nothing...

View File

@@ -17,7 +17,7 @@ package org.springframework.batch.execution.step.simple;
import junit.framework.TestCase;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.domain.StepInterruptedException;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;

View File

@@ -8,7 +8,7 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean class="org.springframework.batch.execution.configuration.JobRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry" ref="jobConfigurationRegistry"/>
<property name="jobConfigurationRegistry" ref="jobRegistry"/>
</bean>
<bean id="test-job" class="org.springframework.batch.core.domain.Job">

View File

@@ -15,7 +15,7 @@
<property name="jobExecutor" ref="jobLifecycle" />
</bean>
<bean id="jobConfigurationRegistry"
<bean id="jobRegistry"
class="org.springframework.batch.execution.configuration.MapJobRegistry" />
<bean id="jobLifecycle"
@@ -40,13 +40,8 @@
<property name="useParent" value="true" />
</bean>
</property>
</bean>
<bean id="stepLifecycle"
class="org.springframework.batch.execution.step.simple.SimpleStepExecutor"
scope="prototype">
<property name="transactionManager" ref="transactionManager" />
<property name="repository" ref="simpleJobRepository" />
<property name="jobRepository" ref="jobRegistry"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="transactionManager"