Recent Changes - Search:

edit SideBar

Container

commonHost module defines a method that creates an Accessor that has a container field.

A container that has one or more accessors is a Composite Accessor, which is a type of Swarmlet.

Cape Code

Cape Code is not setting container because the container is not a Composite Accessor. In Cape Code, the container is a TypedComposite actor that could have non-JavaScript and non-JSAccessor actors in it.

Cape Code does not call commonHost.instantiate() or instantiateAndInitialize(), instead Cape Code instantiates an Accessor.

In the end, the problem comes down to the fact that in Cape Code, we don't have a composite accessor that we can set as the container.

$PTII/ptolemy/actor/lib/jjs/JavaScript.java _createEngineAndEvaluateSetup() has:

         try {
             _instance = ((Invocable)_engine).invokeFunction(
                     "evaluateCode", getName(), scriptValue);
             _exports = ((Map)_instance).get("exports");
         } catch (Throwable throwable) {
             throw new IllegalActionException(this, throwable,
                     "Failed to evaluate script.");
         }

$PTII/ptolemy/actor/lib/jjs/localFunctions.js has:

 function evaluateCode(accessorName, code) {
     var bindings = {
         'clearInterval': clearInterval,
         'clearTimeout': clearTimeout,
         'error': error,
         'getParameter': getParameter,
         'httpRequest': httpRequest,
         'input': input,
         'output': output,
         'parameter': parameter,
         'readURL': readURL,
         'require': require,
         'send': send,
         'setDefault': setDefault,
         'setInterval': setInterval,
         'setParameter': setParameter,
         'setTimeout': setTimeout,
         'superSend': superSend
     };
     return new commonHost.Accessor(accessorName, code, getAccessorCode, bindings);
 }

Compare that with accessors/hosts/common/commonHost.js instantiate():

 Accessor.prototype.instantiate = function(instanceName, accessorClass) {
     if (!this.getAccessorCode) {
         throw('instantiate() is not supported by this swarmlet host.');
     }
     // For functions that accessor ports, etc., we want the default implementation
     // when instantiating the contained accessor.
     var insideBindings = {
         'clearInterval': this.clearInterval,
         'clearTimeout': this.clearTimeout,
         'error': this.error,
         'httpRequest': this.httpRequest,
         'readURL': this.readURL,
         'require': this.require,
         'setInterval': this.setInterval,
         'setTimeout': this.setTimeout,
     };
     instanceName = this.accessorName + '.' + instanceName;
     var containedInstance = instantiateAccessor(
             instanceName, accessorClass, this.getAccessorCode, insideBindings);
     containedInstance.container = this;
     this.containedAccessors.push(containedInstance);
     return containedInstance;
 };

It could be seen as a shortcoming that we can't get to the container and that an actor cannot force the container to call wrapup(). However, if we want Cape Code to support non-composite accessors, we probably need it to be this way.

Probably we want to modify Cape Code so that there is class that can instantiate and invoke a Composite Accessor that contains only pure accessors.

See Also

Edit - History - Print - Recent Changes - Search
Page last modified on November 07, 2016, at 09:17 pm