Releases of Scripting Engines
The JobScheduler supports different scripting engines:
- SpiderMonkey which is included in the JobScheduler release
- Rhino which is part of the Java Run Time Environment (JRE) for versions up to 1.7
- Nashorn which is part of the Java Run Time Environment for versions starting from 1.8
The scripting engines are available as follows:
- The SpiderMonkey engine is only available for 32 bit. 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">
and<script language="javax.script:ECMAscript"/>
for a JRE up to 1.7 - The Rhino with Beans engine is available for 32 bit and 64 bit. It is selected by
<script language"java:javascript">
Language | 32 bit | 64 bit |
---|---|---|
spidermonkey | SpiderMonkey | — |
javascript | spiderMonkey | — |
javax.script:rhino | Rhino | Rhino |
java:javascript | Rhino (with beans) | Rhino (with beans) |
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.
- Please refer to the API documentation for more details.
Migrating JavaScript from Rhino to Nashorn
- Both JavaScript engines are compatible in many aspects.
- see How to change over to Java 1.8 - the new Nashorn JavaScript engine
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
See also
- What Java scripting languages are supported?
- How to change over to Java 1.8 - the new Nashorn JavaScript engine