Class NashornAccessorHostApplication

  • public class NashornAccessorHostApplication
    extends java.lang.Object
    Instantiate and Invoke Accessors using Nashorn. Evaluate the arguments, which are expected to be JavaScript files that define Composite Accessors.

    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 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:

    Echo the command that would be run by hand to replicate the test. This is helpful for use under Ant apply.
    Print a usage message
    -j|--j|-js|--js filename
    Interpret the next argument as the name of a regular JavaScript file to evaluate.
    Keep the calling process alive until either a timeout option expires or all instanted accessors have called wrapup.
    -timeout|--timeout milliseconds
    The minimum amount of time the script should run.
    Print out the version number

    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 -timeout 10000 -js hosts/nashorn/test/testNashornHost.js)

    To run a composite accessor:

     (cd $PTII/org/terraswarm/accessor/accessors/web; $PTII/bin/ptinvoke -timeout 10000 test/auto/RampJSDisplay.js)

    The command line syntax is:

     java -classpath $PTII \
      [-h|--h|-help|--help] \
      [-e|--e|-echo|--echo] \
      [-j|--j|-js|--js filename] \
      [-timeout|--timeout milliseconds] \
      [-v|--v|-version|--version] \
      accessorClassName [accessorClassName ...]
    Ptolemy II 11.0
    Christopher Brooks
    Red (cxh)
    Red (cxh)
    • Constructor Detail

      • NashornAccessorHostApplication

        public NashornAccessorHostApplication()
    • Method Detail

      • createOrchestrator

        public static NashornAccessorHostApplication.ActorSubstitute createOrchestrator​(java.lang.String name)
        Create an orchestrator for a top-level accessor.
        name - The name for the orchestrator.
        an aorchestrator for the top-level accessor.
      • evaluate

        public static int evaluate​(java.lang.String[] args)
                            throws java.lang.Throwable
        Evaluate the files named by the arguments.
        args - An array of one or more file names. See the class comment for the syntax.
        0 for success, 3 for argument problems. See main() in commonHost.js.
        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.
      • main

        public static void main​(java.lang.String[] args)
        Invoke one or more JavaScript files.
        args - One or more JavaScript files. See the class comment for the syntax.