org.springframework.batch.core.partition.support
Class TaskExecutorPartitionHandler

java.lang.Object
  extended by org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler
All Implemented Interfaces:
PartitionHandler, InitializingBean

public class TaskExecutorPartitionHandler
extends Object
implements PartitionHandler, InitializingBean

A PartitionHandler that uses a TaskExecutor to execute the partitioned Step locally in multiple threads. This can be an effective approach for scaling batch steps that are IO intensive, like directory and filesystem scanning and copying.

Since:
2.0
Author:
Dave Syer

Constructor Summary
TaskExecutorPartitionHandler()
           
 
Method Summary
 void afterPropertiesSet()
           
 Collection<StepExecution> handle(StepExecutionSplitter stepExecutionSplitter, StepExecution masterStepExecution)
          Main entry point for PartitionHandler interface.
 void setGridSize(int gridSize)
          Passed to the StepExecutionSplitter in the handle(StepExecutionSplitter, StepExecution) method, instructing it how many StepExecution instances are required, ideally.
 void setStep(Step step)
          Setter for the Step that will be used to execute the partitioned StepExecution.
 void setTaskExecutor(TaskExecutor taskExecutor)
          Setter for the TaskExecutor that is used to farm out step executions to multiple threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskExecutorPartitionHandler

public TaskExecutorPartitionHandler()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

setGridSize

public void setGridSize(int gridSize)
Passed to the StepExecutionSplitter in the handle(StepExecutionSplitter, StepExecution) method, instructing it how many StepExecution instances are required, ideally. The StepExecutionSplitter is allowed to ignore the grid size in the case of a restart, since the input data partitions must be preserved.

Parameters:
gridSize - the number of step executions that will be created

setTaskExecutor

public void setTaskExecutor(TaskExecutor taskExecutor)
Setter for the TaskExecutor that is used to farm out step executions to multiple threads.

Parameters:
taskExecutor - a TaskExecutor

setStep

public void setStep(Step step)
Setter for the Step that will be used to execute the partitioned StepExecution. This is a regular Spring Batch step, with all the business logic required to complete an execution based on the input parameters in its StepExecution context.

Parameters:
step - the Step instance to use to execute business logic

handle

public Collection<StepExecution> handle(StepExecutionSplitter stepExecutionSplitter,
                                        StepExecution masterStepExecution)
                                 throws 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:
stepExecutionSplitter - a strategy for generating a collection of StepExecution instances
masterStepExecution - the master step execution for the whole partition
Returns:
a collection of completed StepExecution instances
Throws:
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.
See Also:
PartitionHandler.handle(StepExecutionSplitter, StepExecution)


Copyright © 2009 SpringSource. All Rights Reserved.