org.springframework.batch.core.jsr.partition

## Class JsrPartitionHandler

- java.lang.Object
- - org.springframework.batch.core.jsr.partition.JsrPartitionHandler

- All Implemented Interfaces:
    PartitionHandler, org.springframework.beans.factory.InitializingBean

      public class JsrPartitionHandler
      extends java.lang.Object
      implements PartitionHandler, org.springframework.beans.factory.InitializingBean

  Executes a step instance per thread using a `ThreadPoolTaskExecutor` in accordance with JSR-352. The results from each step is aggregated into a cumulative result.
  Since:
    3.0
  Author:
    Michael Minella, Mahmoud Ben Hassine

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `JsrPartitionHandler.PartitionPlanState` Since a `PartitionPlan` could provide dynamic data (different results from run to run), the batch runtime needs to save off the results for restarts.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsrPartitionHandler()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()`
    `protected java.util.concurrent.FutureTask<StepExecution>` | `createTask(Step step, StepExecution stepExecution)` Creates the task executing the given step in the context of the given execution.
    `java.util.Collection<java.lang.String>` | `getPartitionStepNames()`
    `Step` | `getStep()`
    `java.util.Collection<StepExecution>` | `handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution)` Main entry point for `PartitionHandler` interface.
    `void` | `setAllowStartIfComplete(boolean allowStartIfComplete)`
    `void` | `setJobRepository(JobRepository jobRepository)`
    `void` | `setPartitionAnalyzer(javax.batch.api.partition.PartitionAnalyzer analyzer)`
    `void` | `setPartitionDataQueue(java.util.Queue<java.io.Serializable> queue)`
    `void` | `setPartitionLock(java.util.concurrent.locks.ReentrantLock lock)`
    `void` | `setPartitionMapper(javax.batch.api.partition.PartitionMapper mapper)`
    `void` | `setPartitions(int partitions)`
    `void` | `setPollingInterval(int pollingInterval)`
    `void` | `setPropertyContext(BatchPropertyContext context)`
    `void` | `setStep(Step step)`
    `void` | `setThreads(int threads)`

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

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

- - ### Constructor Detail

    - #### JsrPartitionHandler

          public JsrPartitionHandler()

  - ### Method Detail

    - #### getStep

          public Step getStep()

      Returns:
        the step that will be executed by each partition

    - #### getPartitionStepNames

          public java.util.Collection<java.lang.String> getPartitionStepNames()

      Returns:
        the names of each partitioned step

    - #### setAllowStartIfComplete

          public void setAllowStartIfComplete(boolean allowStartIfComplete)

      Parameters:
        `allowStartIfComplete` - flag stating if the step should restart if it was complete in a previous run

    - #### setPartitionDataQueue

          public void setPartitionDataQueue(java.util.Queue<java.io.Serializable> queue)

      Parameters:
        `queue` - `Queue` to receive the output of the `PartitionCollector`

    - #### setPartitionLock

          public void setPartitionLock(java.util.concurrent.locks.ReentrantLock lock)

    - #### setPropertyContext

          public void setPropertyContext(BatchPropertyContext context)

      Parameters:
        `context` - `BatchPropertyContext` to resolve partition level step properties

    - #### setPartitionMapper

          public void setPartitionMapper(javax.batch.api.partition.PartitionMapper mapper)

      Parameters:
        `mapper` - `PartitionMapper` used to configure partitioning

    - #### setStep

          public void setStep(Step step)

      Parameters:
        `step` - the step to be executed as a partitioned step

    - #### setPartitionAnalyzer

          public void setPartitionAnalyzer(javax.batch.api.partition.PartitionAnalyzer analyzer)

      Parameters:
        `analyzer` - `PartitionAnalyzer`

    - #### setThreads

          public void setThreads(int threads)

      Parameters:
        `threads` - the number of threads to execute the partitions to be run within. The default is the number of partitions.

    - #### setPartitions

          public void setPartitions(int partitions)

      Parameters:
        `partitions` - the number of partitions to be executed

    - #### setJobRepository

          public void setJobRepository(JobRepository jobRepository)

      Parameters:
        `jobRepository` - `JobRepository`

    - #### setPollingInterval

          public void setPollingInterval(int pollingInterval)

      Parameters:
        `pollingInterval` - the duration of partitions completion polling interval (in milliseconds). The default value is 500ms.

    - #### handle

          public java.util.Collection<StepExecution> handle(StepExecutionSplitter stepSplitter,
                                                            StepExecution stepExecution)
                                                     throws java.lang.Exception

      Description copied from interface: `PartitionHandler`
      Main entry point for `PartitionHandler` interface. The splitter creates all the executions that need to be farmed out, along with their input parameters (in the form of their `ExecutionContext`). The master step execution is used to identify the partition and group together the results logically.
      Specified by:
        `handle` in interface `PartitionHandler`
      Parameters:
        `stepSplitter` - a strategy for generating a collection of `StepExecution` instances
        `stepExecution` - the master step execution for the whole partition
      Returns:
        a collection of completed `StepExecution` instances
      Throws:
        `java.lang.Exception` - if anything goes wrong. This allows implementations to be liberal and rely on the caller to translate an exception into a step failure as necessary.

    - #### createTask

          protected java.util.concurrent.FutureTask<StepExecution> createTask(Step step,
                                                                              StepExecution stepExecution)

      Creates the task executing the given step in the context of the given execution.
      Parameters:
        `step` - the step to execute
        `stepExecution` - the given execution
      Returns:
        the task executing the given step

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`