Class InvokeJob

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

public class InvokeJob extends SerializableJob implements Stoppable
Author:
rob
See Also:

Description

Invoke a java method or script snippet.

This is a wrapper for InvokeType. The result of the invocation is placed in the result property.

Note that stopping this job will simply attempt to interrupt the thread invoking the method. The outcome of this will obviously vary.

Oddjob will do it's best to convert arguments to the signature of the method or operation. An exception will result if it can't achieve this.

Example

Invoking a method on a bean.
<oddjob>

    <job>

        <sequential>

            <jobs>

                <invoke id="invoke-job" function="echo">

                    <source>

                        <bean class="org.oddjob.script.EchoService"/>

                    </source>

                    <parameters>

                        <value value="Hello"/>

                    </parameters>

                </invoke>

                <echo id="echo">${invoke-job.result}</echo>

            </jobs>

        </sequential>

    </job>

</oddjob>
Where EchoService is:

java.io.IOException: No Resource Found: 'org/oddjob/script/EchoService.java', classloader=java.net.URLClassLoader@5d6cac57

Invoking a static method. Note that this uses args instead of parameters for convenience.
<oddjob>

    <job>

        <invoke function="static totalPrice" id="invoke-totalPrice">

            <args>

                <tokenizer text="Red Apples, 24, 47.3"/>

            </args>

            <source>

                <class name="org.oddjob.script.InvokeJobTest"/>

            </source>

        </invoke>

    </job>

</oddjob>
Examples elsewhere.

See InvokeType for several more examples. Property configuration is the same for the type and the job.

The JMXServiceJob job has an example of invoking a JMX operation.

  • Constructor Details

    • InvokeJob

      public InvokeJob()
      Constructor.
  • Method Details

    • execute

      protected int execute() throws Throwable
      Description copied from class: SimpleJob
      Execute this job.
      Specified by:
      execute in class SimpleJob
      Returns:
      0 if the job is complete, anything else otherwise.
      Throws:
      Throwable
    • onReset

      protected void onReset()
      Description copied from class: SimpleJob
      Allow sub classes to do something on reset.
      Overrides:
      onReset in class SimpleJob
    • onStop

      protected void onStop() throws FailedToStopException
      Description copied from class: SimpleJob
      Allow sub classes to do something on stop.
      Overrides:
      onStop in class SimpleJob
      Throws:
      FailedToStopException
    • getSource

      public Invoker getSource()
    • setSource

      public void setSource(Invoker source)
    • getFunction

      public String getFunction()
    • setFunction

      public void setFunction(String function)
    • getParameters

      public ArooaValue getParameters(int index)
    • setParameters

      public void setParameters(int index, ArooaValue parameter)
    • getArgs

      public Object[] getArgs()
    • setArgs

      public void setArgs(Object[] args)
    • getResult

      public Object getResult()