Recent Changes - Search:

edit SideBar


The goal is to be able to start and stop multiple accessors in an accessor host.

Use Case

  • commonHost.js should define accessor life cycle management functions.
  • The Node Host should create a web page that allows the user to start and stop accessors.

Questions and Actions

  • CommonHost should be modified to have a Container that is accessible by the hosts.
    • Note that for Cape Code, the container would typically be a Ptolemy II CompositeAccessor (Supporting containers that only contain accessors could be added later)
      • Under Cape Code, a containedAccessors attribute would be added to the CompositeAccessor
      • Cape Code would provide an interface that would add accessors to the containerAccessors parameter and the list of accessors would be queryable.
  • Add a new method to commonHost called stopAll() that would stop all the accessors.
  • Update the style guide to suggest that the return values of setInterval() and setTimeout() be managed so that wrapup() can clear them.
  • Need help with the web page that would allow access
    • How would the web page communicate with non-Node Accessor Hosts?


  • stop():
    • The Cape Code Host defines stop() and will stop just the current Composite Accessor
    • The Common Host formerly defined stop() to merely print a message, now it invokes wrapup() for all the accessors.
      • This should be modified to invoke the accessors for only the current accessor and a stopAll() function should be added.
    • The Duktape Host does not define stop(), so it uses the Common Host definition above
    • The Node Host formerly had a stop(), but it was moved to commonHost.
  • Container
    • When an accessor is instantiated and invoked, a handle needs to be saved in the container
      • It should be possible to query which handles are present
      • It should be possible to stop just one Composite Accessor
    • The Cape Code Host does not define a Container.
    • The Node Host has a container
      • instantiateAndInitialize(accessorNames) returns an array of accessors created by instantiate(accessorName, accessorClass)
      • The Composite Accessors that are generated by Cape Code Host Code Generation add each accessor to a container variable that is checked in the stop() method


Initial Operations

  1. Start a Composite Accessor
  2. Stop a Composite Accessor
    • What does it mean to stop a composite accessor?
      • Only accessors in the current composite accessor should be stopped.
      • Stopping an accessor means invoking its wrapup() method
      • All accessors in a composite should have wrapup() called, even if wrapup() throws an error in one of the accessors.
      • Perhaps the style guide should be updated to state that accessors should keep track of the return value from setInterval() and setTimeout() so that wrapup() could call clearInterval() and clearTimeout.
      • See Sandboxing.
  3. Stop all Composite accessors
    • For example, if we are calling exit
      • nodeHost.js registers a handler to catch exit() and then invokes wrapup() on all the accessors

Optional Operations

  1. Reload an accessor after the definition has changed.
  2. Detect busy waiting processes (See Sandbox).
  3. Detect if a composite accessor is no longer running and consider starting it up again.
    1. This is starting to sound like a reimplementing npm forever.


There is something to be learned from other systems:

  • Ptolemy II has preinitialize, initialize, prefire, fire, postfire and wrapup
  • Unix processes can be running, blocked on I/O, waiting (ready to be run). See Wikipedia Process (Computing)


  • JavaScript is single threaded and depends on callbacks.
    • How do we defend against an accessor that is in a tight busyloop?
  • Security
    • Access to the Node Host webpage
    • What about authentication of the control signals between the Node Host webpage and the host running the accessors?

Current Status

Cape Code Host Current Status

  • The Cape Code Host can invoke multiple Ptolemy models that define Composite Accessors.
  • Cape Code runs each Composite Accessor in its own JavaScript engine. This makes it easier to kill a non-cooperative Composite Accessor, in principle, and provides more rigorous isolation between accessors. But it may be a resource hog. See also Sandbox.
  • CapeCode does not have an easy way of invoking .js files that define Composite Accessors, though the Cape Code Code Generation facility will execute Composite Accessors
    • It is unclear if we need this capability, though it would give us good a Sandbox

stop() in the Cape Code Host

In the Cape Code Host, stop is defined in @@$PTII/ptolemy/actor/lib/jjs/localFunctions.js:

// Stop execution of the model.  See ptolemy/actor/lib/                                                    
function stop() {
The above code ends up invoking wrapup() for all the accessors.

Common Host Current Status

stop() in the Common Host

Formerly, in the Common Host, stop() is defined, but does nothing (source, jsDoc)

Christopher moved stop() from nodeHost.js to commonHost.js

Node Host Current Status

nodeHost.js (source, jsDoc) defines an main() function that will invoke one or more accessors.

Note that nodeHost invoke(argv) is meant to be called from a very short script:

// Remove "node.js" from the array of command line arguments.                                                            
// Remove "nodeHostInvoke.js" from the array of command line arguments.                                                  

main(argv) takes an optional -timeout option that names the time out in ms.

main(argv) invokes nodeHost instantiateAndInitialize() on each of the composite accessors.

It is up to the composite accessors to cooperate.

See Command Line Arguments.

stop() in the Node Host

Formerly, in the Node Host, stop() invokes wrapup() on all the contained accessors.

Now stop() from commonHost.js is invoked.

See [[ | Node.js: inspect what's left in the event loop that's preventing the script from exiting naturally]] (StackOverflow) to use

Duktape Host Current Status

The Duktape Host has a duk executable that evaluates its arguments. Multiple arguments are supported:

cd accessors/web/host/duktape/duktape                                                                          
cd ../..

# Then we create a second testComposite that has 42 instead of 50.

bash-3.2$ sed 's/50/42/'< duktape/test/testComposite.js  > duktape/test/testComposite42.js
bash-3.2$ ./duktape/duktape/duk duktape/test/testComposite.js duktape/test/testComposite42.js
duk: About to eval duktape/test/testComposite.js
duktape/test/testComposite.js: OK: output was 50, which is equal to 50.
duk: About to eval duktape/test/testComposite42.js
Error: duktape/test/testComposite.js: output was 50, it should have been 42.
        global duktape/test/testComposite42.js:17 preventsyield
error in executing file duktape/test/testComposite42.js

# It is ok that the above failed, that is what is expected.

stop() in the Duktape Host

It looks like we don't have a stop() method defined.

See Also

Edit - History - Print - Recent Changes - Search
Page last modified on December 12, 2016, at 02:53 AM