[Index]

state:if


This job implements an if/then/else logic based on job state. This job can contain any number of child jobs. The first provides the state for the condition. If this state matches the given state, the second job is executed. If it doesn't, then the third job is executed, (if it exists).

The completion state is that of the then or else job. If either don't exist then the Job is flagged as complete.

If any more than three jobs are provided the extra jobs are ignored.

If the first job enters an ACTIVE state then condition will not be evaluated until the first job leaves the ACTIVE state. This job will not block while this is happening. The thread of execution will pass to its next sibling and this job will also enter the ACTIVE state.


Property Summary

executorService Used for an asynchronous evaluation of the if.
jobs The child jobs.
name A name, can be any text.
state The state condition to check against.
stop Read only view of the internal stop flag.

Example Summary

Example 1 If a file exists.
Example 2 An example showing lots of if's.
Example 3 Asynchronous evaluation.

Property Detail

executorService

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo. Will be provided by the framework.

Used for an asynchronous evaluation of the if.

jobs

Configured ByELEMENT
AccessWRITE_ONLY
RequiredAt least one.

The child jobs.

name

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

A name, can be any text.

state

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo, defaults to COMPLETE.

The state condition to check against. See the Oddjob User guide for a full list of state conditions.

stop

AccessREAD_ONLY

Read only view of the internal stop flag. This flag is cleared with a reset.


Examples

Example 1

If a file exists.

<oddjob id="this" xmlns:state="http://rgordon.co.uk/oddjob/state">
    <job>
        <state:if>
            <jobs>
                <exists name="Check File Exists" file="${this.dir}/data/some.txt"/>
                <echo id="then" name="Echo to Console">File Exists</echo>
                <echo id="else" name="Echo to Console">File Doesn't Exist</echo>
            </jobs>
        </state:if>
    </job>
</oddjob>

Example 2

An example showing lots of if's. All these if's go to COMPLETE state when run.

<oddjob>
    <job>
        <sequential xmlns:state="http://rgordon.co.uk/oddjob/state">
            <jobs>
                <state:if>
                    <jobs>
                        <echo>Hello</echo>
                        <echo>Good Bye</echo>
                    </jobs>
                </state:if>
                <state:if>
                    <jobs>
                        <state:flag name="Exception" state="EXCEPTION"/>
                        <state:flag name="Unexpected 1" state="EXCEPTION"/>
                        <echo>No Hello</echo>
                    </jobs>
                </state:if>
                <state:if>
                    <jobs>
                        <echo>Only Hello</echo>
                    </jobs>
                </state:if>
                <state:if state="!COMPLETE">
                    <jobs>
                        <state:flag name="Exception" state="EXCEPTION"/>
                        <echo>No Hello</echo>
                    </jobs>
                </state:if>
                <state:if state="!COMPLETE">
                    <jobs>
                        <echo>Hello</echo>
                        <state:flag name="Unexpected 2" state="EXCEPTION"/>
                    </jobs>
                </state:if>
                <state:if state="!EXCEPTION">
                    <jobs>
                        <echo>Hello</echo>
                        <echo>Good Bye</echo>
                        <state:flag name="Unexpected 3" state="EXCEPTION"/>
                    </jobs>
                </state:if>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example 3

Asynchronous evaluation. Only when the first job moves beyond it's ACTIVE state will the condition be evaluated and the then job (second job) be executed. The execution of the second job is also asynchronous.

<oddjob>
    <job>
        <state:if id="if-job" xmlns:state="http://rgordon.co.uk/oddjob/state">
            <jobs>
                <parallel>
                    <jobs>
                        <state:flag/>
                    </jobs>
                </parallel>
                <echo id="then-job">That Worked!</echo>
                <echo id="else-job">This should never be shown.</echo>
            </jobs>
        </state:if>
    </job>
</oddjob>


(c) R Gordon Ltd 2005 - Present