Class CountingCompletionPolicy

  • All Implemented Interfaces:
    CompletionPolicy

    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.
    Author:
    Dave Syer
    • Field Detail

      • COUNT

        public static final java.lang.String COUNT
        Session key for global counter.
    • Constructor Detail

      • CountingCompletionPolicy

        public CountingCompletionPolicy()
    • Method Detail

      • 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.
        Parameters:
        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.
        Parameters:
        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.
        Parameters:
        context - the current context, specific to the subclass.
        Returns:
        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.
        Parameters:
        context - the current context.
        Returns:
        the change in the value of the counter (default 0).