org.springframework.batch.core.step.item

## Class SimpleChunkProcessor<I,O>

- java.lang.Object
- - org.springframework.batch.core.step.item.SimpleChunkProcessor<I,O>

- All Implemented Interfaces:
    ChunkProcessor<I>, org.springframework.beans.factory.InitializingBean
  Direct Known Subclasses:
    FaultTolerantChunkProcessor

      public class SimpleChunkProcessor<I,O>
      extends java.lang.Object
      implements ChunkProcessor<I>, org.springframework.beans.factory.InitializingBean

  Simple implementation of the `ChunkProcessor` interface that handles basic item writing and processing. Any exceptions encountered will be rethrown.
  See Also:
    `ChunkOrientedTasklet`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleChunkProcessor(ItemProcessor<? super I,? extends O> itemProcessor, ItemWriter<? super O> itemWriter)`
    `SimpleChunkProcessor(ItemWriter<? super O> itemWriter)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Check mandatory properties.
    `protected void` | `doAfterWrite(java.util.List<O> items)` Call the listener's after write method.
    `protected void` | `doOnWriteError(java.lang.Exception e, java.util.List<O> items)` Call listener's writerError method.
    `protected O` | `doProcess(I item)`
    `protected void` | `doWrite(java.util.List<O> items)` Surrounds the actual write call with listener callbacks.
    `protected Chunk<O>` | `getAdjustedOutputs(Chunk<I> inputs, Chunk<O> outputs)` Extension point for subclasses that want to adjust the outputs based on additional saved data in the inputs.
    `protected int` | `getFilterCount(Chunk<I> inputs, Chunk<O> outputs)` Extension point for subclasses to calculate the filter count.
    `protected MulticasterBatchListener<I,O>` | `getListener()`
    `protected void` | `initializeUserData(Chunk<I> inputs)` Extension point for subclasses to allow them to memorise the contents of the inputs, in case they are needed for accounting purposes later.
    `protected boolean` | `isComplete(Chunk<I> inputs)` Extension point for subclasses that want to store additional data in the inputs.
    `void` | `process(StepContribution contribution, Chunk<I> inputs)`
    `void` | `registerListener(StepListener listener)` Register a listener for callbacks at the appropriate stages in a process.
    `void` | `setItemProcessor(ItemProcessor<? super I,? extends O> itemProcessor)`
    `void` | `setItemWriter(ItemWriter<? super O> itemWriter)`
    `void` | `setListeners(java.util.List<? extends StepListener> listeners)` Register some `StepListener`s with the handler.
    `protected Chunk<O>` | `transform(StepContribution contribution, Chunk<I> inputs)`
    `protected void` | `write(StepContribution contribution, Chunk<I> inputs, Chunk<O> outputs)` Simple implementation delegates to the `doWrite(List)` method and increments the write count in the contribution.
    `protected void` | `writeItems(java.util.List<O> items)`

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

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

- - ### Constructor Detail

    - #### SimpleChunkProcessor

          public SimpleChunkProcessor(@Nullable
                                      ItemProcessor<? super I,? extends O> itemProcessor,
                                      ItemWriter<? super O> itemWriter)

    - #### SimpleChunkProcessor

          public SimpleChunkProcessor(ItemWriter<? super O> itemWriter)

  - ### Method Detail

    - #### setItemProcessor

          public void setItemProcessor(ItemProcessor<? super I,? extends O> itemProcessor)

      Parameters:
        `itemProcessor` - the `ItemProcessor` to set

    - #### setItemWriter

          public void setItemWriter(ItemWriter<? super O> itemWriter)

      Parameters:
        `itemWriter` - the `ItemWriter` to set

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Check mandatory properties.
      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`
      See Also:
        `InitializingBean.afterPropertiesSet()`

    - #### setListeners

          public void setListeners(java.util.List<? extends StepListener> listeners)

      Register some `StepListener`s with the handler. Each will get the callbacks in the order specified at the correct stage.
      Parameters:
        `listeners` - list of `StepListener` instances.

    - #### registerListener

          public void registerListener(StepListener listener)

      Register a listener for callbacks at the appropriate stages in a process.
      Parameters:
        `listener` - a `StepListener`

    - #### getListener

          protected MulticasterBatchListener<I,O> getListener()

      Returns:
        the listener

    - #### doProcess

          protected final O doProcess(I item)
                               throws java.lang.Exception

      Parameters:
        `item` - the input item
      Returns:
        the result of the processing
      Throws:
        `java.lang.Exception` - thrown if error occurs.

    - #### doWrite

          protected final void doWrite(java.util.List<O> items)
                                throws java.lang.Exception

      Surrounds the actual write call with listener callbacks.
      Parameters:
        `items` - list of items to be written.
      Throws:
        `java.lang.Exception` - thrown if error occurs.

    - #### doAfterWrite

          protected final void doAfterWrite(java.util.List<O> items)

      Call the listener's after write method.
      Parameters:
        `items` - list of items that were just written.

    - #### doOnWriteError

          protected final void doOnWriteError(java.lang.Exception e,
                                              java.util.List<O> items)

      Call listener's writerError method.
      Parameters:
        `e` - exception that occurred.
        `items` - list of items that failed to be written.

    - #### writeItems

          protected void writeItems(java.util.List<O> items)
                             throws java.lang.Exception

      Parameters:
        `items` - list of items to be written.
      Throws:
        `java.lang.Exception` - thrown if error occurs.

    - #### process

          public final void process(StepContribution contribution,
                                    Chunk<I> inputs)
                             throws java.lang.Exception

      Specified by:
        `process` in interface `ChunkProcessor<I>`
      Throws:
        `java.lang.Exception`

    - #### initializeUserData

          protected void initializeUserData(Chunk<I> inputs)

      Extension point for subclasses to allow them to memorise the contents of the inputs, in case they are needed for accounting purposes later. The default implementation sets up some user data to remember the original size of the inputs. If this method is overridden then some or all of `isComplete(Chunk)`, `getFilterCount(Chunk, Chunk)` and `getAdjustedOutputs(Chunk, Chunk)` might also need to be, to ensure that the user data is handled consistently.
      Parameters:
        `inputs` - the inputs for the process

    - #### getFilterCount

          protected int getFilterCount(Chunk<I> inputs,
                                       Chunk<O> outputs)

      Extension point for subclasses to calculate the filter count. Defaults to the difference between input size and output size.
      Parameters:
        `inputs` - the inputs after transformation
        `outputs` - the outputs after transformation
      Returns:
        the difference in sizes
      See Also:
        `initializeUserData(Chunk)`

    - #### isComplete

          protected boolean isComplete(Chunk<I> inputs)

      Extension point for subclasses that want to store additional data in the inputs. Default just checks if inputs are empty.
      Parameters:
        `inputs` - the input chunk
      Returns:
        true if it is empty
      See Also:
        `initializeUserData(Chunk)`

    - #### getAdjustedOutputs

          protected Chunk<O> getAdjustedOutputs(Chunk<I> inputs,
                                                Chunk<O> outputs)

      Extension point for subclasses that want to adjust the outputs based on additional saved data in the inputs. Default implementation just returns the outputs unchanged.
      Parameters:
        `inputs` - the inputs for the transformation
        `outputs` - the result of the transformation
      Returns:
        the outputs unchanged
      See Also:
        `initializeUserData(Chunk)`

    - #### write

          protected void write(StepContribution contribution,
                               Chunk<I> inputs,
                               Chunk<O> outputs)
                        throws java.lang.Exception

      Simple implementation delegates to the `doWrite(List)` method and increments the write count in the contribution. Subclasses can handle more complicated scenarios, e.g.with fault tolerance. If output items are skipped they should be removed from the inputs as well.
      Parameters:
        `contribution` - the current step contribution
        `inputs` - the inputs that gave rise to the outputs
        `outputs` - the outputs to write
      Throws:
        `java.lang.Exception` - if there is a problem

    - #### transform

          protected Chunk<O> transform(StepContribution contribution,
                                       Chunk<I> inputs)
                                throws java.lang.Exception

      Throws:
        `java.lang.Exception`