Class RepeatJob

All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resettable, Stateful, Stoppable, Structural

public class RepeatJob extends StructuralJob<Runnable> implements Stoppable
Author:
Rob Gordon.
See Also:

Description

This job will repeatedly run its child job. The repeat can be either for:
  • Each value of a collection.
  • Or a given number times.
  • Or until the until property is true.

Without either a until or a times or values the job will loop indefinitely.

Example

Repeat a job 3 times.

<oddjob>

    <job>

        <repeat times="3" id="repeat">

            <job>

                <echo>Hello ${repeat.count}</echo>

            </job>

        </repeat>

    </job>

</oddjob>
Repeat a job 3 times with a sequence.

<oddjob>

    <job>

        <repeat id="each">

            <values>

                <sequence from="1" to="3"/>

            </values>

            <job>

                <echo>Hello ${each.current}</echo>

            </job>

        </repeat>

    </job>

</oddjob>
  • Constructor Details

    • RepeatJob

      public RepeatJob()
  • Method Details

    • getInitialStateOp

      protected StateOperator getInitialStateOp()
      Description copied from class: StructuralJob
      Subclasses must provide the StateOperator that will decide how to evaluate the children's state.
      Specified by:
      getInitialStateOp in class StructuralJob<Runnable>
      Returns:
      A State Operator. Must not be null.
    • setExecutorService

      @Inject public void setExecutorService(ExecutorService executorService)
      Parameters:
      executorService - The Executor Service.
      Reference Property:
      executorService

      Description

      The ExecutorService to use. This will be automatically set by Oddjob.
      Required:
      No.
    • getExecutorService

      public ExecutorService getExecutorService()
      Getter for executor service.
      Returns:
      The executor service or null if not set.
    • setJob

      public void setJob(Runnable child)
      Reference Property:
      job

      Description

      The job who's execution to schedule.
      Required:
      Yes.
    • execute

      protected void execute()
      Description copied from class: StructuralJob
      Execute this job.
      Specified by:
      execute in class StructuralJob<Runnable>
    • onStop

      protected void onStop() throws FailedToStopException
      Description copied from class: StructuralJob
      Allow sub classes to do something on stop.
      Overrides:
      onStop in class StructuralJob<Runnable>
      Throws:
      FailedToStopException
    • startChildStateReflector

      protected void startChildStateReflector()
      Description copied from class: StructuralJob
      Start the child state reflector. Sub classes override this if they need to start the child state reflector at a different time.
      Overrides:
      startChildStateReflector in class StructuralJob<Runnable>
    • onHardReset

      protected void onHardReset()
      Description copied from class: StructuralJob
      Allow sub classes to do something on HARD reset.
      Overrides:
      onHardReset in class StructuralJob<Runnable>
    • setValues

      public void setValues(Iterable<?> values)
    • getValues

      public Iterable<?> getValues()
    • isUntil

      public boolean isUntil()
    • setUntil

      public void setUntil(boolean until)
    • getTimes

      public int getTimes()
    • setTimes

      public void setTimes(int times)
    • getCount

      public int getCount()
    • getIndex

      public int getIndex()
      Returns:
      The index.
      Reference Property:
      index

      Description

      The same as count. Provided so configurations can be swapped between this and ForEachJob job.
    • getCurrent

      public Object getCurrent()