org.springframework.batch.core.step.item
Class ItemOrientedStep

java.lang.Object
  extended by org.springframework.batch.core.step.AbstractStep
      extended by org.springframework.batch.core.step.item.ItemOrientedStep
All Implemented Interfaces:
Step, BeanNameAware, InitializingBean

public class ItemOrientedStep
extends AbstractStep

Simple implementation of executing the step as a set of chunks, each chunk surrounded by a transaction. The structure is therefore that of two nested loops, with transaction boundary around the whole inner loop. The outer loop is controlled by the step operations (setStepOperations(RepeatOperations)), and the inner loop by the chunk operations (setChunkOperations(RepeatOperations)). The inner loop should always be executed in a single thread, so the chunk operations should not do any concurrent execution. N.B. usually that means that the chunk operations should be a RepeatTemplate (which is the default).
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 step is complete. Those that want callbacks at the level of an individual tasks, can specify interceptors for the chunk operations.

Author:
Dave Syer, Lucas Ward, Ben Hale, Robert Kasanicky

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.batch.core.step.AbstractStep
AbstractStep.FatalException
 
Field Summary
 
Fields inherited from class org.springframework.batch.core.step.AbstractStep
JOB_INTERRUPTED
 
Constructor Summary
ItemOrientedStep(String name)
           
 
Method Summary
protected  void close(ExecutionContext ctx)
           
protected  ExitStatus doExecute(StepExecution stepExecution)
          Process the step and update its context so that progress can be monitored by the caller.
protected  void open(ExecutionContext ctx)
           
protected  ExitStatus processChunk(StepExecution execution, StepContribution contribution)
          Execute a bunch of identical business logic operations all within a transaction.
 void registerStream(ItemStream stream)
          Register a single ItemStream for callbacks to the stream interface.
 void setChunkOperations(RepeatOperations chunkOperations)
          The RepeatOperations to use for the inner loop of the batch processing.
 void setInterruptionPolicy(StepInterruptionPolicy interruptionPolicy)
          Setter for the StepInterruptionPolicy.
 void setItemHandler(ItemHandler itemHandler)
          Public setter for the ItemHandler.
 void setStepExecutionListeners(StepExecutionListener[] listeners)
          Register each of the objects as listeners.
 void setStepOperations(RepeatOperations stepOperations)
          The RepeatOperations to use for the outer loop of the batch processing.
 void setStreams(ItemStream[] streams)
          Register each of the streams for callbacks at the appropriate time in the step.
 void setSynchronizer(StepExecutionSynchronizer synchronizer)
          Mostly useful for testing, but could be used to remove dependence on backport concurrency utilities.
 void setTransactionManager(PlatformTransactionManager transactionManager)
          Public setter for the PlatformTransactionManager.
 
Methods inherited from class org.springframework.batch.core.step.AbstractStep
afterPropertiesSet, execute, getCompositeListener, getJobRepository, getName, getStartLimit, isAllowStartIfComplete, registerStepExecutionListener, setAllowStartIfComplete, setBeanName, setJobRepository, setName, setStartLimit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ItemOrientedStep

public ItemOrientedStep(String name)
Parameters:
name -
Method Detail

setTransactionManager

public void setTransactionManager(PlatformTransactionManager transactionManager)
Public setter for the PlatformTransactionManager.

Parameters:
transactionManager - the transaction manager to set

setItemHandler

public void setItemHandler(ItemHandler itemHandler)
Public setter for the ItemHandler.

Parameters:
itemHandler - the ItemHandler to set

setStepExecutionListeners

public void setStepExecutionListeners(StepExecutionListener[] listeners)
Register each of the objects as listeners. If the ItemReader or ItemWriter themselves implements this interface they will be registered automatically, but their injected dependencies will not be. This is a good way to get access to job parameters and execution context if the tasklet is parameterised.

Overrides:
setStepExecutionListeners in class AbstractStep
Parameters:
listeners - an array of listener objects of known types.

setStreams

public void setStreams(ItemStream[] streams)
Register each of the streams for callbacks at the appropriate time in the step. The ItemReader and ItemWriter are automatically registered, but it doesn't hurt to also register them here. Injected dependencies of the reader and writer are not automatically registered, so if you implement ItemWriter using delegation to another object which itself is a ItemStream, you need to register the delegate here.

Parameters:
streams - an array of ItemStream objects.

registerStream

public void registerStream(ItemStream stream)
Register a single ItemStream for callbacks to the stream interface.

Parameters:
stream -

setStepOperations

public void setStepOperations(RepeatOperations stepOperations)
The RepeatOperations to use for the outer loop of the batch processing. Should be set up by the caller through a factory. Defaults to a plain RepeatTemplate.

Parameters:
stepOperations - a RepeatOperations instance.

setChunkOperations

public void setChunkOperations(RepeatOperations chunkOperations)
The RepeatOperations to use for the inner loop of the batch processing. should be set up by the caller through a factory. defaults to a plain RepeatTemplate.

Parameters:
chunkOperations - a RepeatOperations instance.

setInterruptionPolicy

public void setInterruptionPolicy(StepInterruptionPolicy interruptionPolicy)
Setter for the StepInterruptionPolicy. The policy is used to check whether an external request has been made to interrupt the job execution.

Parameters:
interruptionPolicy - a StepInterruptionPolicy

setSynchronizer

public void setSynchronizer(StepExecutionSynchronizer synchronizer)
Mostly useful for testing, but could be used to remove dependence on backport concurrency utilities. Public setter for the StepExecutionSynchronizer.

Parameters:
synchronizer - the StepExecutionSynchronizer to set

doExecute

protected ExitStatus doExecute(StepExecution stepExecution)
                        throws Exception
Process the step and update its context so that progress can be monitored by the caller. The step is broken down into chunks, each one executing in a transaction. The step and its execution and execution context are all given an up to date BatchStatus, and the JobRepository is used to store the result. Various reporting information are also added to the current context (the RepeatContext governing the step execution, which would normally be available to the caller somehow through the step's ExecutionContext.

Specified by:
doExecute in class AbstractStep
Throws:
JobInterruptedException - if the step or a chunk is interrupted
RuntimeException - if there is an exception during a chunk execution
Exception

processChunk

protected ExitStatus processChunk(StepExecution execution,
                                  StepContribution contribution)
Execute a bunch of identical business logic operations all within a transaction. The transaction is programmatically started and stopped outside this method, so subclasses that override do not need to create a transaction.

Parameters:
execution - the current StepExecution which should be treated as read-only for the purposes of this method.
contribution - the current StepContribution which can accept changes to be aggregated later into the step execution.
Returns:
true if there is more data to process.

close

protected void close(ExecutionContext ctx)
              throws Exception
Specified by:
close in class AbstractStep
Throws:
Exception

open

protected void open(ExecutionContext ctx)
             throws Exception
Specified by:
open in class AbstractStep
Throws:
Exception


Copyright © 2008 SpringSource. All Rights Reserved.