Skip to end of metadata
Go to start of metadata

Releases of Scripting Engines

The JobScheduler supports different scripting engines:

The scripting engines are available as follows:

  • The SpiderMonkey engine is only available for 32 bit JobScheduler. It is selected by <script language="javascript"> and <script language"spidermonkey">
  • The Rhino engine is available for 32 bit and 64 bit. It is selected by <script language="javax.script:rhino">, <script language="javax.script:JavaScript"> and <script language="javax.script:ECMAscript"/> for a JRE up to 1.7
  • The Nashorn engine is available for 32 bit and 64 bit. It is selected by <script language="javax.script:JavaScript"> and <script language="javax.script:ECMAscript"/> for a JRE starting from 1.8
  • The "Rhino (with Beans)" / "Nashorn (with Beans)" engine is available for 32 bit and 64 bit. It is selected by <script language"java:javascript">

Language

Used Engine on 32 Bit JobScheduler

Used Engine on 64 Bit JobScheduler

Available in
JobScheduler Release

spidermonkey

SpiderMonkey

All releases, only 32 bit

javascript

SpiderMonkey

All releases, only 32 bit

javax.script:rhino

Rhino (up to JRE 1.7 only)

Rhino (up to JRE 1.7 only)

Starting from 1.5
javax.script:JavaScript

up to JRE 1.7: Rhino
starting from JRE 1.8: Nashorn

up to JRE 1.7: Rhino

starting from JRE 1.8: Nashorn
Starting from 1.5
javax.script:ECMAscript

up to JRE 1.7: Rhino
starting from JRE 1.8: Nashorn

up to JRE 1.7: Rhino

starting from JRE 1.8: Nashorn
Starting from 1.5

java:javascript

JRE 1.7: Rhino (with Java beans layer)
JRE 1.8: Nashorn (with Java beans layer)

JRE 1.7: Rhino (with Java beans layer)
JRE 1.8: Nashorn (with Java beans layer)

Starting from 1.5

If you want to migrate a Javascript for SpiderMonkey to a 64 bit JobScheduler then in most cases you just have to modify the language attribute to <script language="java:javascript">. This works within limits.

Migration Strategies

Migrating JavaScript from Spidermonkey to Rhino

  • We recommend to change the JavaScript to the Rhino syntax. Then it works properly with 32 bit and 64 bit JobScheduler.
    Rhino doesn't have properties. You have to use "setter" and "getter" methods instead.

    Example:

    Spidermonkey

    order.state = String       // Set the order state using the property
    String = order.state       // Get the order state using the property


    Rhino

    order.set_state( String )  // Set the order state using the setter method
    String = order.state()     // Get the order state using the getter method
  • Please refer to the API documentation for more details.

Migrating JavaScript from Rhino to Nashorn

Syntax Examples

Examples for syntactic differences

  • SpiderMonkey
     
Example: job name and task id
 // log job name and tsk id
 spooler_log.info( spooler_job.name + " is running with task id " + spooler_task.id );
Example: add an order to a job chain
 // add an order
 var order = spooler.create_order();
 order.title = "this is an order";
 order.id = "my order id";
 spooler.job_chain( "/path/to/job chain/job chain name" ).add_order( order );
Example: set job state text
 // set a job state text
 spooler_job.state_text = "OK!";
Example: read and write parameter from the current order
 // read and write parameter from the current order
 var orderParams = spooler_task.order.params;
 var myParam = orderParams.value("myParam");
 orderParams.value("myParam") = "new value";
  • Rhino
Example: job name and task id
 // log job name and tsk id
 spooler_log.info(spooler_job.name() + " is running with task id " + spooler_task.id() );
Example: add an order to a job chain
 // add an order
 var order = spooler.create_order();
 order.set_title("this is an order");
 order.set_id("my order id");
 spooler.job_chain( "/path/to/job chain/job chain name" ).add_order( order );
Example: set a job state text
 // set a job state text
 spooler_job.set_state_text("OK!");
Example: read and write parameter from the current order
 // read and write parameter from the current order
 var orderParams = spooler_task.order().params();
 var myParam = orderParams.value("myParam");
 orderParams.set_value("myParam", "new value");

Examples for differences when using reserved words

  • Using the Rhino engine there are no JavaScript reserved words allowed. Therefore, the following code can't be executed with the "Rhino with Beans" engine:
Example: use of a reserved word
 var file = new java.io.File(files[i]);
 file.delete();
  • Since delete is a reserved word in JavaScript the code above results in the following error:
Example: error message when using a reserved word
 javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing name after . operator (<Unknown source>#26) in <Unknown   source> at line number 26
       at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
       at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
       at javax.script.AbstractScriptEngine.eval(Unknown Source)
       at com.sos.scheduler.scripting.Module.call(Module.java:76)
       at com.sos.scheduler.scripting.Module.callBoolean(Module.java:85)
  • Compatible Solution:
Example: compatible solution
 var file = Packages.java.io.File(files[i]);
 file["delete"]();				// because delete is reserved in javascript

Getting Java Objects

The following ECMA script construction can be used to instantiate Java objects using new Packages.myPacket.myClass();

Example:Getting Java Objects
function myFunction(){
    
    var params;
    
    var debugParameter = function(paramName) {
        try{
            spooler_log.debug1(".. mail parameter ["+paramName+"]: "+params.value(paramName));
        } catch (e){} //No error handling
    }
    
    try{
        var myVariable = spooler_log.mail();
        this.myObject = new Packages.myPacket.myClass();
        ....
    } catch(e){
        throw "Error initializing myObject: "+e;
    }
    ....
}

 

Note that import myPacket.myClass(); will cause an initialization error message when used in ECMA script.

For example, the following error would be typical for import sos.net.SOSMail;

Example: Getting Java Objects
[ERROR]  COM-80020009  Ausnahmefehler aufgetreten. [step] [] [Z-JAVA-105  Java exception java.lang.RuntimeException: javax.script.ScriptException: sun.org.mozilla.javascript.internal.JavaScriptException: Error initializing sosMail: TypeError: Cannot find function set_queue_dir in object sos.net.SOSMail@2403f3b1. (<Unknown source>#39) in <Unknown source> at line number 39 - caused by - javax.script.ScriptException: sun.org.mozilla.javascript.internal.JavaScriptException: Error initializing sosMail: TypeError: Cannot find function set_queue_dir in object sos...], method=call

For more information, see:

See also

 

Write a comment…