OPEN - issue BATCH-679: Non-sequential execution - add state subpackage

This commit is contained in:
dsyer
2008-10-30 11:33:05 +00:00
parent 09be3f0b0d
commit dade6952c8
28 changed files with 77 additions and 70 deletions

View File

@@ -17,9 +17,9 @@ package org.springframework.batch.core.configuration.xml;
import java.util.Collection;
import org.springframework.batch.core.job.flow.support.DecisionState;
import org.springframework.batch.core.job.flow.support.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.StateTransition;
import org.springframework.batch.core.job.flow.support.state.DecisionState;
import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;

View File

@@ -19,9 +19,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.batch.core.job.flow.support.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.SplitState;
import org.springframework.batch.core.job.flow.support.StateTransition;
import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.state.SplitState;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;

View File

@@ -21,9 +21,9 @@ import java.util.List;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.flow.support.EndState;
import org.springframework.batch.core.job.flow.support.StateTransition;
import org.springframework.batch.core.job.flow.support.StepState;
import org.springframework.batch.core.job.flow.support.state.EndState;
import org.springframework.batch.core.job.flow.support.state.StepState;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;

View File

@@ -29,7 +29,7 @@ public interface Flow {
/**
* @throws FlowExecutionException
*/
FlowExecution start(JobFlowExecutor executor) throws FlowExecutionException;
FlowExecution start(FlowExecutor executor) throws FlowExecutionException;
/**
* @param stateName the name of the state to resume on
@@ -37,6 +37,6 @@ public interface Flow {
* @return a {@link FlowExecution} containing the exit status of the flow
* @throws FlowExecutionException
*/
FlowExecution resume(String stateName, JobFlowExecutor executor) throws FlowExecutionException;
FlowExecution resume(String stateName, FlowExecutor executor) throws FlowExecutionException;
}

View File

@@ -29,7 +29,7 @@ import org.springframework.batch.core.repository.JobRestartException;
* @author Dave Syer
*
*/
public interface JobFlowExecutor {
public interface FlowExecutor {
/**
* @param step a {@link Step} to execute

View File

@@ -62,7 +62,7 @@ public class FlowJob extends AbstractJob {
@Override
protected StepExecution doExecute(final JobExecution execution) throws JobExecutionException {
try {
FlowExecution result = flow.start(new SimpleJobFlowExecutor(execution));
FlowExecution result = flow.start(new JobFlowExecutor(execution));
return getLastStepExecution(execution, result);
}
catch (FlowExecutionException e) {
@@ -121,7 +121,7 @@ public class FlowJob extends AbstractJob {
* @author Dave Syer
*
*/
private class SimpleJobFlowExecutor implements JobFlowExecutor {
private class JobFlowExecutor implements FlowExecutor {
private final ThreadLocal<StepExecution> stepExecutionHolder = new ThreadLocal<StepExecution>();
private final JobExecution execution;
@@ -129,7 +129,7 @@ public class FlowJob extends AbstractJob {
/**
* @param execution
*/
private SimpleJobFlowExecutor(JobExecution execution) {
private JobFlowExecutor(JobExecution execution) {
this.execution = execution;
stepExecutionHolder.set(null);
}

View File

@@ -27,7 +27,7 @@ import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.FlowExecutionException;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.beans.factory.InitializingBean;
import com.sun.org.apache.xerces.internal.impl.xpath.XPath.Step;
@@ -101,9 +101,9 @@ public class SimpleFlow implements Flow, InitializingBean {
}
/**
* @see Flow#start(JobFlowExecutor)
* @see Flow#start(FlowExecutor)
*/
public FlowExecution start(JobFlowExecutor executor) throws FlowExecutionException {
public FlowExecution start(FlowExecutor executor) throws FlowExecutionException {
if (startState == null) {
initializeTransitions();
}
@@ -113,9 +113,9 @@ public class SimpleFlow implements Flow, InitializingBean {
}
/**
* @see Flow#resume(String, JobFlowExecutor)
* @see Flow#resume(String, FlowExecutor)
*/
public FlowExecution resume(String stateName, JobFlowExecutor executor) throws FlowExecutionException {
public FlowExecution resume(String stateName, FlowExecutor executor) throws FlowExecutionException {
String status = FlowExecution.UNKNOWN;
State state = stateMap.get(stateName);

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.core.job.flow.support;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
/**
@@ -45,6 +45,6 @@ public interface State {
* @return a status for the execution
* @throws Exception if anything goes wrong
*/
String handle(JobFlowExecutor executor) throws Exception;
String handle(FlowExecutor executor) throws Exception;
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.core.job.flow.support;
import org.springframework.batch.core.job.flow.support.util.PatternMatcher;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.StringUtils;

View File

@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.State;
/**
@@ -45,6 +46,6 @@ public abstract class AbstractState implements State {
return getClass().getSimpleName()+": name=["+name+"]";
}
public abstract String handle(JobFlowExecutor executor) throws Exception;
public abstract String handle(FlowExecutor executor) throws Exception;
}

View File

@@ -1,6 +1,6 @@
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
/**
@@ -20,7 +20,7 @@ public class DecisionState extends AbstractState {
}
@Override
public String handle(JobFlowExecutor executor) throws Exception {
public String handle(FlowExecutor executor) throws Exception {
return decider.decide(executor.getJobExecution(), executor.getStepExecution());
}

View File

@@ -1,9 +1,10 @@
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.State;
/**
* {@link State} implementation for ending a job if it is in progress and
@@ -29,10 +30,10 @@ public class EndState extends AbstractState {
* is the first place we came after a restart we do nothing (otherwise the
* same outcome that ended the job on the last run will occur).
*
* @see State#handle(JobFlowExecutor)
* @see State#handle(FlowExecutor)
*/
@Override
public String handle(JobFlowExecutor executor) throws Exception {
public String handle(FlowExecutor executor) throws Exception {
JobExecution jobExecution = executor.getJobExecution();
// If there are no step executions, then we are at the beginning of a
// restart

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import java.util.Collection;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import java.util.Collection;
import java.util.Collections;

View File

@@ -1,9 +1,9 @@
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
/**
* @author Dave Syer
@@ -19,7 +19,7 @@ public class PauseState extends AbstractState {
}
@Override
public String handle(JobFlowExecutor executor) throws Exception {
public String handle(FlowExecutor executor) throws Exception {
JobExecution jobExecution = executor.getJobExecution();

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import java.util.ArrayList;
import java.util.Collection;
@@ -23,7 +23,8 @@ import java.util.concurrent.FutureTask;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.FlowExecutionException;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.State;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.task.TaskRejectedException;
@@ -63,10 +64,10 @@ public class SplitState extends AbstractState {
* Execute the flows in parallel by passing them to the {@link TaskExecutor}
* and wait for all of them to finish before proceeding.
*
* @see State#handle(JobFlowExecutor)
* @see State#handle(FlowExecutor)
*/
@Override
public String handle(final JobFlowExecutor executor) throws Exception {
public String handle(final FlowExecutor executor) throws Exception {
Collection<FutureTask<FlowExecution>> tasks = new ArrayList<FutureTask<FlowExecution>>();

View File

@@ -1,10 +1,11 @@
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.State;
/**
* {@link State} implementation that delegates to a {@link JobFlowExecutor} to
* {@link State} implementation that delegates to a {@link FlowExecutor} to
* execute the specified {@link Step}.
*
* @author Dave Syer
@@ -23,7 +24,7 @@ public class StepState extends AbstractState {
}
@Override
public String handle(JobFlowExecutor executor) throws Exception {
public String handle(FlowExecutor executor) throws Exception {
return executor.executeStep(step);
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.util;
/**
* @author Dave Syer

View File

@@ -26,7 +26,7 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.support.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -26,7 +26,7 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.support.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -32,13 +32,13 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.core.job.flow.support.DecisionState;
import org.springframework.batch.core.job.flow.support.EndState;
import org.springframework.batch.core.job.flow.support.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.PauseState;
import org.springframework.batch.core.job.flow.support.SimpleFlow;
import org.springframework.batch.core.job.flow.support.StateTransition;
import org.springframework.batch.core.job.flow.support.StepState;
import org.springframework.batch.core.job.flow.support.state.DecisionState;
import org.springframework.batch.core.job.flow.support.state.EndState;
import org.springframework.batch.core.job.flow.support.state.JobExecutionDecider;
import org.springframework.batch.core.job.flow.support.state.PauseState;
import org.springframework.batch.core.job.flow.support.state.StepState;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;

View File

@@ -21,14 +21,14 @@ import org.springframework.batch.core.StartLimitExceededException;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.repository.JobRestartException;
/**
* @author Dave Syer
*
*/
public class JobFlowExecutorSupport implements JobFlowExecutor {
public class JobFlowExecutorSupport implements FlowExecutor {
public String executeStep(Step step) throws JobInterruptedException, JobRestartException,
StartLimitExceededException {

View File

@@ -27,7 +27,7 @@ import java.util.List;
import org.junit.Test;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.FlowExecutionException;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.SimpleFlow;
import org.springframework.batch.core.job.flow.support.StateTransition;
@@ -35,11 +35,11 @@ import org.springframework.batch.core.job.flow.support.StateTransition;
* @author Dave Syer
*
*/
public class BasicFlowTests {
public class SimpleFlowTests {
private SimpleFlow flow = new SimpleFlow("job");
private JobFlowExecutor executor = new JobFlowExecutorSupport();
private FlowExecutor executor = new JobFlowExecutorSupport();
@Test(expected = IllegalArgumentException.class)
public void testEmptySteps() throws Exception {
@@ -156,7 +156,7 @@ public class BasicFlowTests {
public void testFailedStep() throws Exception {
flow.setStateTransitions(collect(StateTransition.createStateTransition(new StubState("step1") {
@Override
public String handle(JobFlowExecutor executor) {
public String handle(FlowExecutor executor) {
return FlowExecution.FAILED;
}
}, "step2"), StateTransition.createEndStateTransition(new StubState("step2"))));
@@ -185,7 +185,7 @@ public class BasicFlowTests {
private boolean paused = false;
@Override
public String handle(JobFlowExecutor executor) throws Exception {
public String handle(FlowExecutor executor) throws Exception {
if (!paused) {
paused = true;
return FlowExecution.PAUSED;

View File

@@ -16,9 +16,9 @@
package org.springframework.batch.core.job.flow.support;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.support.AbstractState;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.State;
import org.springframework.batch.core.job.flow.support.state.AbstractState;
/**
* Base class for {@link State} implementations.
@@ -36,7 +36,7 @@ public class StateSupport extends AbstractState {
}
@Override
public String handle(JobFlowExecutor executor) throws Exception {
public String handle(FlowExecutor executor) throws Exception {
return FlowExecution.COMPLETED;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import static org.junit.Assert.assertEquals;
@@ -21,7 +21,9 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.job.flow.JobFlowExecutor;
import org.springframework.batch.core.job.flow.FlowExecutor;
import org.springframework.batch.core.job.flow.support.JobFlowExecutorSupport;
import org.springframework.batch.core.job.flow.support.state.EndState;
/**
* @author Dave Syer
@@ -37,7 +39,7 @@ public class EndStateTests {
}
/**
* Test method for {@link EndState#handle(JobFlowExecutor)}.
* Test method for {@link EndState#handle(FlowExecutor)}.
* @throws Exception
*/
@Test
@@ -58,7 +60,7 @@ public class EndStateTests {
}
/**
* Test method for {@link EndState#handle(JobFlowExecutor)}.
* Test method for {@link EndState#handle(FlowExecutor)}.
* @throws Exception
*/
@Test
@@ -79,7 +81,7 @@ public class EndStateTests {
}
/**
* Test method for {@link EndState#handle(JobFlowExecutor)}.
* Test method for {@link EndState#handle(FlowExecutor)}.
* @throws Exception
*/
@Test

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -23,7 +23,7 @@ import java.util.Collections;
import org.junit.Test;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.support.MaxValueFlowExecutionAggregator;
import org.springframework.batch.core.job.flow.support.state.MaxValueFlowExecutionAggregator;
/**
* @author Dave Syer

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.job.flow.support;
package org.springframework.batch.core.job.flow.support.state;
import static org.junit.Assert.assertEquals;
@@ -24,7 +24,7 @@ import org.easymock.EasyMock;
import org.junit.Test;
import org.springframework.batch.core.job.flow.Flow;
import org.springframework.batch.core.job.flow.FlowExecution;
import org.springframework.batch.core.job.flow.support.SplitState;
import org.springframework.batch.core.job.flow.support.state.SplitState;
import org.springframework.core.task.SimpleAsyncTaskExecutor;