Class ParallelJob

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

public class ParallelJob extends SimultaneousStructural implements OptionallyTransient
Author:
Rob Gordon
See Also:

Description

A job which executes it's child jobs in parallel.

Once the child jobs are submitted, Oddjob's thread of execution continues on out of this job. The state is set to ACTIVE and will continue to change depending on the state of the child Jobs. The join property can be used to hold the thread of execution until the submitted jobs have finished executing - but it's use is discouraged. See the property documentation below for more information. The state of job, including its modification by the stateOperator property is identical to SequentialJob and is well documented there. Likewise with the transient property.

Example

Two jobs running in parallel. Note that the order of execution of the two child jobs is not predictable.
<oddjob>

    <job>

        <parallel>

            <jobs>

                <echo>This runs in parallel</echo>

                <echo>With this which could be displayed first!</echo>

            </jobs>

        </parallel>

    </job>

</oddjob>
Two services started in parallel. This might be quite useful if the services took a long time to start - maybe because they loaded a lot of data into a cache for instance.
<oddjob>

    <job>

        <cascade cascadeOn="COMPLETE">

            <jobs>

                <parallel>

                    <jobs>

                        <bean class="org.oddjob.jobs.structural.ServiceManagerTest$Lights" id="lights"/>

                        <bean class="org.oddjob.jobs.structural.ServiceManagerTest$MachineThatGoes" goes="ping" id="machine"/>

                    </jobs>

                </parallel>

                <echo>The lights are ${lights.are} and the machine goes ${machine.goes}.</echo>

            </jobs>

        </cascade>

    </job>

</oddjob>
The CascadeJob will execute the final job only once both services have started, and it will continue be in a STARTED after execution has completed.

Adding a SERVICES stateOperator property will mean that parallel is COMPLETE once the services have started and so the whole cascade shows as complete.

<oddjob>

    <job>

        <cascade>

            <jobs>

                <parallel stateOperator="SERVICES">

                    <jobs>

                        <bean class="org.oddjob.jobs.structural.ServiceManagerTest$Lights" id="lights"/>

                        <bean class="org.oddjob.jobs.structural.ServiceManagerTest$MachineThatGoes" goes="ping" id="machine"/>

                    </jobs>

                </parallel>

                <echo>The lights are ${lights.are} and the machine goes ${machine.goes}.</echo>

            </jobs>

        </cascade>

    </job>

</oddjob>
Examples elsewhere.
  • Constructor Details

    • ParallelJob

      public ParallelJob()
  • Method Details

    • setStateOperator

      public void setStateOperator(StateOperator stateOperator)
      Parameters:
      stateOperator - The state operator to be applied to children's states to derive our state.
      Reference Property:
      stateOperator

      Description

      Set the way the children's state is evaluated and reflected by the parent. Values can be WORST, ACTIVE, or SERVICES.
      Required:
      No, default is ACTIVE.
    • getStateOperator

      public StateOperator getStateOperator()
      Getter for State Operator.
      Returns:
    • 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<Object>
      Returns:
      A State Operator. Must not be null.
    • isJoin

      public boolean isJoin()
      Description copied from class: SimultaneousStructural
      Should execution wait for all jobs to be executed before returning to calling code.

      This property is intended to be overridden by sub classes that wish to give that choice to users.

      Overrides:
      isJoin in class SimultaneousStructural
      Returns:
      true for execution to wait for children. False for completion to be asynchronous.
    • setJoin

      public void setJoin(boolean join)
    • isTransient

      public boolean isTransient()
      Description copied from interface: OptionallyTransient
      Is the component transient.
      Specified by:
      isTransient in interface OptionallyTransient
      Returns:
      true if transient, false otherwise.
    • setTransient

      public void setTransient(boolean _transient)