BATCH-220: Complete rename StepHandler -> Tasklet
This commit is contained in:
@@ -22,7 +22,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.listener.MulticasterBatchListener;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
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;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.batch.repeat.RepeatOperations;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
/**
|
||||
* Simplest possible implementation of {@link StepHandler} with no skipping or
|
||||
* Simplest possible implementation of {@link Tasklet} with no skipping or
|
||||
* recovering. Just delegates all calls to the provided {@link ItemReader} and
|
||||
* {@link ItemWriter}.
|
||||
*
|
||||
@@ -44,7 +44,7 @@ import org.springframework.core.AttributeAccessor;
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemOrientedStepHandler<T, S> implements StepHandler {
|
||||
public class ChunkOrientedTasklet<T, S> implements Tasklet {
|
||||
|
||||
private static final String INPUT_BUFFER_KEY = "INPUT_BUFFER_KEY";
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ItemOrientedStepHandler<T, S> implements StepHandler {
|
||||
* @param itemWriter
|
||||
* @param repeatOperations
|
||||
*/
|
||||
public ItemOrientedStepHandler(ItemReader<? extends T> itemReader,
|
||||
public ChunkOrientedTasklet(ItemReader<? extends T> itemReader,
|
||||
ItemProcessor<? super T, ? extends S> itemProcessor, ItemWriter<? super S> itemWriter,
|
||||
RepeatOperations repeatOperations) {
|
||||
super();
|
||||
@@ -114,10 +114,10 @@ public class ItemOrientedStepHandler<T, S> implements StepHandler {
|
||||
* {@link ItemProcessor} returns null, the write is omitted and another item
|
||||
* taken from the reader.
|
||||
*
|
||||
* @see org.springframework.batch.core.step.tasklet.StepHandler#handle(org.springframework.batch.core.StepContribution,
|
||||
* @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution,
|
||||
* AttributeAccessor)
|
||||
*/
|
||||
public ExitStatus handle(final StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(final StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
|
||||
// TODO: check flags to see if these need to be saved or not (e.g. JMS not)
|
||||
final Chunk<T> inputs = getInputBuffer(attributes);
|
||||
@@ -21,7 +21,7 @@ import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
@@ -262,7 +262,7 @@ public class SimpleStepFactoryBean<T,S> implements FactoryBean, BeanNameAware {
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
public final Object getObject() throws Exception {
|
||||
StepHandlerStep step = new StepHandlerStep(getName());
|
||||
TaskletStep step = new TaskletStep(getName());
|
||||
applyConfiguration(step);
|
||||
return step;
|
||||
}
|
||||
@@ -387,7 +387,7 @@ public class SimpleStepFactoryBean<T,S> implements FactoryBean, BeanNameAware {
|
||||
* @param step
|
||||
*
|
||||
*/
|
||||
protected void applyConfiguration(StepHandlerStep step) {
|
||||
protected void applyConfiguration(TaskletStep step) {
|
||||
|
||||
Assert.notNull(getItemReader(), "ItemReader must be provided");
|
||||
Assert.notNull(getItemWriter(), "ItemWriter must be provided");
|
||||
@@ -457,9 +457,9 @@ public class SimpleStepFactoryBean<T,S> implements FactoryBean, BeanNameAware {
|
||||
|
||||
step.setStepOperations(stepOperations);
|
||||
|
||||
ItemOrientedStepHandler<T,S> stepHandler = new ItemOrientedStepHandler<T,S>(itemReader, itemProcessor, itemWriter, chunkOperations);
|
||||
stepHandler.setListeners(getListeners());
|
||||
step.setStepHandler(stepHandler);
|
||||
ChunkOrientedTasklet<T,S> tasklet = new ChunkOrientedTasklet<T,S>(itemReader, itemProcessor, itemWriter, chunkOperations);
|
||||
tasklet.setListeners(getListeners());
|
||||
step.setTasklet(tasklet);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.springframework.batch.core.step.skip.ItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
|
||||
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -194,7 +194,7 @@ public class SkipLimitStepFactoryBean<T, S> extends SimpleStepFactoryBean<T, S>
|
||||
* Uses the {@link #setSkipLimit(int)} value to configure item handler and
|
||||
* and exception handler.
|
||||
*/
|
||||
protected void applyConfiguration(StepHandlerStep step) {
|
||||
protected void applyConfiguration(TaskletStep step) {
|
||||
super.applyConfiguration(step);
|
||||
|
||||
if (retryLimit > 0 || skipLimit > 0 || retryPolicy != null) {
|
||||
@@ -261,12 +261,12 @@ public class SkipLimitStepFactoryBean<T, S> extends SimpleStepFactoryBean<T, S>
|
||||
exceptions.addAll(new ArrayList<Class<? extends Throwable>>(retryableExceptionClasses));
|
||||
ItemSkipPolicy writeSkipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, exceptions,
|
||||
new ArrayList<Class<? extends Throwable>>(fatalExceptionClasses));
|
||||
ItemOrientedStepHandler<T, S> stepHandler = new StatefulRetryStepHandler<T, S>(getItemReader(),
|
||||
ChunkOrientedTasklet<T, S> tasklet = new StatefulRetryTasklet<T, S>(getItemReader(),
|
||||
getItemProcessor(), getItemWriter(), getChunkOperations(), retryTemplate, readSkipPolicy,
|
||||
writeSkipPolicy);
|
||||
stepHandler.setListeners(getListeners());
|
||||
tasklet.setListeners(getListeners());
|
||||
|
||||
step.setStepHandler(stepHandler);
|
||||
step.setTasklet(tasklet);
|
||||
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class SkipLimitStepFactoryBean<T, S> extends SimpleStepFactoryBean<T, S>
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
static class StatefulRetryStepHandler<T, S> extends ItemOrientedStepHandler<T, S> {
|
||||
static class StatefulRetryTasklet<T, S> extends ChunkOrientedTasklet<T, S> {
|
||||
|
||||
final private RetryOperations retryOperations;
|
||||
|
||||
@@ -309,7 +309,7 @@ public class SkipLimitStepFactoryBean<T, S> extends SimpleStepFactoryBean<T, S>
|
||||
* @param itemWriter
|
||||
* @param retryTemplate
|
||||
*/
|
||||
public StatefulRetryStepHandler(ItemReader<? extends T> itemReader,
|
||||
public StatefulRetryTasklet(ItemReader<? extends T> itemReader,
|
||||
ItemProcessor<? super T, ? extends S> itemProcessor, ItemWriter<? super S> itemWriter,
|
||||
RepeatOperations chunkOperations, RetryOperations retryTemplate, ItemSkipPolicy readSkipPolicy,
|
||||
ItemSkipPolicy writeSkipPolicy) {
|
||||
|
||||
@@ -25,12 +25,12 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Adapts a {@link Callable}<{@link ExitStatus}> to the
|
||||
* {@link StepHandler} interface.
|
||||
* {@link Tasklet} interface.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class CallableStepHandlerAdapter implements StepHandler, InitializingBean {
|
||||
public class CallableTaskletAdapter implements Tasklet, InitializingBean {
|
||||
|
||||
private Callable<ExitStatus> callable;
|
||||
|
||||
@@ -54,9 +54,9 @@ public class CallableStepHandlerAdapter implements StepHandler, InitializingBean
|
||||
/**
|
||||
* Execute the provided Callable and return its {@link ExitStatus}. Ignores
|
||||
* the {@link StepContribution} and the attributes.
|
||||
* @see StepHandler#handle(StepContribution, AttributeAccessor)
|
||||
* @see Tasklet#execute(StepContribution, AttributeAccessor)
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
return callable.call();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
/**
|
||||
* A {@link StepHandler} that wraps a method in a POJO. By default the return
|
||||
* A {@link Tasklet} that wraps a method in a POJO. By default the return
|
||||
* value is {@link ExitStatus#FINISHED} unless the delegate POJO itself returns
|
||||
* an {@link ExitStatus}. The POJO method is usually going to have no arguments,
|
||||
* but a static argument or array of arguments can be used by setting the
|
||||
@@ -32,16 +32,16 @@ import org.springframework.core.AttributeAccessor;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StepHandlerAdapter extends AbstractMethodInvokingDelegator<Object> implements StepHandler {
|
||||
public class MethodInvokingTaskletAdapter extends AbstractMethodInvokingDelegator<Object> implements Tasklet {
|
||||
|
||||
/**
|
||||
* Delegate execution to the target object and translate the return value to
|
||||
* an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores
|
||||
* the {@link StepContribution} and the attributes.
|
||||
*
|
||||
* @see StepHandler#handle(StepContribution, AttributeAccessor)
|
||||
* @see Tasklet#execute(StepContribution, AttributeAccessor)
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
return mapResult(invokeDelegateMethod());
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.springframework.core.AttributeAccessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link StepHandler} that executes a system command.
|
||||
* {@link Tasklet} that executes a system command.
|
||||
*
|
||||
* The system command is executed in a new thread - timeout value is required to
|
||||
* be set, so that the batch job does not hang forever if the external process
|
||||
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class SystemCommandStepHandler extends StepExecutionListenerSupport implements StepHandler, InitializingBean {
|
||||
public class SystemCommandTasklet extends StepExecutionListenerSupport implements Tasklet, InitializingBean {
|
||||
|
||||
private String command;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SystemCommandStepHandler extends StepExecutionListenerSupport imple
|
||||
* Execute system command and map its exit code to {@link ExitStatus} using
|
||||
* {@link SystemProcessExitCodeMapper}.
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
ExecutorThread executorThread = new ExecutorThread();
|
||||
executorThread.start();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.springframework.batch.core.step.tasklet;
|
||||
|
||||
import org.springframework.batch.core.step.tasklet.SystemCommandStepHandler;
|
||||
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
|
||||
* returned by a system command. Designed for use with the
|
||||
* {@link SystemCommandStepHandler}.
|
||||
* {@link SystemCommandTasklet}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
|
||||
@@ -16,34 +16,30 @@
|
||||
package org.springframework.batch.core.step.tasklet;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
/**
|
||||
* Strategy for processing in a step. Bears a resemblance to {@link ItemReader}
|
||||
* and {@link ItemWriter} because part of the contract of the processor is that
|
||||
* it should delegate calls to those interfaces.
|
||||
* Strategy for processing in a step.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface StepHandler {
|
||||
public interface Tasklet {
|
||||
|
||||
/**
|
||||
* Given the current context in the form of a step contribution, do whatever
|
||||
* is necessary to process this unit inside a chunk. Implementations obtain
|
||||
* the item and return {@link ExitStatus#FINISHED} if it is null. If it is
|
||||
* not null process the item and return {@link ExitStatus#CONTINUABLE}. On
|
||||
* failure throws an exception.
|
||||
* is necessary to process this unit inside a transaction. Implementations
|
||||
* return {@link ExitStatus#FINISHED} if finished. If not they return
|
||||
* {@link ExitStatus#CONTINUABLE}. On failure throws an exception.
|
||||
*
|
||||
* @param contribution mutable state to be passed back to update the current
|
||||
* step execution
|
||||
* @param attributes attributes shared between invocations
|
||||
* @param attributes attributes shared between invocations but not between
|
||||
* restarts
|
||||
* @return an {@link ExitStatus} indicating whether processing is
|
||||
* continuable.
|
||||
*/
|
||||
ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception;
|
||||
ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception;
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.batch.core.step.StepExecutionSynchronizer;
|
||||
@@ -49,10 +48,11 @@ import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
|
||||
import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||
|
||||
/**
|
||||
* Simple implementation of executing the step as a set of chunks, each chunk
|
||||
* surrounded by a transaction. The structure is therefore that of a loop with
|
||||
* transaction boundary inside the loop. The loop is controlled by the step
|
||||
* operations ( {@link #setStepOperations(RepeatOperations)}).<br/>
|
||||
* Simple implementation of executing the step as a call to a {@link Tasklet},
|
||||
* possibly repeated, and each call surrounded by a transaction. The structure
|
||||
* is therefore that of a loop with transaction boundary inside the loop. The
|
||||
* loop is controlled by the step operations (
|
||||
* {@link #setStepOperations(RepeatOperations)}).<br/><br/>
|
||||
*
|
||||
* Clients can use interceptors in the step operations to intercept or listen to
|
||||
* the iteration on a step-wide basis, for instance to get a callback when the
|
||||
@@ -64,9 +64,9 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||
* @author Ben Hale
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class StepHandlerStep extends AbstractStep {
|
||||
public class TaskletStep extends AbstractStep {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(StepHandlerStep.class);
|
||||
private static final Log logger = LogFactory.getLog(TaskletStep.class);
|
||||
|
||||
private RepeatOperations stepOperations = new RepeatTemplate();
|
||||
|
||||
@@ -79,21 +79,21 @@ public class StepHandlerStep extends AbstractStep {
|
||||
|
||||
private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute();
|
||||
|
||||
private StepHandler stepHandler;
|
||||
private Tasklet tasklet;
|
||||
|
||||
private StepExecutionSynchronizer synchronizer;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public StepHandlerStep() {
|
||||
public TaskletStep() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public StepHandlerStep(String name) {
|
||||
public TaskletStep(String name) {
|
||||
super(name);
|
||||
synchronizer = new StepExecutionSynchronizerFactory().getStepExecutionSynchronizer();
|
||||
}
|
||||
@@ -116,14 +116,14 @@ public class StepHandlerStep extends AbstractStep {
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the {@link StepHandler}.
|
||||
* Public setter for the {@link Tasklet}.
|
||||
*
|
||||
* @param stepHandler the {@link StepHandler} to set
|
||||
* @param tasklet the {@link Tasklet} to set
|
||||
*/
|
||||
public void setStepHandler(StepHandler stepHandler) {
|
||||
this.stepHandler = stepHandler;
|
||||
if (stepHandler instanceof StepExecutionListener) {
|
||||
registerStepExecutionListener((StepExecutionListener) stepHandler);
|
||||
public void setTasklet(Tasklet tasklet) {
|
||||
this.tasklet = tasklet;
|
||||
if (tasklet instanceof StepExecutionListener) {
|
||||
registerStepExecutionListener((StepExecutionListener) tasklet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public class StepHandlerStep extends AbstractStep {
|
||||
try {
|
||||
|
||||
try {
|
||||
exitStatus = stepHandler.handle(contribution, attributes);
|
||||
exitStatus = tasklet.execute(contribution, attributes);
|
||||
}
|
||||
catch (Error e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
@@ -42,7 +42,7 @@ import org.springframework.core.AttributeAccessor;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ItemOrientedStepHandlerTests {
|
||||
public class ChunkOrientedTaskletTests {
|
||||
|
||||
private StubItemReader itemReader = new StubItemReader();
|
||||
|
||||
@@ -59,22 +59,22 @@ public class ItemOrientedStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testHandle() throws Exception {
|
||||
ItemOrientedStepHandler<String, String> handler = new ItemOrientedStepHandler<String, String>(itemReader,
|
||||
ChunkOrientedTasklet<String, String> handler = new ChunkOrientedTasklet<String, String>(itemReader,
|
||||
new PassthroughItemProcessor<String>(), itemWriter, repeatTemplate);
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
handler.handle(contribution, context);
|
||||
handler.execute(contribution, context);
|
||||
assertEquals(2, itemReader.count);
|
||||
assertEquals("12", itemWriter.values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleCompositeItem() throws Exception {
|
||||
ItemOrientedStepHandler<String, String> handler = new ItemOrientedStepHandler<String, String>(itemReader,
|
||||
ChunkOrientedTasklet<String, String> handler = new ChunkOrientedTasklet<String, String>(itemReader,
|
||||
new AgrgegateItemProcessor(), itemWriter, repeatTemplate);
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
handler.handle(contribution, context);
|
||||
handler.execute(contribution, context);
|
||||
assertEquals(2, itemReader.count);
|
||||
assertEquals("12", itemWriter.values);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.item.SkipLimitStepFactoryBean.StatefulRetryStepHandler;
|
||||
import org.springframework.batch.core.step.item.SkipLimitStepFactoryBean.StatefulRetryTasklet;
|
||||
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
|
||||
import org.springframework.batch.core.step.tasklet.BasicAttributeAccessor;
|
||||
@@ -47,7 +47,7 @@ import org.springframework.batch.retry.support.RetryTemplate;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StatefulRetryStepHandlerTests {
|
||||
public class StatefulRetryTaskletTests {
|
||||
|
||||
private Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
protected List<String> written = new ArrayList<String>();
|
||||
|
||||
private StatefulRetryStepHandler<Integer, String> handler;
|
||||
private StatefulRetryTasklet<Integer, String> handler;
|
||||
|
||||
private RepeatTemplate chunkOperations = new RepeatTemplate();
|
||||
|
||||
@@ -101,16 +101,16 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testBasicHandle() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(itemReader, itemProcessor, itemWriter, chunkOperations,
|
||||
handler = new StatefulRetryTasklet<Integer, String>(itemReader, itemProcessor, itemWriter, chunkOperations,
|
||||
retryTemplate, readSkipPolicy, writeSkipPolicy);
|
||||
StepContribution contribution = new StepExecution("foo", null).createStepContribution();
|
||||
handler.handle(contribution, new BasicAttributeAccessor());
|
||||
handler.execute(contribution, new BasicAttributeAccessor());
|
||||
assertEquals(limit, contribution.getItemCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipOnRead() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(new ItemReader<Integer>() {
|
||||
handler = new StatefulRetryTasklet<Integer, String>(new ItemReader<Integer>() {
|
||||
public Integer read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
|
||||
throw new RuntimeException("Barf!");
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
StepContribution contribution = new StepExecution("foo", null).createStepContribution();
|
||||
BasicAttributeAccessor attributes = new BasicAttributeAccessor();
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected SkipLimitExceededException");
|
||||
}
|
||||
catch (SkipLimitExceededException e) {
|
||||
@@ -131,7 +131,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testSkipSingleItemOnWrite() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
handler = new StatefulRetryTasklet<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
written.addAll(items);
|
||||
throw new RuntimeException("Barf!");
|
||||
@@ -141,14 +141,14 @@ public class StatefulRetryStepHandlerTests {
|
||||
StepContribution contribution = new StepExecution("foo", null).createStepContribution();
|
||||
BasicAttributeAccessor attributes = new BasicAttributeAccessor();
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("Barf!", e.getMessage());
|
||||
}
|
||||
assertTrue(attributes.hasAttribute("OUTPUT_BUFFER_KEY"));
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
assertEquals(1, contribution.getItemCount());
|
||||
assertEquals(1, contribution.getWriteSkipCount());
|
||||
assertEquals(1, written.size());
|
||||
@@ -156,7 +156,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testSkipMultipleItems() throws Exception {
|
||||
handler = new StatefulRetryStepHandler<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
handler = new StatefulRetryTasklet<Integer, String>(itemReader, itemProcessor, new ItemWriter<String>() {
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
logger.debug("Writing items: "+items);
|
||||
written.addAll(items);
|
||||
@@ -170,7 +170,7 @@ public class StatefulRetryStepHandlerTests {
|
||||
// Count to 3: (try + skip + skip)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected RuntimeException on i="+i);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -182,18 +182,18 @@ public class StatefulRetryStepHandlerTests {
|
||||
Chunk<String> chunk = (Chunk<String>) attributes.getAttribute("OUTPUT_BUFFER_KEY");
|
||||
assertEquals(1, chunk.getSkips().size());
|
||||
// The last recovery for this chunk...
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
|
||||
attributes = new BasicAttributeAccessor();
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected RuntimeException on i=");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals("Barf!", e.getMessage());
|
||||
}
|
||||
try {
|
||||
handler.handle(contribution, attributes);
|
||||
handler.execute(contribution, attributes);
|
||||
fail("Expected SkipLimitExceededException");
|
||||
}
|
||||
catch (SkipLimitExceededException e) {
|
||||
@@ -21,12 +21,12 @@ import static org.junit.Assert.fail;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.step.tasklet.CallableStepHandlerAdapter;
|
||||
import org.springframework.batch.core.step.tasklet.CallableTaskletAdapter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
public class CallableStepHandlerAdapterTests {
|
||||
public class CallableTaskletAdapterTests {
|
||||
|
||||
private CallableStepHandlerAdapter adapter = new CallableStepHandlerAdapter();
|
||||
private CallableTaskletAdapter adapter = new CallableTaskletAdapter();
|
||||
|
||||
@Test
|
||||
public void testHandle() throws Exception {
|
||||
@@ -35,7 +35,7 @@ public class CallableStepHandlerAdapterTests {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
});
|
||||
assertEquals(ExitStatus.FINISHED, adapter.handle(null,null));
|
||||
assertEquals(ExitStatus.FINISHED, adapter.execute(null,null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,7 +39,7 @@ import org.springframework.batch.core.repository.dao.MapJobExecutionDao;
|
||||
import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
|
||||
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
|
||||
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -59,9 +59,9 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/core/repository/dao/sql-dao-test.xml")
|
||||
public class StepHandlerStepIntegrationTests {
|
||||
public class ChunkOrientedStepIntegrationTests {
|
||||
|
||||
private StepHandlerStep step;
|
||||
private TaskletStep step;
|
||||
|
||||
private Job job;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class StepHandlerStepIntegrationTests {
|
||||
jobRepositoryFactoryBean.afterPropertiesSet();
|
||||
jobRepository = (JobRepository) jobRepositoryFactoryBean.getObject();
|
||||
|
||||
step = new StepHandlerStep("stepName");
|
||||
step = new TaskletStep("stepName");
|
||||
step.setJobRepository(jobRepository);
|
||||
step.setTransactionManager(transactionManager);
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
@@ -112,7 +112,7 @@ public class StepHandlerStepIntegrationTests {
|
||||
@Test
|
||||
public void testStatusForCommitFailedException() throws Exception {
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(getReader(new String[] { "a", "b", "c" }),
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(getReader(new String[] { "a", "b", "c" }),
|
||||
new ItemWriter<String>() {
|
||||
public void write(List<? extends String> data) throws Exception {
|
||||
TransactionSynchronizationManager
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.tasklet;
|
||||
|
||||
import org.springframework.batch.core.step.item.ItemOrientedStepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
import org.springframework.batch.core.step.item.ChunkOrientedTasklet;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.PassthroughItemProcessor;
|
||||
@@ -25,13 +25,13 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
|
||||
/**
|
||||
* Simplest possible implementation of {@link StepHandler} with no skipping or
|
||||
* Simplest possible implementation of {@link Tasklet} with no skipping or
|
||||
* recovering or processing. Just delegates all calls to the provided
|
||||
* {@link ItemReader} and {@link ItemWriter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SimpleStepHandler<T> extends ItemOrientedStepHandler<T, T> {
|
||||
public class SimpleChunkOrientedTasklet<T> extends ChunkOrientedTasklet<T, T> {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -45,17 +45,17 @@ public class SimpleStepHandler<T> extends ItemOrientedStepHandler<T, T> {
|
||||
|
||||
/**
|
||||
* Creates a {@link PassthroughItemProcessor} and uses it to create an
|
||||
* instance of {@link ItemOrientedStepHandler}.
|
||||
* instance of {@link ChunkOrientedTasklet}.
|
||||
*/
|
||||
public SimpleStepHandler(ItemReader<T> itemReader, ItemWriter<T> itemWriter) {
|
||||
public SimpleChunkOrientedTasklet(ItemReader<T> itemReader, ItemWriter<T> itemWriter) {
|
||||
super(itemReader, new PassthroughItemProcessor<T>(), itemWriter, repeatTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PassthroughItemProcessor} and uses it to create an
|
||||
* instance of {@link ItemOrientedStepHandler}.
|
||||
* instance of {@link ChunkOrientedTasklet}.
|
||||
*/
|
||||
public SimpleStepHandler(ItemReader<T> itemReader, ItemWriter<T> itemWriter, RepeatOperations repeatOperations) {
|
||||
public SimpleChunkOrientedTasklet(ItemReader<T> itemReader, ItemWriter<T> itemWriter, RepeatOperations repeatOperations) {
|
||||
super(itemReader, new PassthroughItemProcessor<T>(), itemWriter, repeatOperations);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
|
||||
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
|
||||
import org.springframework.batch.core.repository.support.SimpleJobRepository;
|
||||
import org.springframework.batch.core.step.StepExecutionSynchronizer;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana
|
||||
|
||||
public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
private StepHandlerStep step;
|
||||
private TaskletStep step;
|
||||
|
||||
private JobExecution jobExecution;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
new MapStepExecutionDao(), new MapExecutionContextDao());
|
||||
|
||||
JobSupport jobConfiguration = new JobSupport();
|
||||
step = new StepHandlerStep("interruptedStep");
|
||||
step = new TaskletStep("interruptedStep");
|
||||
jobConfiguration.addStep(step);
|
||||
jobConfiguration.setBeanName("testJob");
|
||||
jobExecution = jobRepository.createJobExecution(jobConfiguration, new JobParameters());
|
||||
@@ -79,7 +79,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
// N.B, If we don't set the completion policy it might run forever
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
step.setStepHandler(new SimpleStepHandler<Object>(new ItemReader<Object>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<Object>(new ItemReader<Object>() {
|
||||
public Object read() throws Exception {
|
||||
// do something non-trivial (and not Thread.sleep())
|
||||
double foo = 1;
|
||||
@@ -116,7 +116,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
Thread processingThread = createThread(stepExecution);
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<Object>(new ItemReader<Object>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<Object>(new ItemReader<Object>() {
|
||||
public Object read() throws Exception {
|
||||
return null;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class StepExecutorInterruptionTests extends TestCase {
|
||||
|
||||
public void testLockNotReleasedIfChunkFails() throws Exception {
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<Object>(new ItemReader<Object>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<Object>(new ItemReader<Object>() {
|
||||
public Object read() throws Exception {
|
||||
throw new RuntimeException("Planned!");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerAdapter;
|
||||
import org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
*/
|
||||
public class StepHandlerAdapterTests {
|
||||
|
||||
private StepHandlerAdapter tasklet = new StepHandlerAdapter();
|
||||
private MethodInvokingTaskletAdapter tasklet = new MethodInvokingTaskletAdapter();
|
||||
private Object result = null;
|
||||
|
||||
public ExitStatus execute() {
|
||||
@@ -47,20 +47,20 @@ public class StepHandlerAdapterTests {
|
||||
@Test
|
||||
public void testExecuteWithExitStatus() throws Exception {
|
||||
tasklet.setTargetMethod("execute");
|
||||
assertEquals(ExitStatus.NOOP, tasklet.handle(null,null));
|
||||
assertEquals(ExitStatus.NOOP, tasklet.execute(null,null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapResultWithNull() throws Exception {
|
||||
tasklet.setTargetMethod("process");
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.handle(null,null));
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.execute(null,null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapResultWithNonNull() throws Exception {
|
||||
tasklet.setTargetMethod("process");
|
||||
this.result = "foo";
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.handle(null,null));
|
||||
assertEquals(ExitStatus.FINISHED, tasklet.execute(null,null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,19 +16,19 @@ import org.springframework.batch.core.JobInterruptedException;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.tasklet.SystemCommandException;
|
||||
import org.springframework.batch.core.step.tasklet.SystemCommandStepHandler;
|
||||
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.util.Assert;
|
||||
|
||||
/**
|
||||
* Tests for {@link SystemCommandStepHandler}.
|
||||
* Tests for {@link SystemCommandTasklet}.
|
||||
*/
|
||||
public class SystemCommandStepHandlerIntegrationTests {
|
||||
public class SystemCommandTaskletIntegrationTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SystemCommandStepHandlerIntegrationTests.class);
|
||||
private static final Log log = LogFactory.getLog(SystemCommandTaskletIntegrationTests.class);
|
||||
|
||||
private SystemCommandStepHandler tasklet = new SystemCommandStepHandler();
|
||||
private SystemCommandTasklet tasklet = new SystemCommandTasklet();
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("systemCommandStep", new JobExecution(new JobInstance(
|
||||
1L, new JobParameters(), "systemCommandJob")));
|
||||
@@ -56,7 +56,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
tasklet.afterPropertiesSet();
|
||||
|
||||
log.info("Executing command: " + command);
|
||||
ExitStatus exitStatus = tasklet.handle(null,null);
|
||||
ExitStatus exitStatus = tasklet.execute(null,null);
|
||||
|
||||
assertEquals(ExitStatus.FINISHED, exitStatus);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
tasklet.afterPropertiesSet();
|
||||
|
||||
log.info("Executing command: " + command);
|
||||
ExitStatus exitStatus = tasklet.handle(null,null);
|
||||
ExitStatus exitStatus = tasklet.execute(null,null);
|
||||
|
||||
assertEquals(ExitStatus.FAILED, exitStatus);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
|
||||
log.info("Executing command: " + command);
|
||||
try {
|
||||
tasklet.handle(null,null);
|
||||
tasklet.execute(null,null);
|
||||
fail();
|
||||
}
|
||||
catch (SystemCommandException e) {
|
||||
@@ -108,7 +108,7 @@ public class SystemCommandStepHandlerIntegrationTests {
|
||||
|
||||
stepExecution.setTerminateOnly();
|
||||
try {
|
||||
tasklet.handle(null,null);
|
||||
tasklet.execute(null,null);
|
||||
fail();
|
||||
}
|
||||
catch (JobInterruptedException e) {
|
||||
@@ -47,7 +47,7 @@ import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
|
||||
import org.springframework.batch.core.repository.support.SimpleJobRepository;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.batch.core.step.StepInterruptionPolicy;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
@@ -64,7 +64,7 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
|
||||
public class StepHandlerStepTests {
|
||||
public class TasketStepTests {
|
||||
|
||||
List<String> processed = new ArrayList<String>();
|
||||
|
||||
@@ -76,7 +76,7 @@ public class StepHandlerStepTests {
|
||||
}
|
||||
};
|
||||
|
||||
private StepHandlerStep step;
|
||||
private TaskletStep step;
|
||||
|
||||
private Job job;
|
||||
|
||||
@@ -94,12 +94,12 @@ public class StepHandlerStepTests {
|
||||
return new ListItemReader<String>(Arrays.asList(args));
|
||||
}
|
||||
|
||||
private StepHandlerStep getStep(String[] strings) throws Exception {
|
||||
StepHandlerStep step = new StepHandlerStep("stepName");
|
||||
private TaskletStep getStep(String[] strings) throws Exception {
|
||||
TaskletStep step = new TaskletStep("stepName");
|
||||
// Only process one item:
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
|
||||
step.setStepHandler(new SimpleStepHandler<String>(getReader(strings), itemWriter, template));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(getReader(strings), itemWriter, template));
|
||||
step.setJobRepository(new JobRepositorySupport());
|
||||
step.setTransactionManager(transactionManager);
|
||||
return step;
|
||||
@@ -210,7 +210,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@@ -235,7 +235,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@@ -260,7 +260,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.registerStepExecutionListener(new StepExecutionListenerSupport() {
|
||||
public ExitStatus onErrorInStep(StepExecution stepExecution, Throwable e) {
|
||||
return ExitStatus.FAILED.addExitDescription("FOO");
|
||||
@@ -287,7 +287,7 @@ public class StepHandlerStepTests {
|
||||
@Test
|
||||
public void testNonRestartedJob() throws Exception {
|
||||
MockRestartableItemReader tasklet = new MockRestartableItemReader();
|
||||
step.setStepHandler(new SimpleStepHandler<String>(tasklet, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(tasklet, itemWriter));
|
||||
step.registerStream(tasklet);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -348,7 +348,7 @@ public class StepHandlerStepTests {
|
||||
@Test
|
||||
public void testNoSaveExecutionAttributesRestartableJob() {
|
||||
MockRestartableItemReader tasklet = new MockRestartableItemReader();
|
||||
step.setStepHandler(new SimpleStepHandler<String>(tasklet, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(tasklet, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@@ -369,7 +369,7 @@ public class StepHandlerStepTests {
|
||||
*/
|
||||
@Test
|
||||
public void testRestartJobOnNonRestartableTasklet() throws Exception {
|
||||
step.setStepHandler(new SimpleStepHandler<String>(new ItemReader<String>() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(new ItemReader<String>() {
|
||||
public String read() throws Exception {
|
||||
return "foo";
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public class StepHandlerStepTests {
|
||||
executionContext.putString("foo", "bar");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(reader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.registerStream(reader);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
@@ -491,7 +491,7 @@ public class StepHandlerStepTests {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
step.setStepHandler(new SimpleStepHandler<String>(new MockRestartableItemReader() {
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(new MockRestartableItemReader() {
|
||||
public String read() throws Exception {
|
||||
throw new RuntimeException("FOO");
|
||||
}
|
||||
@@ -519,7 +519,7 @@ public class StepHandlerStepTests {
|
||||
executionContext.putString("foo", "bar");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(reader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.setStreams(new ItemStream[] { reader });
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
@@ -554,7 +554,7 @@ public class StepHandlerStepTests {
|
||||
|
||||
};
|
||||
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -582,7 +582,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("Foo");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -610,7 +610,7 @@ public class StepHandlerStepTests {
|
||||
throw new Error("Foo");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -638,7 +638,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("Foo");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.setTransactionManager(new ResourcelessTransactionManager() {
|
||||
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
|
||||
// Simulate failure on rollback when stream resets
|
||||
@@ -735,7 +735,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("Bar");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(itemReader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.registerStream(itemReader);
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
@@ -773,7 +773,7 @@ public class StepHandlerStepTests {
|
||||
throw new RuntimeException("CRASH!");
|
||||
}
|
||||
};
|
||||
step.setStepHandler(new SimpleStepHandler<String>(reader, itemWriter));
|
||||
step.setTasklet(new SimpleChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.registerStream(reader);
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.batch.integration.job;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
@@ -24,13 +24,13 @@ import org.springframework.core.AttributeAccessor;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class TestStepHandler implements StepHandler {
|
||||
public class TestTasklet implements Tasklet {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
<property name="steps" ref="step" />
|
||||
</bean>
|
||||
|
||||
<bean id="step" parent="handlerStep">
|
||||
<property name="stepHandler">
|
||||
<bean class="org.springframework.batch.integration.job.TestStepHandler" />
|
||||
<bean id="step" parent="taskletStep">
|
||||
<property name="tasklet">
|
||||
<bean class="org.springframework.batch.integration.job.TestTasklet" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
|
||||
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
|
||||
|
||||
<bean id="jobLauncher"
|
||||
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
@@ -27,8 +27,7 @@
|
||||
<property name="restartable" value="true" />
|
||||
</bean>
|
||||
<bean id="taskletStep"
|
||||
class="org.springframework.batch.core.step.tasklet.StepHandlerStep"
|
||||
abstract="true">
|
||||
class="org.springframework.batch.core.step.tasklet.TaskletStep" abstract="true">
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
<property name="allowStartIfComplete" value="true" />
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
@@ -13,19 +13,19 @@ import org.springframework.core.AttributeAccessor;
|
||||
/**
|
||||
* Dummy tasklet that retrieves message from the job execution context.
|
||||
*/
|
||||
public class DummyMessageReceivingStepHandler extends StepExecutionListenerSupport implements StepHandler {
|
||||
public class DummyMessageReceivingTasklet extends StepExecutionListenerSupport implements Tasklet {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DummyMessageReceivingStepHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(DummyMessageReceivingTasklet.class);
|
||||
|
||||
private String receivedMessage = null;
|
||||
|
||||
public void beforeStep(StepExecution stepExecution) {
|
||||
ExecutionContext ctx = stepExecution.getJobExecution().getExecutionContext();
|
||||
receivedMessage = ctx.getString(DummyMessageSendingStepHandler.MESSAGE_KEY);
|
||||
receivedMessage = ctx.getString(DummyMessageSendingTasklet.MESSAGE_KEY);
|
||||
logger.info("Got message from context: " + receivedMessage);
|
||||
}
|
||||
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.derby.impl.sql.compile.GetCurrentConnectionNode;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
@@ -13,11 +14,11 @@ import org.springframework.core.AttributeAccessor;
|
||||
/**
|
||||
* Dummy tasklet that stores a message in the job execution context.
|
||||
*/
|
||||
public class DummyMessageSendingStepHandler extends StepExecutionListenerSupport implements StepHandler {
|
||||
public class DummyMessageSendingTasklet extends StepExecutionListenerSupport implements Tasklet {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DummyMessageSendingStepHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(DummyMessageSendingTasklet.class);
|
||||
|
||||
public static final String MESSAGE_KEY = "DummyMessageSendingStepHandler.MESSAGE";
|
||||
public static final String MESSAGE_KEY = DummyMessageSendingTasklet.class.getSimpleName()+".MESSAGE";
|
||||
|
||||
private String message = "Hello!";
|
||||
|
||||
@@ -28,7 +29,7 @@ public class DummyMessageSendingStepHandler extends StepExecutionListenerSupport
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.batch.sample.tasklet;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.UnexpectedJobExecutionException;
|
||||
import org.springframework.batch.core.step.tasklet.StepHandler;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
@@ -15,11 +15,11 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class FileDeletingStepHandler implements StepHandler, InitializingBean {
|
||||
public class FileDeletingTasklet implements Tasklet, InitializingBean {
|
||||
|
||||
private Resource[] resources;
|
||||
|
||||
public ExitStatus handle(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
public ExitStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
for (Resource resource : resources) {
|
||||
boolean deleted = resource.getFile().delete();
|
||||
if (!deleted) {
|
||||
@@ -12,21 +12,21 @@
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="step1" parent="taskletStep">
|
||||
<property name="stepHandler" ref="sender" />
|
||||
<property name="tasklet" ref="sender" />
|
||||
</bean>
|
||||
<bean id="step2" parent="taskletStep">
|
||||
<property name="stepHandler" ref="receiver" />
|
||||
<property name="tasklet" ref="receiver" />
|
||||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="sender"
|
||||
class="org.springframework.batch.sample.tasklet.DummyMessageSendingStepHandler">
|
||||
class="org.springframework.batch.sample.tasklet.DummyMessageSendingTasklet">
|
||||
<property name="message" value="Hey!" />
|
||||
</bean>
|
||||
|
||||
<bean id="receiver"
|
||||
class="org.springframework.batch.sample.tasklet.DummyMessageReceivingStepHandler" />
|
||||
class="org.springframework.batch.sample.tasklet.DummyMessageReceivingTasklet" />
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="deleteFilesInDir" parent="taskletStep">
|
||||
<property name="stepHandler">
|
||||
<bean class="org.springframework.batch.sample.tasklet.FileDeletingStepHandler">
|
||||
<property name="tasklet">
|
||||
<bean class="org.springframework.batch.sample.tasklet.FileDeletingTasklet">
|
||||
<property name="resources" value="file:target/test-outputs/test-dir/*" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="executeSystemCommand" parent="taskletStep">
|
||||
<property name="stepHandler">
|
||||
<bean class="org.springframework.batch.core.step.tasklet.SystemCommandStepHandler">
|
||||
<property name="tasklet">
|
||||
<bean class="org.springframework.batch.core.step.tasklet.SystemCommandTasklet">
|
||||
<property name="command" value="java -version" />
|
||||
<!-- 5 second timeout for the command to complete -->
|
||||
<property name="timeout" value="5000" />
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<property name="restartable" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="taskletStep" class="org.springframework.batch.core.step.tasklet.StepHandlerStep" abstract="true">
|
||||
<bean id="taskletStep" class="org.springframework.batch.core.step.tasklet.TaskletStep" abstract="true">
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
<property name="allowStartIfComplete" value="true" />
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.springframework.batch.sample;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.sample.tasklet.DummyMessageReceivingStepHandler;
|
||||
import org.springframework.batch.sample.tasklet.DummyMessageSendingStepHandler;
|
||||
import org.springframework.batch.sample.tasklet.DummyMessageReceivingTasklet;
|
||||
import org.springframework.batch.sample.tasklet.DummyMessageSendingTasklet;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -14,10 +14,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class JobExecutionContextSampleFunctionalTests extends AbstractValidatingBatchLauncherTests {
|
||||
|
||||
@Autowired
|
||||
private DummyMessageSendingStepHandler sender;
|
||||
private DummyMessageSendingTasklet sender;
|
||||
|
||||
@Autowired
|
||||
private DummyMessageReceivingStepHandler receiver;
|
||||
private DummyMessageReceivingTasklet receiver;
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
assertEquals(sender.getMessage(), receiver.getReceivedMessage());
|
||||
|
||||
Reference in New Issue
Block a user