org.springframework.batch.repeat.policy

## Class SimpleCompletionPolicy

- java.lang.Object
- - org.springframework.batch.repeat.policy.CompletionPolicySupport
  - - org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy
    - - org.springframework.batch.repeat.policy.SimpleCompletionPolicy

- All Implemented Interfaces:
    CompletionPolicy

      public class SimpleCompletionPolicy
      extends DefaultResultCompletionPolicy

  Policy for terminating a batch after a fixed number of operations. Internal state is maintained and a counter incremented, so successful use of this policy requires that isComplete() is only called once per batch item. Using the standard `RepeatTemplate` should ensure this contract is kept, but it needs to be carefully monitored.
  Author:
    Dave Syer

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `SimpleCompletionPolicy.SimpleTerminationContext`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_CHUNK_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleCompletionPolicy()`
    `SimpleCompletionPolicy(int chunkSize)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getChunkSize()`
    `boolean` | `isComplete(RepeatContext context)` Terminate if the chunk size has been reached.
    `boolean` | `isComplete(RepeatContext context, RepeatStatus result)` Terminate if the chunk size has been reached, or the result is null.
    `void` | `setChunkSize(int chunkSize)`
    `RepeatContext` | `start(RepeatContext context)` Reset the counter.
    `java.lang.String` | `toString()`
    `void` | `update(RepeatContext context)` Increment the counter in the context.

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

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

- - ### Field Detail

    - #### DEFAULT_CHUNK_SIZE

          public static final int DEFAULT_CHUNK_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SimpleCompletionPolicy

          public SimpleCompletionPolicy()

    - #### SimpleCompletionPolicy

          public SimpleCompletionPolicy(int chunkSize)

  - ### Method Detail

    - #### setChunkSize

          public void setChunkSize(int chunkSize)

    - #### getChunkSize

          public int getChunkSize()

    - #### start

          public RepeatContext start(RepeatContext context)

      Reset the counter.
      Specified by:
        `start` in interface `CompletionPolicy`
      Overrides:
        `start` in class `CompletionPolicySupport`
      Parameters:
        `context` - the current context if one is already in progress.
      Returns:
        a context object that can be used by the implementation to store internal state for a batch.
      See Also:
        `CompletionPolicy.start(RepeatContext)`

    - #### isComplete

          public boolean isComplete(RepeatContext context,
                                    RepeatStatus result)

      Terminate if the chunk size has been reached, or the result is null.
      Specified by:
        `isComplete` in interface `CompletionPolicy`
      Overrides:
        `isComplete` in class `DefaultResultCompletionPolicy`
      Parameters:
        `context` - the current batch context.
        `result` - the result of the latest batch item processing.
      Returns:
        true if the batch should terminate.
      Throws:
        `java.lang.RuntimeException` - (normally terminating the batch) if the result is itself an exception.
      See Also:
        `CompletionPolicy.isComplete(RepeatContext, RepeatStatus)`

    - #### isComplete

          public boolean isComplete(RepeatContext context)

      Terminate if the chunk size has been reached.
      Specified by:
        `isComplete` in interface `CompletionPolicy`
      Overrides:
        `isComplete` in class `DefaultResultCompletionPolicy`
      Parameters:
        `context` - the current batch context.
      Returns:
        true if the batch should terminate.
      See Also:
        `CompletionPolicy.isComplete(RepeatContext)`

    - #### update

          public void update(RepeatContext context)

      Increment the counter in the context.
      Specified by:
        `update` in interface `CompletionPolicy`
      Overrides:
        `update` in class `CompletionPolicySupport`
      Parameters:
        `context` - the value returned by start.
      See Also:
        `CompletionPolicy.update(RepeatContext)`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`