Package org.springframework.batch.core.step.tasklet

# Class TaskletStep

java.lang.Object
org.springframework.batch.core.step.AbstractStep
org.springframework.batch.core.step.tasklet.TaskletStep

All Implemented Interfaces:
  `Step`, `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanNameAware`, `org.springframework.beans.factory.InitializingBean`

public class TaskletStep extends AbstractStep
Simple implementation of executing the step as a call to a `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 ( `setStepOperations(RepeatOperations)`).
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, Michael Minella, Will Schipp, Mahmoud Ben Hassine

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `TASKLET_TYPE_KEY`

  ### Fields inherited from interface org.springframework.batch.core.Step

  `STEP_TYPE_KEY`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TaskletStep()`
  Default constructor.
  `TaskletStep(String name)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `afterPropertiesSet()`
  `protected void`
  `close(ExecutionContext ctx)`
  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.
  `protected Semaphore`
  `createSemaphore()`
  Extension point mainly for test purposes so that the behaviour of the lock can be manipulated to simulate various pathologies.
  `protected void`
  `doExecute(StepExecution stepExecution)`
  Process the step and update its context so that progress can be monitored by the caller.
  `Tasklet`
  `getTasklet()`
  retrieve the tasklet - helper method for JobOperator
  `protected void`
  `open(ExecutionContext ctx)`
  Extension point for subclasses to provide callbacks to their collaborators at the beginning of a step, to open or acquire resources.
  `void`
  `registerChunkListener(ChunkListener listener)`
  Register a chunk listener for callbacks at the appropriate stages in a step execution.
  `void`
  `registerStream(ItemStream stream)`
  Register a single `ItemStream` for callbacks to the stream interface.
  `void`
  `setChunkListeners(ChunkListener[] listeners)`
  Register each of the objects as listeners.
  `void`
  `setInterruptionPolicy(StepInterruptionPolicy interruptionPolicy)`
  Setter for the `StepInterruptionPolicy`.
  `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`
  `setTasklet(Tasklet tasklet)`
  Public setter for the `Tasklet`.
  `void`
  `setTransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute transactionAttribute)`
  Public setter for the `TransactionAttribute`.
  `void`
  `setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)`
  Public setter for the `PlatformTransactionManager`.

  ### Methods inherited from class org.springframework.batch.core.step.AbstractStep

  `doExecutionRegistration, doExecutionRelease, execute, getCompositeListener, getJobRepository, getName, getStartLimit, isAllowStartIfComplete, registerStepExecutionListener, setAllowStartIfComplete, setBeanName, setJobRepository, setName, setStartLimit, setStepExecutionListeners, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### TASKLET_TYPE_KEY

    public static final String TASKLET_TYPE_KEY
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### TaskletStep

    public TaskletStep()
    Default constructor.

  - ### TaskletStep

    public TaskletStep(String name)
    Parameters:
      `name` - the name for the `TaskletStep`

- ## Method Details

  - ### afterPropertiesSet

    public void afterPropertiesSet() throws Exception
    Specified by:
      `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
    Overrides:
      `afterPropertiesSet` in class `AbstractStep`
    Throws:
      `Exception`

  - ### setTransactionManager

    public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
    Public setter for the `PlatformTransactionManager`.
    Parameters:
      `transactionManager` - the transaction manager to set

  - ### setTransactionAttribute

    public void setTransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute transactionAttribute)
    Public setter for the `TransactionAttribute`.
    Parameters:
      `transactionAttribute` - the `TransactionAttribute` to set

  - ### setTasklet

    public void setTasklet(Tasklet tasklet)
    Public setter for the `Tasklet`.
    Parameters:
      `tasklet` - the `Tasklet` to set

  - ### registerChunkListener

    public void registerChunkListener(ChunkListener listener)
    Register a chunk listener for callbacks at the appropriate stages in a step execution.
    Parameters:
      `listener` - a `ChunkListener`

  - ### setChunkListeners

    public void setChunkListeners(ChunkListener[] listeners)
    Register each of the objects as listeners.
    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` - instance of `ItemStream`

  - ### 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.

  - ### 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`

  - ### doExecute

    protected void 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 governing the step execution, which would normally be available to the caller through the step's `ExecutionContext`.
    Specified by:
      `doExecute` in class `AbstractStep`
    Parameters:
      `stepExecution` - the current step context
    Throws:
      `JobInterruptedException` - if the step or a chunk is interrupted
      `RuntimeException` - if there is an exception during a chunk execution
      `Exception` - checked exception thrown by implementation

  - ### createSemaphore

    protected Semaphore createSemaphore()
    Extension point mainly for test purposes so that the behaviour of the lock can be manipulated to simulate various pathologies.
    Returns:
      a semaphore for locking access to the JobRepository

  - ### close

    protected void close(ExecutionContext ctx) throws Exception
    Description copied from class: `AbstractStep`
    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.
    Overrides:
      `close` in class `AbstractStep`
    Parameters:
      `ctx` - the `ExecutionContext` to use
    Throws:
      `Exception` - checked exception thrown by implementation

  - ### open

    protected void open(ExecutionContext ctx) throws Exception
    Description copied from class: `AbstractStep`
    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.
    Overrides:
      `open` in class `AbstractStep`
    Parameters:
      `ctx` - the `ExecutionContext` to use
    Throws:
      `Exception` - checked exception thrown by implementation

  - ### getTasklet

    public Tasklet getTasklet()
    retrieve the tasklet - helper method for JobOperator
    Returns:
      the `Tasklet` instance being executed within this step