Class Trigger

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

public class Trigger extends ScheduleBase
Author:
Rob Gordon.
See Also:

Description

A trigger runs its job when the job being triggered on enters the state specified.

Once the trigger's job runs, the trigger will reflect the state of the job. The trigger will continue to reflect its job's state until it is reset.

Subsequent state changes in the triggering job are ignored until the trigger is reset and re-run.

If the triggering job is destroyed, because it is deleted or on a remote server the trigger will enter an exception state.

Example

A simple trigger.
<oddjob id="this">

    <job>

        <sequential name="Trigger Example">

            <jobs>

                <scheduling:trigger name="Alert Trigger" on="${important}" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">

                    <job>

                        <echo name="Alert">Important job has completed!</echo>

                    </job>

                </scheduling:trigger>

                <folder name="A Folder of Jobs">

                    <jobs>

                        <echo id="important" name="Run Me">I'm important</echo>

                    </jobs>

                </folder>

            </jobs>

        </sequential>

    </job>

</oddjob>
A trigger that runs once two other jobs have completed.
<oddjob xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling" xmlns:state="http://rgordon.co.uk/oddjob/state">

    <job>

        <sequential name="Trigger on Two Things">

            <jobs>

                <scheduling:trigger id="trigger" on="${watch-both}">

                    <job>

                        <echo id="notify" name="Triggered Job">You ran two things!</echo>

                    </job>

                </scheduling:trigger>

                <state:and id="watch-both" name="Watch Two Jobs">

                    <jobs>

                        <state:mirror job="${thing1}" name="Mirror Job 1"/>

                        <state:mirror job="${thing2}" name="Mirror Job 2"/>

                    </jobs>

                </state:and>

                <folder name="A Folder of Jobs">

                    <jobs>

                        <echo id="thing1" name="Run me!">Thank you</echo>

                        <echo id="thing2" name="Run me!">Thank you</echo>

                    </jobs>

                </folder>

            </jobs>

        </sequential>

    </job>

</oddjob>
Cancelling a trigger.
<oddjob id="this" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">

    <job>

        <sequential name="Trigger Example">

            <jobs>

                <scheduling:trigger id="trigger" name="Alert Trigger" on="${our-job}" state="FAILURE" cancelWhen="FINISHED">

                    <job>

                        <echo name="Alert" id="triggered-job">That job shouldn't fail!</echo>

                    </job>

                </scheduling:trigger>

                <folder name="A Folder of Jobs">

                    <jobs>

                        <echo id="our-job" name="Run Me">I won't fail</echo>

                    </jobs>

                </folder>

            </jobs>

        </sequential>

    </job>

</oddjob>
Examples Elsewhere.
  • The scheduling example (examples/scheduling/dailyftp.xml) uses a trigger to send an email if one of the FTP transfers fails.
  • Constructor Details

    • Trigger

      public Trigger()
  • Method Details

    • setExecutorService

      @Inject public void setExecutorService(ExecutorService executor)
    • getStateOp

      protected StateOperator getStateOp()
      Description copied from class: ScheduleBase
      Sub classes provide the state operator that is used to calculate the subclasses completion state.
      Specified by:
      getStateOp in class ScheduleBase
      Returns:
      The operator. Must not be null.
    • begin

      protected void begin()
      Description copied from class: ScheduleBase
      Sub classes must override this to submit the first execution.
      Specified by:
      begin in class ScheduleBase
    • onStop

      protected void onStop()
      Description copied from class: ScheduleBase
      Subclasses can override to perform stopping operations.
      Overrides:
      onStop in class ScheduleBase
    • postStop

      protected void postStop()
      Description copied from class: ScheduleBase
      Subclasses can override to perform actions once children have stopped.
      Overrides:
      postStop in class ScheduleBase
    • setJob

      public void setJob(Runnable job)
      Reference Property:
      job

      Description

      The job to run when the trigger fires.
      Required:
      Yes.
    • getState

      public StateCondition getState()
    • setState

      public void setState(StateCondition state)
    • getCancelWhen

      public StateCondition getCancelWhen()
    • setCancelWhen

      public void setCancelWhen(StateCondition cancelWhen)
    • isNewOnly

      public boolean isNewOnly()
    • setNewOnly

      public void setNewOnly(boolean newEventOnly)
    • getOn

      public Stateful getOn()
    • setOn

      public void setOn(Stateful triggerOn)