public class NashornAccessorHostApplication
extends java.lang.Object
The Nashorn and Cape Code Accessor hosts are similar in that they both use Nashorn as the underlying JavaScript engine. They also both can invoke JavaScript accessors that use modules defined in $PTII/ptolemy/actor/lib/jjs/modules.
The Nashorn Accessor Host differs from the Cape Code Accessor Host in that Cape Code Accessor Host reads in Ptolemy II .xml MoML files and can invoke regular Ptolemy II actors written in Java such a ptolemy.actor.lib.Ramp. The Nashorn Accessor Host reads in .js files that define CompositeAccessors. The Nashorn Accessor Host is not intended to invoke regular Ptolemy II actors written in Java and it does not invoke the Ptolemy II actor execution semantics code implemented in Java.
Note that by using code generation, Cape Code .xml MoML files can be converted in to .js Composite Accessor files provided that the .xml file only uses JavaScript and JSAccessor actors.
The main() method of this class takes the following command line arguments:
-e|--e|-echo|--echo
-h|--h|-help|--help
-j|--j|-js|--js filename
-k|--k|-keepalive|--keepalive
-timeout|--timeout milliseconds
-v|--v|-version|--version
After the flags, the one or more JavaScript files are present that name either or regular JavaScript files.
To run a very simple test:
(cd $PTII/org/terraswarm/accessor/accessors/web; $PTII/bin/ptinvoke ptolemy.actor.lib.jjs.NashornAccessorHostApplication -timeout 10000 -js hosts/nashorn/test/testNashornHost.js)
To run a composite accessor:
(cd $PTII/org/terraswarm/accessor/accessors/web; $PTII/bin/ptinvoke ptolemy.actor.lib.jjs.NashornAccessorHostApplication -timeout 10000 test/auto/RampJSDisplay.js)
The command line syntax is:
java -classpath $PTII ptolemy.actor.lib.jjs.NashornAccessorHostApplication \ [-h|--h|-help|--help] \ [-e|--e|-echo|--echo] \ [-j|--j|-js|--js filename] \ [-timeout|--timeout milliseconds] \ [-v|--v|-version|--version] \ accessorClassName [accessorClassName ...]
Modifier and Type | Class and Description |
---|---|
static class |
NashornAccessorHostApplication.ActorSubstitute
Class that substitute for the JavaScript actor so that setTimeout,
setInterval, and CapeCode modules work in a pure Nashorn host.
|
Constructor and Description |
---|
NashornAccessorHostApplication() |
Modifier and Type | Method and Description |
---|---|
static NashornAccessorHostApplication.ActorSubstitute |
createOrchestrator(java.lang.String name)
Create an orchestrator for a top-level accessor.
|
static int |
evaluate(java.lang.String[] args)
Evaluate the files named by the arguments.
|
static void |
main(java.lang.String[] args)
Invoke one or more JavaScript files.
|
public static NashornAccessorHostApplication.ActorSubstitute createOrchestrator(java.lang.String name)
name
- The name for the orchestrator.public static int evaluate(java.lang.String[] args) throws java.lang.Throwable
args
- An array of one or more file names. See the class comment for
the syntax.java.lang.Throwable
- If the Nashorn engine cannot be found, if
a file cannot be read or closed. if evaluateCode() JavaScript
method is not defined or if there is a problem evaluating a
file.public static void main(java.lang.String[] args)
args
- One or more JavaScript files. See the class
comment for the syntax.