IN PROGRESS - issue BATCH-894: RFC: move ExitStatus up into Core?

Replaced infrastrucure status with local enum and moved ExitStatus into core.   TODO: maybe get rid of continuable.
This commit is contained in:
dsyer
2008-11-07 18:40:58 +00:00
parent 9ac28ef106
commit 8b2d02f5d9
107 changed files with 475 additions and 411 deletions

View File

@@ -1,15 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-batch-docs</artifactId>
<version>2.0.0.CI-SNAPSHOT</version>
<artifactId>org.springframework.batch.docs</artifactId>
<version>2.0.0.CI-SNAPSHOT</version>
<name>Documentation</name>
<packaging>pom</packaging>
<description>Spring Batch Documentation - reference guide and user manuals.</description>
<parent>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch</artifactId>
<artifactId>org.springframework.batch</artifactId>
<version>2.0.0.CI-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
@@ -61,7 +62,9 @@
<include name="**/*.jpg" />
</fileset>
</copy>
<move file="${basedir}/target/site/reference/pdf/index.pdf" tofile="${basedir}/target/site/reference/pdf/${artifactId}.pdf" failonerror="false" />
<move file="${basedir}/target/site/reference/pdf/index.pdf"
tofile="${basedir}/target/site/reference/pdf/${artifactId}.pdf"
failonerror="false" />
</postProcess>
</configuration>
<phase>pre-site</phase>

View File

@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.repeat;
package org.springframework.batch.core;
import java.io.Serializable;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.util.StringUtils;
/**
@@ -66,6 +67,11 @@ public class ExitStatus implements Serializable {
*/
public static final ExitStatus FAILED = new ExitStatus(false, "FAILED");
/**
* Convenient constant value representing finished processing with interrupted status.
*/
public static final ExitStatus INTERRUPTED = new ExitStatus(false, "INTERRUPTED");
private final boolean continuable;
private final String exitCode;
@@ -138,8 +144,9 @@ public class ExitStatus implements Serializable {
* Severity is defined by the exit code:
* <ul>
* <li>Codes beginning with NOOP have severity 1</li>
* <li>Codes beginning with FAILED have severity 2</li>
* <li>Codes beginning with UNKNOWN have severity 3</li>
* <li>Codes beginning with INTERRUPTED have severity 2</li>
* <li>Codes beginning with FAILED have severity 3</li>
* <li>Codes beginning with UNKNOWN have severity 4</li>
* </ul>
* Others have severity 0.<br/>
*
@@ -173,12 +180,15 @@ public class ExitStatus implements Serializable {
if (status.exitCode.startsWith(NOOP.exitCode)) {
return 0;
}
if (status.exitCode.startsWith(FAILED.exitCode)) {
if (status.exitCode.startsWith(INTERRUPTED.exitCode)) {
return 1;
}
if (status.exitCode.startsWith(UNKNOWN.exitCode)) {
if (status.exitCode.startsWith(FAILED.exitCode)) {
return 2;
}
if (status.exitCode.startsWith(UNKNOWN.exitCode)) {
return 3;
}
return 0;
}

View File

@@ -27,7 +27,6 @@ import java.util.List;
import java.util.Set;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
/**
* Batch domain object representing the execution of a job.

View File

@@ -23,7 +23,6 @@ import java.util.Date;
import java.util.List;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.batch.core;
import org.springframework.batch.repeat.ExitStatus;
/**
* Listener interface for the lifecycle of a {@link Step}.

View File

@@ -21,6 +21,7 @@ import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
@@ -35,7 +36,6 @@ import org.springframework.batch.core.listener.CompositeExecutionJobListener;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

View File

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

View File

@@ -19,6 +19,7 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
@@ -26,7 +27,6 @@ import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;

View File

@@ -21,7 +21,7 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
/**
* An implementation of {@link ExitCodeMapper} that can be configured through a

View File

@@ -18,9 +18,9 @@ package org.springframework.batch.core.listener;
import java.util.Arrays;
import java.util.Iterator;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.Ordered;
/**

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.listener;
import java.util.List;
import org.springframework.batch.core.ChunkListener;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.ItemProcessListener;
import org.springframework.batch.core.ItemReadListener;
import org.springframework.batch.core.ItemWriteListener;
@@ -26,7 +27,6 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -15,9 +15,9 @@
*/
package org.springframework.batch.core.listener;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -18,12 +18,12 @@ package org.springframework.batch.core.listener;
import java.util.List;
import org.springframework.batch.core.ChunkListener;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.ItemReadListener;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.repeat.ExitStatus;
/**
* Basic no-op implementations of all {@link StepListener} implementations.

View File

@@ -10,7 +10,6 @@ import org.springframework.batch.core.partition.PartitionHandler;
import org.springframework.batch.core.partition.StepExecutionSplitter;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**
@@ -70,7 +69,7 @@ public class PartitionStep extends AbstractStep {
* @see Step#execute(StepExecution)
*/
@Override
protected ExitStatus doExecute(StepExecution stepExecution) throws Exception {
protected void doExecute(StepExecution stepExecution) throws Exception {
// Wait for task completion and then aggregate the results
Collection<StepExecution> executions = partitionHandler.handle(stepExecutionSplitter, stepExecution);
@@ -79,8 +78,6 @@ public class PartitionStep extends AbstractStep {
throw new JobExecutionException("Partition handler returned an incomplete step");
}
return stepExecution.getExitStatus();
}
}

View File

@@ -3,8 +3,8 @@ package org.springframework.batch.core.partition.support;
import java.util.Collection;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**

View File

@@ -8,11 +8,11 @@ import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.partition.PartitionHandler;
import org.springframework.batch.core.partition.StepExecutionSplitter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;

View File

@@ -10,9 +10,9 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.OptimisticLockingFailureException;

View File

@@ -8,9 +8,9 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

View File

@@ -21,8 +21,8 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.util.Assert;
@@ -74,10 +74,9 @@ public class StepExecutionSimpleCompletionPolicy extends StepExecutionListenerSu
* @param result
* @return true if the commit interval has been reached or the result
* indicates completion
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext,
* org.springframework.batch.repeat.ExitStatus)
* @see CompletionPolicy#isComplete(RepeatContext, RepeatStatus)
*/
public boolean isComplete(RepeatContext context, ExitStatus result) {
public boolean isComplete(RepeatContext context, RepeatStatus result) {
Assert.state(delegate != null, "The delegate resource has not been initialised. "
+ "Remember to register this object as a StepListener.");
return delegate.isComplete(context, result);

View File

@@ -18,11 +18,12 @@ package org.springframework.batch.core.scope;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
/**
* Convenient base class for clients who need to do something in a repeat
@@ -52,7 +53,7 @@ public abstract class StepContextRepeatCallback implements RepeatCallback {
*
* @see RepeatCallback#doInIteration(RepeatContext)
*/
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
ChunkContext chunkContext = attributeQueue.poll();
if (chunkContext == null) {
@@ -64,7 +65,9 @@ public abstract class StepContextRepeatCallback implements RepeatCallback {
// otherwise step-scoped beans will be re-initialised for each chunk.
StepSynchronizationManager.register(stepContext);
try {
return doInStepContext(context, stepContext);
ExitStatus exitStatus = doInStepContext(context, stepContext);
stepContext.getStepExecution().setExitStatus(exitStatus);
return RepeatStatus.continueIf(exitStatus.isContinuable());
}
finally {
// Still some stuff to do with the data in this chunk,

View File

@@ -22,6 +22,7 @@ import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
@@ -34,7 +35,6 @@ import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.scope.StepContext;
import org.springframework.batch.core.scope.StepSynchronizationManager;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
@@ -47,12 +47,13 @@ import org.springframework.util.Assert;
* @author Ben Hale
* @author Robert Kasanicky
*/
public abstract class AbstractStep implements Step, InitializingBean, BeanNameAware {
public abstract class AbstractStep implements Step, InitializingBean,
BeanNameAware {
/**
* Exit code for interrupted status.
*/
public static final String JOB_INTERRUPTED = "JOB_INTERRUPTED";
public static final String JOB_INTERRUPTED = "INTERRUPTED";
private static final Log logger = LogFactory.getLog(AbstractStep.class);
@@ -113,7 +114,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
/**
* Public setter for the startLimit.
*
* @param startLimit the startLimit to set
* @param startLimit
* the startLimit to set
*/
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
@@ -127,7 +129,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
* Public setter for flag that determines whether the step should start
* again if it is already complete. Defaults to false.
*
* @param allowStartIfComplete the value of the flag to set
* @param allowStartIfComplete
* the value of the flag to set
*/
public void setAllowStartIfComplete(boolean allowStartIfComplete) {
this.allowStartIfComplete = allowStartIfComplete;
@@ -143,21 +146,23 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
}
/**
* Extension point for subclasses to execute business logic.
* Extension point for subclasses to execute business logic. Subclasses
* should set the {@link ExitStatus} on the {@link StepExecution} before
* returning.
*
* @param stepExecution the current step context
* @return {@link ExitStatus} to show whether the step is finished
* processing.
* @param stepExecution
* the current step context
* @throws Exception
*/
protected abstract ExitStatus doExecute(StepExecution stepExecution) throws Exception;
protected abstract void doExecute(StepExecution stepExecution) throws Exception;
/**
* Extension point for subclasses to provide callbacks to their
* collaborators at the beginning of a step, to open or acquire resources.
* Does nothing by default.
*
* @param ctx the {@link ExecutionContext} to use
* @param ctx
* the {@link ExecutionContext} to use
* @throws Exception
*/
protected void open(ExecutionContext ctx) throws Exception {
@@ -166,9 +171,10 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
/**
* Extension point for subclasses to provide callbacks to their
* collaborators at the end of a step (right at the end of the finally
* block), to close or release resources. Does nothing by default.
* block), to close or release resources. Does nothing by default.
*
* @param ctx the {@link ExecutionContext} to use
* @param ctx
* the {@link ExecutionContext} to use
* @throws Exception
*/
protected void close(ExecutionContext ctx) throws Exception {
@@ -177,10 +183,11 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
/**
* Template method for step execution logic - calls abstract methods for
* resource initialization ({@link #open(ExecutionContext)}), execution
* logic ({@link #doExecute(StepExecution)}) and resource closing ({@link #close(ExecutionContext)}).
* logic ({@link #doExecute(StepExecution)}) and resource closing (
* {@link #close(ExecutionContext)}).
*/
public final void execute(StepExecution stepExecution) throws JobInterruptedException,
UnexpectedJobExecutionException {
public final void execute(StepExecution stepExecution)
throws JobInterruptedException, UnexpectedJobExecutionException {
stepExecution.setStartTime(new Date());
stepExecution.setStatus(BatchStatus.STARTED);
getJobRepository().update(stepExecution);
@@ -195,7 +202,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
getCompositeListener().beforeStep(stepExecution);
open(stepExecution.getExecutionContext());
exitStatus = doExecute(stepExecution);
doExecute(stepExecution);
exitStatus = stepExecution.getExitStatus();
// Check if someone is trying to stop us
if (stepExecution.isTerminateOnly()) {
@@ -208,66 +216,68 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
try {
getJobRepository().update(stepExecution);
getJobRepository().updateExecutionContext(stepExecution);
}
catch (Exception e) {
} catch (Exception e) {
commitException = e;
exitStatus = exitStatus.and(ExitStatus.UNKNOWN);
}
}
catch (Throwable e) {
} catch (Throwable e) {
logger.error("Encountered an error executing the step: " + e.getClass() + ": " + e.getMessage(), e);
logger.error("Encountered an error executing the step: "
+ e.getClass() + ": " + e.getMessage(), e);
stepExecution.setStatus(determineBatchStatus(e));
exitStatus = getDefaultExitStatusForFailure(e);
stepExecution.addFailureException(e);
try {
getJobRepository().updateExecutionContext(stepExecution);
}
catch (Exception ex) {
logger.error("Encountered an error on listener error callback.", ex);
} catch (Exception ex) {
logger.error(
"Encountered an error on listener error callback.", ex);
stepExecution.addFailureException(ex);
}
}
finally {
} finally {
try {
exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution));
}
catch (Exception e){
exitStatus = exitStatus.and(getCompositeListener().afterStep(
stepExecution));
} catch (Exception e) {
logger.error("Exception in afterStep callback", e);
}
stepExecution.setExitStatus(exitStatus);
stepExecution.setEndTime(new Date());
try {
getJobRepository().update(stepExecution);
}
catch (Exception e) {
} catch (Exception e) {
if (commitException == null) {
commitException = e;
}
else {
logger.error("Exception while updating step execution after commit exception", e);
} else {
logger
.error(
"Exception while updating step execution after commit exception",
e);
}
}
try {
close(stepExecution.getExecutionContext());
}
catch (Exception e) {
logger.error("Exception while closing step execution resources", e);
} catch (Exception e) {
logger.error(
"Exception while closing step execution resources", e);
stepExecution.addFailureException(e);
}
StepSynchronizationManager.release();
if (commitException != null) {
stepExecution.setStatus(BatchStatus.UNKNOWN);
logger.error("Encountered an error saving batch meta data."
+ "This job is now in an unknown state and should not be restarted.", commitException);
logger
.error(
"Encountered an error saving batch meta data."
+ "This job is now in an unknown state and should not be restarted.",
commitException);
stepExecution.addFailureException(commitException);
}
}
@@ -279,11 +289,10 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
private static BatchStatus determineBatchStatus(Throwable e) {
if (e instanceof FatalException) {
return BatchStatus.UNKNOWN;
}
else if (e instanceof JobInterruptedException || e.getCause() instanceof JobInterruptedException) {
} else if (e instanceof JobInterruptedException
|| e.getCause() instanceof JobInterruptedException) {
return BatchStatus.STOPPED;
}
else {
} else {
return BatchStatus.FAILED;
}
}
@@ -292,7 +301,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
* Register a step listener for callbacks at the appropriate stages in a
* step execution.
*
* @param listener a {@link StepExecutionListener}
* @param listener
* a {@link StepExecutionListener}
*/
public void registerStepExecutionListener(StepExecutionListener listener) {
this.listener.register(listener);
@@ -301,7 +311,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
/**
* Register each of the objects as listeners.
*
* @param listeners an array of listener objects of known types.
* @param listeners
* an array of listener objects of known types.
*/
public void setStepExecutionListeners(StepExecutionListener[] listeners) {
for (int i = 0; i < listeners.length; i++) {
@@ -319,7 +330,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
/**
* Public setter for {@link JobRepository}.
*
* @param jobRepository is a mandatory dependence (no default).
* @param jobRepository
* is a mandatory dependence (no default).
*/
public void setJobRepository(JobRepository jobRepository) {
this.jobRepository = jobRepository;
@@ -333,18 +345,21 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
* Default mapping from throwable to {@link ExitStatus}. Clients can modify
* the exit code using a {@link StepExecutionListener}.
*
* @param ex the cause of the failure
* @param ex
* the cause of the failure
* @return an {@link ExitStatus}
*/
private ExitStatus getDefaultExitStatusForFailure(Throwable ex) {
ExitStatus exitStatus;
if (ex instanceof JobInterruptedException || ex.getCause() instanceof JobInterruptedException) {
exitStatus = new ExitStatus(false, JOB_INTERRUPTED, JobInterruptedException.class.getName());
}
else if (ex instanceof NoSuchJobException || ex.getCause() instanceof NoSuchJobException) {
exitStatus = new ExitStatus(false, ExitCodeMapper.NO_SUCH_JOB, ex.getClass().getName());
}
else {
if (ex instanceof JobInterruptedException
|| ex.getCause() instanceof JobInterruptedException) {
exitStatus = new ExitStatus(false, JOB_INTERRUPTED,
JobInterruptedException.class.getName());
} else if (ex instanceof NoSuchJobException
|| ex.getCause() instanceof NoSuchJobException) {
exitStatus = new ExitStatus(false, ExitCodeMapper.NO_SUCH_JOB, ex
.getClass().getName());
} else {
StringWriter writer = new StringWriter();
ex.printStackTrace(new PrintWriter(writer));
String message = writer.toString();

View File

@@ -16,10 +16,10 @@
package org.springframework.batch.core.step;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.item.NoWorkFoundException;
import org.springframework.batch.repeat.ExitStatus;
/**
* Fails the step if no items have been processed ( item count is 0).

View File

@@ -19,16 +19,17 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
import org.springframework.batch.core.step.skip.NonSkippableReadException;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.retry.RetryOperations;
import org.springframework.batch.support.Classifier;
import org.springframework.core.AttributeAccessor;
@@ -84,18 +85,20 @@ public class FaultTolerantChunkOrientedTasklet<I, O> extends AbstractFaultTolera
if (inputs.isEmpty() && outputs.isEmpty()) {
result = getRepeatOperations().iterate(new RepeatCallback() {
public ExitStatus doInIteration(final RepeatContext context) throws Exception {
RepeatStatus continuable = getRepeatOperations().iterate(new RepeatCallback() {
public RepeatStatus doInIteration(final RepeatContext context) throws Exception {
I item = read(contribution, skippedReads);
if (item == null) {
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
inputs.add(item);
contribution.incrementReadCount();
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
});
result = continuable.isContinuable() ? ExitStatus.CONTINUABLE : ExitStatus.FINISHED;
}

View File

@@ -6,16 +6,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.retry.RetryOperations;
import org.springframework.batch.support.Classifier;
import org.springframework.core.AttributeAccessor;
@@ -56,19 +57,20 @@ public class NonbufferingFaultTolerantChunkOrientedTasklet<I, O> extends
final List<I> inputs = new ArrayList<I>();
final List<Exception> skippedReads = getBufferedList(attributes, SKIPPED_READS_KEY);
result = getRepeatOperations().iterate(new RepeatCallback() {
public ExitStatus doInIteration(final RepeatContext context) throws Exception {
RepeatStatus continuable = getRepeatOperations().iterate(new RepeatCallback() {
public RepeatStatus doInIteration(final RepeatContext context) throws Exception {
I item = read(contribution, skippedReads);
if (item == null) {
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
inputs.add(item);
contribution.incrementReadCount();
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
});
result = continuable.isContinuable() ? ExitStatus.CONTINUABLE : ExitStatus.FINISHED;
// filter inputs marked for skipping
final Map<I, Exception> skippedInputs = getBufferedSkips(attributes, SKIPPED_INPUTS_KEY);

View File

@@ -3,15 +3,16 @@ package org.springframework.batch.core.step.item;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.core.AttributeAccessor;
/**
@@ -40,20 +41,22 @@ public class SimpleChunkOrientedTasklet<I, O> extends AbstractItemOrientedTaskle
ExitStatus result = ExitStatus.CONTINUABLE;
final List<I> inputs = new ArrayList<I>();
result = repeatOperations.iterate(new RepeatCallback() {
RepeatStatus continuable = repeatOperations.iterate(new RepeatCallback() {
public ExitStatus doInIteration(final RepeatContext context) throws Exception {
public RepeatStatus doInIteration(final RepeatContext context) throws Exception {
I item = doRead();
if (item == null) {
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
inputs.add(item);
contribution.incrementReadCount();
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
});
result = continuable.isContinuable() ? ExitStatus.CONTINUABLE : ExitStatus.FINISHED;
// If there is no input we don't have to do anything more
if (inputs.isEmpty()) {
return result;

View File

@@ -17,8 +17,8 @@ package org.springframework.batch.core.step.tasklet;
import java.util.concurrent.Callable;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.AttributeAccessor;
import org.springframework.util.Assert;

View File

@@ -2,11 +2,11 @@ package org.springframework.batch.core.step.tasklet;
import java.util.Map;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.util.Assert;
/**
* Maps exit codes to {@link org.springframework.batch.repeat.ExitStatus}
* Maps exit codes to {@link org.springframework.batch.core.ExitStatus}
* according to injected map. The injected map is required to contain a value
* for 'else' key, this value will be returned if the injected map
* does not contain value for the exit code returned by the system process.
@@ -30,7 +30,7 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi
/**
* @param mappings <code>Integer</code> exit code keys to
* {@link org.springframework.batch.repeat.ExitStatus} values.
* {@link org.springframework.batch.core.ExitStatus} values.
*/
public void setMappings(Map<Object, ExitStatus> mappings) {
Assert.notNull(mappings.get(ELSE_KEY));

View File

@@ -15,9 +15,9 @@
*/
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;
/**

View File

@@ -1,6 +1,6 @@
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
/**
* Simple {@link SystemProcessExitCodeMapper} implementation that performs following mapping:

View File

@@ -7,11 +7,11 @@ import java.util.concurrent.FutureTask;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.AttributeAccessor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.step.tasklet.SystemCommandTasklet;
import org.springframework.batch.repeat.ExitStatus;
/**
* Maps the exit code of a system process to ExitStatus value

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;
/**

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.step.tasklet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
@@ -35,7 +36,6 @@ import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.CompositeItemStream;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -100,30 +100,37 @@ public class TaskletStep extends AbstractStep {
*/
public TaskletStep(String name) {
super(name);
synchronizer = new StepExecutionSynchronizerFactory().getStepExecutionSynchronizer();
synchronizer = new StepExecutionSynchronizerFactory()
.getStepExecutionSynchronizer();
}
/**
* Public setter for the {@link PlatformTransactionManager}.
*
* @param transactionManager the transaction manager to set
* @param transactionManager
* the transaction manager to set
*/
public void setTransactionManager(PlatformTransactionManager transactionManager) {
public void setTransactionManager(
PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
/**
* Public setter for the {@link TransactionAttribute}.
* @param transactionAttribute the {@link TransactionAttribute} to set
*
* @param transactionAttribute
* the {@link TransactionAttribute} to set
*/
public void setTransactionAttribute(TransactionAttribute transactionAttribute) {
public void setTransactionAttribute(
TransactionAttribute transactionAttribute) {
this.transactionAttribute = transactionAttribute;
}
/**
* Public setter for the {@link Tasklet}.
*
* @param tasklet the {@link Tasklet} to set
* @param tasklet
* the {@link Tasklet} to set
*/
public void setTasklet(Tasklet tasklet) {
this.tasklet = tasklet;
@@ -139,7 +146,8 @@ public class TaskletStep extends AbstractStep {
* This is a good way to get access to job parameters and execution context
* if the tasklet is parameterised.
*
* @param listeners an array of listener objects of known types.
* @param listeners
* an array of listener objects of known types.
*/
public void setStepExecutionListeners(StepExecutionListener[] listeners) {
for (int i = 0; i < listeners.length; i++) {
@@ -156,7 +164,8 @@ public class TaskletStep extends AbstractStep {
* which itself is a {@link ItemStream}, you need to register the delegate
* here.
*
* @param streams an array of {@link ItemStream} objects.
* @param streams
* an array of {@link ItemStream} objects.
*/
public void setStreams(ItemStream[] streams) {
for (int i = 0; i < streams.length; i++) {
@@ -179,7 +188,8 @@ public class TaskletStep extends AbstractStep {
* processing. Should be set up by the caller through a factory. Defaults to
* a plain {@link RepeatTemplate}.
*
* @param stepOperations a {@link RepeatOperations} instance.
* @param stepOperations
* a {@link RepeatOperations} instance.
*/
public void setStepOperations(RepeatOperations stepOperations) {
this.stepOperations = stepOperations;
@@ -190,7 +200,8 @@ public class TaskletStep extends AbstractStep {
* check whether an external request has been made to interrupt the job
* execution.
*
* @param interruptionPolicy a {@link StepInterruptionPolicy}
* @param interruptionPolicy
* a {@link StepInterruptionPolicy}
*/
public void setInterruptionPolicy(StepInterruptionPolicy interruptionPolicy) {
this.interruptionPolicy = interruptionPolicy;
@@ -201,7 +212,8 @@ public class TaskletStep extends AbstractStep {
* backport concurrency utilities. Public setter for the
* {@link StepExecutionSynchronizer}.
*
* @param synchronizer the {@link StepExecutionSynchronizer} to set
* @param synchronizer
* the {@link StepExecutionSynchronizer} to set
*/
public void setSynchronizer(StepExecutionSynchronizer synchronizer) {
this.synchronizer = synchronizer;
@@ -216,26 +228,29 @@ public class TaskletStep extends AbstractStep {
* the current context governing the step execution, which would normally be
* available to the caller through the step's {@link ExecutionContext}.<br/>
*
* @throws JobInterruptedException if the step or a chunk is interrupted
* @throws RuntimeException if there is an exception during a chunk
* execution
* @throws JobInterruptedException
* if the step or a chunk is interrupted
* @throws RuntimeException
* if there is an exception during a chunk execution
*
*/
@Override
protected ExitStatus doExecute(StepExecution stepExecution) throws Exception {
protected void doExecute(StepExecution stepExecution) throws Exception {
stream.update(stepExecution.getExecutionContext());
getJobRepository().updateExecutionContext(stepExecution);
return stepOperations.iterate(new StepContextRepeatCallback(stepExecution) {
stepOperations.iterate(new StepContextRepeatCallback(stepExecution) {
@Override
public ExitStatus doInStepContext(RepeatContext repeatContext, StepContext stepContext) throws Exception {
public ExitStatus doInStepContext(RepeatContext repeatContext,
StepContext stepContext) throws Exception {
StepExecution stepExecution = stepContext.getStepExecution();
ExceptionHolder fatalException = new ExceptionHolder();
StepContribution contribution = stepExecution.createStepContribution();
StepContribution contribution = stepExecution
.createStepContribution();
stepExecution.getExecutionContext().clearDirtyFlag();
// Before starting a new transaction, check for
@@ -244,7 +259,8 @@ public class TaskletStep extends AbstractStep {
ExitStatus exitStatus = ExitStatus.CONTINUABLE;
TransactionStatus transaction = transactionManager.getTransaction(transactionAttribute);
TransactionStatus transaction = transactionManager
.getTransaction(transactionAttribute);
boolean locked = false;
@@ -252,8 +268,7 @@ public class TaskletStep extends AbstractStep {
try {
exitStatus = tasklet.execute(contribution, stepContext);
}
finally {
} finally {
// Apply the contribution to the step
// even if unsuccessful
logger.debug("Applying contribution: " + contribution);
@@ -269,8 +284,7 @@ public class TaskletStep extends AbstractStep {
try {
synchronizer.lock(stepExecution);
locked = true;
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
stepExecution.setStatus(BatchStatus.STOPPED);
Thread.currentThread().interrupt();
}
@@ -286,44 +300,45 @@ public class TaskletStep extends AbstractStep {
stream.update(stepExecution.getExecutionContext());
try {
getJobRepository().updateExecutionContext(stepExecution);
}
catch (Exception e) {
getJobRepository()
.updateExecutionContext(stepExecution);
} catch (Exception e) {
fatalException.setException(e);
stepExecution.setStatus(BatchStatus.UNKNOWN);
throw new FatalException("Fatal error detected during save of step execution context", e);
throw new FatalException(
"Fatal error detected during save of step execution context",
e);
}
try {
transactionManager.commit(transaction);
}
catch (Exception e) {
} catch (Exception e) {
fatalException.setException(e);
stepExecution.setStatus(BatchStatus.UNKNOWN);
logger.error("Fatal error detected during commit.");
throw new FatalException("Fatal error detected during commit", e);
throw new FatalException(
"Fatal error detected during commit", e);
}
try {
logger.debug("Saving step execution after commit: " + stepExecution);
logger.debug("Saving step execution after commit: "
+ stepExecution);
getJobRepository().update(stepExecution);
}
catch (Exception e) {
} catch (Exception e) {
fatalException.setException(e);
stepExecution.setStatus(BatchStatus.UNKNOWN);
throw new FatalException("Fatal error detected during update of step execution", e);
throw new FatalException(
"Fatal error detected during update of step execution",
e);
}
}
catch (Error e) {
} catch (Error e) {
processRollback(stepExecution, fatalException, transaction);
throw e;
}
catch (Exception e) {
} catch (Exception e) {
processRollback(stepExecution, fatalException, transaction);
throw e;
}
finally {
} finally {
// only release the lock if we acquired it
if (locked) {
synchronizer.release(stepExecution);
@@ -348,8 +363,8 @@ public class TaskletStep extends AbstractStep {
* @param fatalException
* @param transaction
*/
private void processRollback(final StepExecution stepExecution, final ExceptionHolder fatalException,
TransactionStatus transaction) {
private void processRollback(final StepExecution stepExecution,
final ExceptionHolder fatalException, TransactionStatus transaction) {
/*
* Any exception thrown within the transaction should automatically
@@ -359,8 +374,7 @@ public class TaskletStep extends AbstractStep {
try {
transactionManager.rollback(transaction);
}
catch (Exception e) {
} catch (Exception e) {
/*
* If we already failed to commit, it doesn't help to do this again
* - it's better to allow the CommitFailedException to propagate

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.repeat;
package org.springframework.batch.core;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
import org.apache.commons.lang.SerializationUtils;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
/**
* @author Dave Syer
@@ -30,7 +31,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)}
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
* .
*/
@Test
@@ -42,7 +43,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)}
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
* .
*/
@Test
@@ -54,7 +55,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)}
* {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)}
* .
*/
@Test
@@ -107,7 +108,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(boolean)}.
* {@link org.springframework.batch.core.ExitStatus#and(boolean)}.
*/
@Test
public void testAndBoolean() {
@@ -120,7 +121,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
* .
*/
@Test
@@ -133,7 +134,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
* .
*/
@Test
@@ -143,7 +144,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
* .
*/
@Test
@@ -153,7 +154,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
* .
*/
@Test
@@ -164,7 +165,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
* .
*/
@Test
@@ -175,7 +176,7 @@ public class ExitStatusTests {
/**
* Test method for
* {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)}
* {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)}
* .
*/
@Test

View File

@@ -22,7 +22,6 @@ import java.util.List;
import org.apache.commons.lang.SerializationUtils;
import org.junit.Test;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -26,7 +26,6 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -1,8 +1,8 @@
package org.springframework.batch.core.configuration.xml;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;
public class TestTasklet extends AbstractTestComponent implements Tasklet {

View File

@@ -35,6 +35,7 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.JobExecutionListener;
@@ -57,7 +58,6 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
/**
* Tests for DefaultJobLifecycle. MapJobDao and MapStepExecutionDao are used

View File

@@ -26,6 +26,7 @@ import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.JobParameters;
@@ -42,7 +43,6 @@ 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;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**

View File

@@ -30,6 +30,7 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
@@ -38,7 +39,6 @@ import org.springframework.batch.core.job.JobSupport;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.task.TaskExecutor;
/**

View File

@@ -23,6 +23,7 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
@@ -30,7 +31,6 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter;
import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.ClassUtils;
/**

View File

@@ -21,9 +21,9 @@ import java.util.Map;
import junit.framework.TestCase;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.launch.support.ExitCodeMapper;
import org.springframework.batch.core.launch.support.SimpleJvmExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
public class SimpleJvmExitCodeMapperTests extends TestCase {

View File

@@ -20,9 +20,9 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -23,8 +23,8 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
@@ -31,7 +32,6 @@ import org.springframework.batch.core.partition.StepExecutionSplitter;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;

View File

@@ -8,9 +8,9 @@ import java.util.Collections;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
public class StepExecutionAggregatorTests {

View File

@@ -10,13 +10,13 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.partition.StepExecutionSplitter;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.task.TaskRejectedException;

View File

@@ -31,11 +31,11 @@ import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.annotation.Transactional;

View File

@@ -14,11 +14,11 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional;

View File

@@ -8,7 +8,7 @@ import org.junit.Test;
import java.util.List;
import java.util.Map;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

View File

@@ -4,9 +4,9 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

View File

@@ -20,10 +20,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
/**
* @author Dave Syer
@@ -44,7 +45,8 @@ public class StepContextRepeatCallbackTests {
return ExitStatus.NOOP;
}
};
assertEquals(ExitStatus.NOOP, callback.doInIteration(null));
assertEquals(RepeatStatus.FINISHED, callback.doInIteration(null));
assertEquals(ExitStatus.NOOP, stepExecution.getExitStatus());
}
@Test

View File

@@ -12,13 +12,13 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**
@@ -55,10 +55,11 @@ public class AbstractStepTests {
events.add("open");
}
protected ExitStatus doExecute(StepExecution context) throws Exception {
@Override
protected void doExecute(StepExecution context) throws Exception {
assertSame(execution, context);
events.add("doExecute");
return ExitStatus.FINISHED;
context.setExitStatus(ExitStatus.FINISHED);
}
protected void close(ExecutionContext ctx) throws Exception {
@@ -139,8 +140,7 @@ public class AbstractStepTests {
public void testBeanName() throws Exception {
AbstractStep step = new AbstractStep() {
@Override
protected ExitStatus doExecute(StepExecution stepExecution) throws Exception {
return null;
protected void doExecute(StepExecution stepExecution) throws Exception {
}
};
assertNull(step.getName());
@@ -152,8 +152,7 @@ public class AbstractStepTests {
public void testName() throws Exception {
AbstractStep step = new AbstractStep() {
@Override
protected ExitStatus doExecute(StepExecution stepExecution) throws Exception {
return null;
protected void doExecute(StepExecution stepExecution) throws Exception {
}
};
assertNull(step.getName());
@@ -196,7 +195,7 @@ public class AbstractStepTests {
public void testFailure() throws Exception {
tested = new EventTrackingStep() {
@Override
protected ExitStatus doExecute(StepExecution context) throws Exception {
protected void doExecute(StepExecution context) throws Exception {
super.doExecute(context);
throw new RuntimeException("crash!");
}
@@ -234,9 +233,9 @@ public class AbstractStepTests {
public void testStoppedStep() throws Exception {
tested = new EventTrackingStep() {
@Override
protected ExitStatus doExecute(StepExecution context) throws Exception {
protected void doExecute(StepExecution context) throws Exception {
context.setTerminateOnly();
return super.doExecute(context);
super.doExecute(context);
}
};
tested.setJobRepository(repository);
@@ -257,7 +256,7 @@ public class AbstractStepTests {
assertEquals("close", events.get(i++));
assertEquals(7, events.size());
assertEquals("JOB_INTERRUPTED", execution.getExitStatus().getExitCode());
assertEquals("INTERRUPTED", execution.getExitStatus().getExitCode());
assertTrue("Execution context modifications made by listener should be persisted", repository.saved
.containsKey("afterStep"));
@@ -270,9 +269,8 @@ public class AbstractStepTests {
public void testFailureInSavingExecutionContext() throws Exception {
tested = new EventTrackingStep() {
@Override
protected ExitStatus doExecute(StepExecution context) throws Exception {
protected void doExecute(StepExecution context) throws Exception {
super.doExecute(context);
return ExitStatus.FINISHED;
}
};
repository = new JobRepositoryStub() {

View File

@@ -28,9 +28,9 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.launch.EmptyItemWriter;
import org.springframework.batch.core.step.JobRepositorySupport;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
@@ -70,10 +70,10 @@ public class RepeatOperationsStepFactoryBeanTests extends TestCase {
factory.setStepOperations(new RepeatOperations() {
public ExitStatus iterate(RepeatCallback callback) {
public RepeatStatus iterate(RepeatCallback callback) {
list = new ArrayList<String>();
list.add("foo");
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
});

View File

@@ -8,6 +8,7 @@ import static org.springframework.batch.core.BatchStatus.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobInterruptedException;
@@ -26,7 +27,6 @@ import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.core.AttributeAccessor;
import org.springframework.transaction.TransactionException;

View File

@@ -21,8 +21,8 @@ import static org.junit.Assert.fail;
import java.util.concurrent.Callable;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.step.tasklet.CallableTaskletAdapter;
import org.springframework.batch.repeat.ExitStatus;
public class CallableTaskletAdapterTests {

View File

@@ -8,8 +8,8 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.step.tasklet.ConfigurableSystemProcessExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
/**
* Tests for {@link ConfigurableSystemProcessExitCodeMapper}

View File

@@ -3,8 +3,8 @@ package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.step.tasklet.SimpleSystemProcessExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
/**
* Tests for {@link SimpleSystemProcessExitCodeMapper}.

View File

@@ -19,8 +19,8 @@ import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter;
import org.springframework.batch.repeat.ExitStatus;
/**
* @author Dave Syer

View File

@@ -10,6 +10,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobInterruptedException;
@@ -18,7 +19,6 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.step.tasklet.SystemCommandException;
import org.springframework.batch.core.step.tasklet.SystemCommandTasklet;
import org.springframework.batch.core.step.tasklet.SystemProcessExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.util.Assert;

View File

@@ -29,6 +29,7 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
@@ -54,7 +55,6 @@ import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamSupport;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;

View File

@@ -28,9 +28,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -123,12 +123,12 @@ public class ExternalRetryInBatchTests {
repeatTemplate.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
final String item = provider.read();
if (item==null) {
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
RetryCallback<String> callback = new RetryCallback<String>() {
@@ -154,7 +154,7 @@ public class ExternalRetryInBatchTests {
retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState(item));
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}

View File

@@ -16,7 +16,8 @@
package org.springframework.batch.repeat.jms;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
@@ -26,27 +27,27 @@ import javax.jms.JMSException;
import javax.jms.Session;
import javax.sql.DataSource;
import org.springframework.batch.repeat.ExitStatus;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jms.connection.SessionProxy;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.SessionCallback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeansException;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationContext;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml")
@@ -101,11 +102,11 @@ public class SynchronousTests implements ApplicationContextAware {
assertInitialState();
repeatTemplate.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text);
return new ExitStatus(text != null);
return RepeatStatus.continueIf(text != null);
}
});
@@ -125,11 +126,11 @@ public class SynchronousTests implements ApplicationContextAware {
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
public Object doInTransaction(org.springframework.transaction.TransactionStatus status) {
repeatTemplate.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
String text = (String) jmsTemplate.receiveAndConvert("queue");
list.add(text);
simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text);
return new ExitStatus(text != null);
return RepeatStatus.continueIf(text != null);
}
});
// force rollback...
@@ -170,11 +171,11 @@ public class SynchronousTests implements ApplicationContextAware {
public Object doInTransaction(org.springframework.transaction.TransactionStatus status) {
repeatTemplate.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
String text = (String) txJmsTemplate.receiveAndConvert("queue");
list.add(text);
simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text);
return new ExitStatus(text != null);
return RepeatStatus.continueIf(text != null);
}
});

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.repeat;
/**
* Interface for batch completion policies, to enable batch operations to
* strategise normal completion conditions. Stateful implementations of batch
@@ -41,7 +42,7 @@ public interface CompletionPolicy {
*
* @see #isComplete(RepeatContext)
*/
boolean isComplete(RepeatContext context, ExitStatus result);
boolean isComplete(RepeatContext context, RepeatStatus result);
/**
* Allow policy to signal completion according to internal state, without

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.repeat;
/**
* Callback interface for batch operations. Many simple processes will be able
* to use off-the-shelf implementations of this interface, enabling the
@@ -35,9 +36,9 @@ public interface RepeatCallback {
* implementation of the caller.
*
* @param context the current context passed in by the caller.
* @return an {@link ExitStatus} which is continuable if there is (or may
* @return an {@link RepeatStatus} which is continuable if there is (or may
* be) more data to process.
* @throws Exception if there is a problem with the processing.
*/
ExitStatus doInIteration(RepeatContext context) throws Exception;
RepeatStatus doInIteration(RepeatContext context) throws Exception;
}

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.repeat;
/**
* Interface for listeners to the batch process. Implementers can provide
* enhance the behaviour of a batch in small cross-cutting modules. The
@@ -41,7 +42,7 @@ public interface RepeatListener {
* @param context the current batch context
* @param result the result of the callback
*/
void after(RepeatContext context, ExitStatus result);
void after(RepeatContext context, RepeatStatus result);
/**
* Called once at the start of a complete batch, before any items are

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.repeat;
/**
* The main interface providing access to batch operations. The batch client is
* the {@link RepeatCallback}, where a single item or record is processed. The
@@ -41,6 +42,6 @@ public interface RepeatOperations {
* indication of whether the {@link RepeatOperations} can continue
* processing if this method is called again.
*/
ExitStatus iterate(RepeatCallback callback) throws RepeatException;
RepeatStatus iterate(RepeatCallback callback) throws RepeatException;
}

View File

@@ -0,0 +1,25 @@
package org.springframework.batch.repeat;
public enum RepeatStatus {
UNKNOWN(true), CONTINUABLE(true), FINISHED(false);
private final boolean continuable;
private RepeatStatus(boolean continuable) {
this.continuable = continuable;
}
public static RepeatStatus continueIf(boolean continuable) {
return continuable ? CONTINUABLE : FINISHED;
}
public boolean isContinuable() {
return this == CONTINUABLE;
}
public RepeatStatus and(boolean value) {
return value && continuable ? CONTINUABLE : FINISHED;
}
}

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.repeat.callback;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatOperations;
@@ -55,7 +55,7 @@ public class NestedRepeatCallback implements RepeatCallback {
*
* @see org.springframework.batch.repeat.RepeatCallback#doInIteration(RepeatContext)
*/
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
return template.iterate(callback);
}
}

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.repeat.interceptor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ProxyMethodInvocation;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
@@ -75,7 +75,7 @@ public class RepeatOperationsInterceptor implements MethodInterceptor {
try {
repeatOperations.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
try {
MethodInvocation clone = invocation;
@@ -89,16 +89,16 @@ public class RepeatOperationsInterceptor implements MethodInterceptor {
Object value = clone.proceed();
if (voidReturnType) {
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
if (!isComplete(value)) {
// Save the last result
result.setValue(value);
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
else {
result.setFinalValue(value);
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
}
catch (Throwable e) {

View File

@@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatListener;
@@ -54,7 +54,7 @@ public class CompositeRepeatListener implements RepeatListener {
/* (non-Javadoc)
* @see org.springframework.batch.repeat.RepeatListener#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus)
*/
public void after(RepeatContext context, ExitStatus result) {
public void after(RepeatContext context, RepeatStatus result) {
for (RepeatListener listener : listeners) {
listener.after(context, result);
}

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.repeat.listener;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatListener;
@@ -31,7 +31,7 @@ public class RepeatListenerSupport implements RepeatListener {
public void before(RepeatContext context) {
}
public void after(RepeatContext context, ExitStatus result) {
public void after(RepeatContext context, RepeatStatus result) {
}
public void close(RepeatContext context) {

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.repeat.policy;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
@@ -34,9 +34,9 @@ public class CompletionPolicySupport implements CompletionPolicy {
* delegate to {@link #isComplete(RepeatContext)}.
*
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext,
* ExitStatus)
* RepeatStatus)
*/
public boolean isComplete(RepeatContext context, ExitStatus result) {
public boolean isComplete(RepeatContext context, RepeatStatus result) {
if (result != null && !result.isContinuable()) {
return true;
}

View File

@@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
@@ -48,9 +48,9 @@ public class CompositeCompletionPolicy implements CompletionPolicy {
* This policy is complete if any of the composed policies is complete.
*
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext,
* ExitStatus)
* RepeatStatus)
*/
public boolean isComplete(RepeatContext context, ExitStatus result) {
public boolean isComplete(RepeatContext context, RepeatStatus result) {
RepeatContext[] contexts = ((CompositeBatchContext) context).contexts;
CompletionPolicy[] policies = ((CompositeBatchContext) context).policies;
for (int i = 0; i < policies.length; i++) {

View File

@@ -17,13 +17,13 @@
package org.springframework.batch.repeat.policy;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
/**
* Very simple {@link CompletionPolicy} that bases its decision on the result of
* a batch operation. If the result is null or not continuable according to the
* {@link ExitStatus} the batch is complete, otherwise not.
* {@link RepeatStatus} the batch is complete, otherwise not.
*
* @author Dave Syer
*
@@ -31,13 +31,13 @@ import org.springframework.batch.repeat.RepeatContext;
public class DefaultResultCompletionPolicy extends CompletionPolicySupport {
/**
* True if the result is null, or a {@link ExitStatus} indicating
* True if the result is null, or a {@link RepeatStatus} indicating
* completion.
*
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext,
* ExitStatus)
* RepeatStatus)
*/
public boolean isComplete(RepeatContext context, ExitStatus result) {
public boolean isComplete(RepeatContext context, RepeatStatus result) {
return (result == null || !result.isContinuable());
}

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.repeat.policy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -64,11 +64,11 @@ public class SimpleCompletionPolicy extends DefaultResultCompletionPolicy {
* Terminate if the chunk size has been reached, or the result is null.
*
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext,
* ExitStatus)
* RepeatStatus)
* @throws RuntimeException (normally terminating the batch) if the result is
* itself an exception.
*/
public boolean isComplete(RepeatContext context, ExitStatus result) {
public boolean isComplete(RepeatContext context, RepeatStatus result) {
return super.isComplete(context, result) || ((SimpleTerminationContext) context).isComplete();
}

View File

@@ -24,7 +24,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
@@ -52,7 +52,7 @@ import org.springframework.util.Assert;
* the {@link RepeatCallback} can consider using a custom {@link RepeatListener}
* instead of trying to customise the {@link CompletionPolicy}. This is
* generally a friendlier interface to implement, and the
* {@link RepeatListener#after(RepeatContext, ExitStatus)} method is passed in
* {@link RepeatListener#after(RepeatContext, RepeatStatus)} method is passed in
* the result of the callback, which would be an instance of {@link Throwable}
* if the business processing had thrown an exception. If the exception is not
* to be propagated to the caller, then a non-default {@link CompletionPolicy}
@@ -110,7 +110,7 @@ public class RepeatTemplate implements RepeatOperations {
/**
* Setter for policy to decide when the batch is complete. The default is to
* complete normally when the callback returns a {@link ExitStatus} which is
* complete normally when the callback returns a {@link RepeatStatus} which is
* not marked as continuable, and abnormally when the callback throws an
* exception (but the decision to re-throw the exception is deferred to the
* {@link ExceptionHandler}).
@@ -132,11 +132,11 @@ public class RepeatTemplate implements RepeatOperations {
*
* @see org.springframework.batch.repeat.RepeatOperations#iterate(org.springframework.batch.repeat.RepeatCallback)
*/
public ExitStatus iterate(RepeatCallback callback) {
public RepeatStatus iterate(RepeatCallback callback) {
RepeatContext outer = RepeatSynchronizationManager.getContext();
ExitStatus result = ExitStatus.CONTINUABLE;
RepeatStatus result = RepeatStatus.CONTINUABLE;
try {
// This works with an asynchronous TaskExecutor: the
// interceptors have to wait for the child processes.
@@ -162,7 +162,7 @@ public class RepeatTemplate implements RepeatOperations {
* for all the results from the callback.
*
*/
private ExitStatus executeInternal(final RepeatCallback callback) {
private RepeatStatus executeInternal(final RepeatCallback callback) {
// Reset the termination policy if there is one...
RepeatContext context = start();
@@ -180,7 +180,7 @@ public class RepeatTemplate implements RepeatOperations {
}
// Return value, default is to allow continued processing.
ExitStatus result = ExitStatus.CONTINUABLE;
RepeatStatus result = RepeatStatus.CONTINUABLE;
RepeatInternalState state = createInternalState(context);
Collection<Throwable> throwables = state.getThrowables();
@@ -346,7 +346,7 @@ public class RepeatTemplate implements RepeatOperations {
* @see #isComplete(RepeatContext)
* @see #createInternalState(RepeatContext)
*/
protected ExitStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state)
protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state)
throws Throwable {
update(context);
return callback.doInIteration(context);
@@ -358,7 +358,7 @@ public class RepeatTemplate implements RepeatOperations {
* processes. By default does nothing and returns true.
*
* @param state the internal state.
* @return true if {@link #canContinue(ExitStatus)} is true for all results
* @return true if {@link #canContinue(RepeatStatus)} is true for all results
* retrieved.
*/
protected boolean waitForResults(RepeatInternalState state) {
@@ -370,10 +370,10 @@ public class RepeatTemplate implements RepeatOperations {
* Check return value from batch operation.
*
* @param value the last callback result.
* @return true if the value is {@link ExitStatus#CONTINUABLE}.
* @return true if the value is {@link RepeatStatus#CONTINUABLE}.
*/
protected final boolean canContinue(ExitStatus value) {
return ((ExitStatus) value).isContinuable();
protected final boolean canContinue(RepeatStatus value) {
return ((RepeatStatus) value).isContinuable();
}
private boolean isMarkedComplete(RepeatContext context) {
@@ -394,7 +394,7 @@ public class RepeatTemplate implements RepeatOperations {
* @param context the current batch context.
* @param value the result of the callback to process.
*/
protected void executeAfterInterceptors(final RepeatContext context, ExitStatus value) {
protected void executeAfterInterceptors(final RepeatContext context, RepeatStatus value) {
// Don't re-throw exceptions here: let the exception handler deal with
// that...
@@ -413,9 +413,9 @@ public class RepeatTemplate implements RepeatOperations {
* Delegate to the {@link CompletionPolicy}.
*
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext,
* ExitStatus)
* RepeatStatus)
*/
protected boolean isComplete(RepeatContext context, ExitStatus result) {
protected boolean isComplete(RepeatContext context, RepeatStatus result) {
boolean complete = completionPolicy.isComplete(context, result);
if (complete) {
logger.debug("Repeat is complete according to policy and result value.");

View File

@@ -1,6 +1,6 @@
package org.springframework.batch.repeat.support;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
/**
@@ -16,7 +16,7 @@ interface ResultHolder {
* @return the result, or null if there is none.
* @throws IllegalStateException
*/
ExitStatus getResult();
RepeatStatus getResult();
/**
* Get the error for client from this holder if any. Does not block if

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.repeat.support;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
@@ -78,7 +78,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
* method so there is no need to synchronize access.
*
*/
protected ExitStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state)
protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state)
throws Throwable {
ExecutingRunnable runnable = null;
@@ -161,7 +161,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
state.getThrowables().add(future.getError());
}
else {
ExitStatus status = future.getResult();
RepeatStatus status = future.getResult();
result = result && canContinue(status);
executeAfterInterceptors(future.getContext(), status);
}
@@ -192,7 +192,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
private final ResultQueue<ResultHolder> queue;
private volatile ExitStatus result;
private volatile RepeatStatus result;
private volatile Throwable error;
@@ -241,7 +241,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate {
* Get the result - never blocks because the queue manages waiting for
* the task to finish.
*/
public ExitStatus getResult() {
public RepeatStatus getResult() {
return result;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.callback;
import junit.framework.TestCase;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -29,12 +29,12 @@ public class NestedRepeatCallbackTests extends TestCase {
public void testExecute() throws Exception {
NestedRepeatCallback callback = new NestedRepeatCallback(new RepeatTemplate(), new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return new ExitStatus(count <= 1);
return RepeatStatus.continueIf(count <= 1);
}
});
ExitStatus result = callback.doInIteration(null);
RepeatStatus result = callback.doInIteration(null);
assertEquals(2, count);
assertFalse(result.isContinuable()); // False because processing has finished
}

View File

@@ -27,7 +27,7 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatException;
import org.springframework.batch.repeat.RepeatOperations;
@@ -68,7 +68,7 @@ public class RepeatOperationsInterceptorTests extends TestCase {
public void testSetTemplate() throws Exception {
final List<Object> calls = new ArrayList<Object>();
interceptor.setRepeatOperations(new RepeatOperations() {
public ExitStatus iterate(RepeatCallback callback) {
public RepeatStatus iterate(RepeatCallback callback) {
try {
Object result = callback.doInIteration(null);
calls.add(result);
@@ -76,7 +76,7 @@ public class RepeatOperationsInterceptorTests extends TestCase {
catch (Exception e) {
throw new RepeatException("Encountered exception in repeat.", e);
}
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
});
((Advised) service).addAdvice(interceptor);
@@ -87,9 +87,9 @@ public class RepeatOperationsInterceptorTests extends TestCase {
public void testCallbackNotExecuted() throws Exception {
final List<Object> calls = new ArrayList<Object>();
interceptor.setRepeatOperations(new RepeatOperations() {
public ExitStatus iterate(RepeatCallback callback) {
public RepeatStatus iterate(RepeatCallback callback) {
calls.add(null);
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
});
((Advised) service).addAdvice(interceptor);

View File

@@ -21,7 +21,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatListener;
@@ -46,9 +46,9 @@ public class RepeatListenerTests extends TestCase {
}
} });
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return new ExitStatus(count <= 1);
return RepeatStatus.continueIf(count <= 1);
}
});
// 2 calls: the second time there is no processing
@@ -69,9 +69,9 @@ public class RepeatListenerTests extends TestCase {
}
});
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
});
assertEquals(0, count);
@@ -83,18 +83,18 @@ public class RepeatListenerTests extends TestCase {
RepeatTemplate template = new RepeatTemplate();
final List<Object> calls = new ArrayList<Object>();
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
public void after(RepeatContext context, ExitStatus result) {
public void after(RepeatContext context, RepeatStatus result) {
calls.add("1");
}
}, new RepeatListenerSupport() {
public void after(RepeatContext context, ExitStatus result) {
public void after(RepeatContext context, RepeatStatus result) {
calls.add("2");
}
} });
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return new ExitStatus(count <= 1);
return RepeatStatus.continueIf(count <= 1);
}
});
// 2 calls to the callback, and the second one had no processing...
@@ -117,9 +117,9 @@ public class RepeatListenerTests extends TestCase {
}
} });
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
});
assertEquals(0, count);
@@ -135,10 +135,10 @@ public class RepeatListenerTests extends TestCase {
}
});
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
context.setCompleteOnly();
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
});
assertEquals(1, count);
@@ -158,9 +158,9 @@ public class RepeatListenerTests extends TestCase {
}
} });
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return new ExitStatus(count < 2);
return RepeatStatus.continueIf(count < 2);
}
});
// Test that more than one call comes in to the callback...
@@ -184,7 +184,7 @@ public class RepeatListenerTests extends TestCase {
} });
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
throw new IllegalStateException("Bogus");
}
});
@@ -201,7 +201,7 @@ public class RepeatListenerTests extends TestCase {
RepeatTemplate template = new RepeatTemplate();
final List<Object> calls = new ArrayList<Object>();
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
public void after(RepeatContext context, ExitStatus result) {
public void after(RepeatContext context, RepeatStatus result) {
calls.add("1");
}
}, new RepeatListenerSupport() {
@@ -211,7 +211,7 @@ public class RepeatListenerTests extends TestCase {
} });
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
throw new IllegalStateException("Bogus");
}
});
@@ -231,7 +231,7 @@ public class RepeatListenerTests extends TestCase {
final List<Object> calls = new ArrayList<Object>();
final List<Object> fails = new ArrayList<Object>();
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
public void after(RepeatContext context, ExitStatus result) {
public void after(RepeatContext context, RepeatStatus result) {
calls.add("1");
}
}, new RepeatListenerSupport() {
@@ -242,7 +242,7 @@ public class RepeatListenerTests extends TestCase {
} });
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
throw new IllegalStateException("Bogus");
}
});

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.repeat.policy;
import junit.framework.TestCase;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
public class CompositeCompletionPolicyTests extends TestCase {
@@ -59,7 +59,7 @@ public class CompositeCompletionPolicyTests extends TestCase {
CompositeCompletionPolicy policy = new CompositeCompletionPolicy();
policy.setPolicies(new CompletionPolicy[] { new MockCompletionPolicySupport(),
new MockCompletionPolicySupport() {
public boolean isComplete(RepeatContext context, ExitStatus result) {
public boolean isComplete(RepeatContext context, RepeatStatus result) {
return true;
}
} });

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.policy;
import junit.framework.TestCase;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
@@ -53,7 +53,7 @@ public class CountingCompletionPolicyTests extends TestCase {
};
policy.setMaxCount(10);
RepeatContext context = policy.start(null);
assertTrue(policy.isComplete(context, ExitStatus.FINISHED));
assertTrue(policy.isComplete(context, RepeatStatus.FINISHED));
}
public void testDefaultBehaviourWithUpdate() throws Exception {

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.policy;
import junit.framework.TestCase;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
public class SimpleCompletionPolicyTests extends TestCase {
@@ -27,7 +27,7 @@ public class SimpleCompletionPolicyTests extends TestCase {
RepeatContext context;
ExitStatus dummy = ExitStatus.CONTINUABLE;
RepeatStatus dummy = RepeatStatus.CONTINUABLE;
protected void setUp() throws Exception {
super.setUp();

View File

@@ -16,10 +16,11 @@
package org.springframework.batch.repeat.policy;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatContext;
public class TimeoutCompletionPolicyTests {
@@ -43,7 +44,7 @@ public class TimeoutCompletionPolicyTests {
@Test
public void testNonContinuableResult() throws Exception {
TimeoutTerminationPolicy policy = new TimeoutTerminationPolicy();
ExitStatus result = new ExitStatus(false, "non-continuable exit status");
RepeatStatus result = RepeatStatus.FINISHED;
assertTrue(policy.isComplete(policy.start(null), result));
}

View File

@@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
@@ -42,7 +42,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
final Set<String> threadNames = new HashSet<String>();
final RepeatCallback callback = new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
assertNotSame(threadName, Thread.currentThread().getName());
threadNames.add(Thread.currentThread().getName());
Thread.sleep(100);
@@ -50,7 +50,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
if (item!=null) {
processor.write(Collections.singletonList(item));
}
return new ExitStatus(item!=null);
return RepeatStatus.continueIf(item!=null);
}
};
@@ -78,7 +78,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
final Set<String> threadNames = new HashSet<String>();
final RepeatCallback stepCallback = new ItemReaderRepeatCallback<Trade>(provider, processor) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
assertNotSame(threadName, Thread.currentThread().getName());
threadNames.add(Thread.currentThread().getName());
Thread.sleep(100);
@@ -86,9 +86,9 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
}
};
RepeatCallback jobCallback = new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
stepTemplate.iterate(stepCallback);
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
};

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.repeat.support;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.callback.NestedRepeatCallback;
@@ -51,9 +51,9 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
// once
chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
ExitStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++; // for test assertion
return super.doInIteration(context);
}
@@ -86,9 +86,9 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
chunkTemplate.setTaskExecutor(new SimpleAsyncTaskExecutor());
ExitStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++; // for test assertion
return super.doInIteration(context);
}
@@ -158,8 +158,8 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
chunker.reset();
template.iterate(new ItemReaderRepeatCallback<Trade>(truncated, processor) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
ExitStatus result = super.doInIteration(context);
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
RepeatStatus result = super.doInIteration(context);
if (!result.isContinuable() && chunker.first()) {
chunker.set();
}

View File

@@ -19,7 +19,7 @@ import java.util.Collections;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
@@ -44,13 +44,13 @@ public class ItemReaderRepeatCallback<T> implements RepeatCallback {
/* (non-Javadoc)
* @see org.springframework.batch.repeat.RepeatCallback#doInIteration(org.springframework.batch.repeat.RepeatContext)
*/
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
T item = reader.read();
if (item==null) {
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
writer.write(Collections.singletonList(item));
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
}

View File

@@ -20,7 +20,6 @@ import junit.framework.TestCase;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
public class RepeatSynchronizationManagerTests extends TestCase {

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.repeat.support;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
@@ -73,7 +73,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
throw new IllegalStateException("foo!");
}
@@ -109,9 +109,9 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
}
});
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
return new ExitStatus(count < 1);
return RepeatStatus.continueIf(count < 1);
}
});
@@ -143,7 +143,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
throw new RuntimeException("foo");
}
@@ -176,7 +176,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
throw new RuntimeException("foo");
}
@@ -198,10 +198,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
*/
public void testEarlyCompletionWithContext() throws Exception {
ExitStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
ExitStatus result = super.doInIteration(context);
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
RepeatStatus result = super.doInIteration(context);
if (processor.count >= 2) {
context.setCompleteOnly();
// If we return null the batch will terminate anyway
@@ -226,10 +226,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
*/
public void testEarlyCompletionWithContextTerminated() throws Exception {
ExitStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
ExitStatus result = super.doInIteration(context);
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
RepeatStatus result = super.doInIteration(context);
if (processor.count >= 2) {
context.setTerminateOnly();
// If we return null the batch will terminate anyway
@@ -251,15 +251,15 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
RepeatTemplate outer = getRepeatTemplate();
RepeatTemplate inner = getRepeatTemplate();
outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
assertNotNull(context);
assertNotSame("Nested batch should have new session", context, context.getParent());
assertSame(context, RepeatSynchronizationManager.getContext());
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
}) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
assertSame(context, RepeatSynchronizationManager.getContext());
return super.doInIteration(context);
@@ -272,14 +272,14 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
RepeatTemplate outer = getRepeatTemplate();
RepeatTemplate inner = getRepeatTemplate();
outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
assertEquals(2, count);
fail("Nested batch should not have been executed");
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
}) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
context.setCompleteOnly();
return super.doInIteration(context);
@@ -293,19 +293,19 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
outer.setCompletionPolicy(new SimpleCompletionPolicy(2));
RepeatTemplate inner = getRepeatTemplate();
outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
assertNotNull(context);
assertNotSame("Nested batch should have new session", context, context.getParent());
assertSame(context, RepeatSynchronizationManager.getContext());
return ExitStatus.FINISHED;
return RepeatStatus.FINISHED;
}
}) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
assertSame(context, RepeatSynchronizationManager.getContext());
super.doInIteration(context);
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
});
assertEquals(4, count);
@@ -316,7 +316,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
* @throws Exception
*/
public void testResult() throws Exception {
ExitStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor));
RepeatStatus result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor));
assertEquals(NUMBER_OF_ITEMS, processor.count);
// We are complete - do not expect to be called again
assertFalse(result.isContinuable());
@@ -326,10 +326,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
count++;
if (count < 2) {
return ExitStatus.CONTINUABLE;
return RepeatStatus.CONTINUABLE;
}
throw new RuntimeException("Barf second try count=" + count);
}
@@ -352,13 +352,13 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
template.setCompletionPolicy(new SimpleCompletionPolicy(4));
ExitStatus result = ExitStatus.FINISHED;
RepeatStatus result = RepeatStatus.FINISHED;
try {
result = template.iterate(new ItemReaderRepeatCallback<Trade>(provider, processor) {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
ExitStatus result = super.doInIteration(context);
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
RepeatStatus result = super.doInIteration(context);
if (processor.count >= 2) {
context.setCompleteOnly();
throw new RuntimeException("Barf second try count=" + processor.count);
@@ -383,20 +383,6 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
}
public void testCustomExitCode() {
ExitStatus status = template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
ExitStatus exitStatus = new ExitStatus(false, "CUSTOM_CODE");
return exitStatus;
}
});
assertEquals("CUSTOM_CODE", status.getExitCode());
}
/**
* Checked exceptions are wrapped into runtime RepeatException.
* RepeatException should be unwrapped before before it is passed to
@@ -438,7 +424,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
try {
template.iterate(new RepeatCallback() {
public ExitStatus doInIteration(RepeatContext context) throws Exception {
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
throw new RepeatException("typically thrown by nested repeat template", exception);
}
});

View File

@@ -15,7 +15,10 @@
*/
package org.springframework.batch.repeat.support;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.NoSuchElementException;

View File

@@ -5,13 +5,13 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.integration.chunk;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.integration.chunk;
import java.io.Serializable;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
public class ChunkResponse implements Serializable {

View File

@@ -16,12 +16,12 @@
package org.springframework.batch.integration.job;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
@@ -97,10 +97,10 @@ public class MessageOrientedStep extends AbstractStep {
* @see AbstractStep#execute(StepExecution)
*/
@Override
public ExitStatus doExecute(StepExecution stepExecution) throws JobInterruptedException,
protected void doExecute(StepExecution stepExecution) throws JobInterruptedException,
UnexpectedJobExecutionException {
JobExecutionRequest request = new JobExecutionRequest(stepExecution .getJobExecution());
JobExecutionRequest request = new JobExecutionRequest(stepExecution.getJobExecution());
ExecutionContext executionContext = stepExecution.getExecutionContext();
@@ -116,7 +116,7 @@ public class MessageOrientedStep extends AbstractStep {
waitForReply(request.getJobId());
}
return ExitStatus.FINISHED;
stepExecution.setExitStatus(ExitStatus.FINISHED);
}

View File

@@ -10,6 +10,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
@@ -26,7 +27,6 @@ import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.item.SimpleStepFactoryBean;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

View File

@@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals;
import java.util.Collection;
import org.junit.Test;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.util.StringUtils;
public class ChunkProcessorChunkHandlerTests {

View File

@@ -25,12 +25,12 @@ import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.integration.JobRepositorySupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.channel.DirectChannel;

View File

@@ -15,9 +15,9 @@
*/
package org.springframework.batch.integration.job;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;
/**

Some files were not shown because too many files have changed in this diff Show More