Class CountingCompletionPolicy

All Implemented Interfaces:

public abstract class CountingCompletionPolicy extends DefaultResultCompletionPolicy
Abstract base class for policies that need to count the number of occurrences of some event (e.g. an exception type in the context), and terminate based on a limit for the counter. The value of the counter can be stored between batches in a nested context, so that the termination decision is based on the aggregate of a number of sibling batches.
Dave Syer
  • Field Details

    • COUNT

      public static final String COUNT
      Session key for global counter.
  • Constructor Details

    • CountingCompletionPolicy

      public CountingCompletionPolicy()
  • Method Details

    • setUseParent

      public void setUseParent(boolean useParent)
      Flag to indicate whether the count is at the level of the parent context, or just local to the context. If true then the count is aggregated among siblings in a nested batch.
      useParent - whether to use the parent context to cache the total count. Default value is false.
    • setMaxCount

      public void setMaxCount(int maxCount)
      Setter for maximum value of count before termination.
      maxCount - the maximum number of counts before termination. Default 0 so termination is immediate.
    • getCount

      protected abstract int getCount(RepeatContext context)
      Extension point for subclasses. Obtain the value of the count in the current context. Subclasses can count the number of attempts or violations and store the result in their context. This policy base class will take care of the termination contract and aggregating at the level of the session if required.
      context - the current context, specific to the subclass.
      the value of the counter in the context.
    • doUpdate

      protected int doUpdate(RepeatContext context)
      Extension point for subclasses. Inspect the context and update the state of a counter in whatever way is appropriate. This will be added to the session-level counter if setUseParent(boolean) is true.
      context - the current context.
      the change in the value of the counter (default 0).
    • isComplete

      public final boolean isComplete(RepeatContext context)
      Description copied from class: DefaultResultCompletionPolicy
      Always false.
      Specified by:
      isComplete in interface CompletionPolicy
      isComplete in class DefaultResultCompletionPolicy
      context - the current batch context.
      true if the batch should terminate.
      See Also:
    • start

      public RepeatContext start(RepeatContext parent)
      Description copied from class: CompletionPolicySupport
      Build a new RepeatContextSupport and return it.
      Specified by:
      start in interface CompletionPolicy
      start in class CompletionPolicySupport
      parent - the current context if one is already in progress.
      a context object that can be used by the implementation to store internal state for a batch.
      See Also:
    • update

      public final void update(RepeatContext context)
      Description copied from class: CompletionPolicySupport
      Increment the context so the counter is up to date. Do nothing else.
      Specified by:
      update in interface CompletionPolicy
      update in class CompletionPolicySupport
      context - the value returned by start.
      See Also: