Module: @accessors-hosts/nodeHost

Node.js swarmlet host module. To use this, issue the following command:

var nodeHost = require(path + '/nodeHost.js');

where path is the path to this nodeHost.js file.

The resulting nodeHost object provides a number of functions, including:

  • getAccessorCode(accessorClass): Return the source code for an accessor, given its fully-qualified class name, e.g. 'net/REST'.

  • getTopLevelAccessors(): Return an array of instantiated top-level accessors (implemented in commonHost.js).

  • installIfMissingThenRequire(npmPackage): Check the require path for a module and if it is not found, invoke npm install.

  • instantiate(accessorName, accessorClass): Instantiate an accessor with an assigned name (an arbitrary string) and its fully-qualified class name, e.g. 'net/REST'.

  • instantiateTopLevel(): Instantiate and return a top-level accessor.

  • startHostShell(): Start an interactive shell on stdin/stdout to execute commands. Type 'help' in this shell for a list of supported commands.

  • stopAllAccessors(): Call wrapup on all top-level accessors.

    See nodeHostShell.js for an example use of this module.

    See https://accessors.org/accessors/wiki/Main/DuktapeHost.

Version:
  • $$Id$$
Author:
  • Edward A. Lee, Chris Shaver, Christopher Brooks
Source:

Members

(inner) accessorPath

Module variable giving the paths to search for accessors. By default this module assumes that accessors are stored in dirname/../.., where dirname is the directory where this script is located.

Source:

Methods

(inner) exitHandler(options)

Handle calls to exit, Control-C, errors and uncaught exceptions. The wrapup() method is invoked for all accessors. The first exception is reported and process.exitCode is set to non-zero;

Parameters:
Name Type Description
options

Properties for the call. Properties include cleanup and exit.

Source:

(inner) getAccessorCode(name)

Return the source code for an accessor from its fully qualified name.

A name can be an absolute pathname, a relative pathname or a fully qualified accessor name such as 'net/REST'.

If name refers to a file that can be read, then the contents of that file are returned. If name does not refer to a file that can be read, then each element of the accessorPath array is prepended to the name and a file read is attempted.

If there is no such accessor on the accessor search path, then an exception is thrown.

Parameters:
Name Type Description
name

Fully qualified accessor name, e.g. 'net/REST'.

Source:

(inner) getHostName()

Return the name of this host.

Return the string "Node".

Source:
Returns:

In nodeHost.js, return "Node".

(inner) getResource(uri)

Get a resource. Below are the types of resources that are handled all other resources will cause an error.

  • $KEYSTORE is replaced with $HOME/.ptKeystore
Parameters:
Name Type Description
uri

A specification for the resource.

Source:

(inner) installIfMissingThenRequire(npmPackage)

Check the require path for a module and if it is not found, invoke npm install.

In node, the module loading system caches the return values of stat() calls. Thus, if we require() a missing package, then installing it will not invalidate the cache and calling require() again will not find our newly installed cache. As a workaround, for possibly missing packages, we search the array of paths contained by module.paths.

Parameters:
Name Type Description
npmPackage

the package to be possibly installed using npm and then required.

Source:
Returns:

the value returned by requiring the package

(inner) instantiate(accessorName, accessorClass)

Instantiate and return an accessor. This will throw an exception if there is no such accessor class on the accessor search path.

Parameters:
Name Type Description
accessorName

The name to give to the instance.

accessorClass

Fully qualified accessor class name, e.g. 'net/REST'.

Source:

(inner) instantiateInterface(accessorName, accessorClass)

Return an accessor and a list of its required modules for purposes of examining its non-functional characteristics. This is accomplished by instantiating the accessor, and ignoring any exceptions from require due to modules that do not exist for this host.

WARNING: An accessor instantiated by this function may be unusable in a swarmlet! Use instantiate if you want to run the accessor later.

FIXME: The instantiatedInterface still appears to the swarmlet as an ordinary instantiated accessor. I think we should delete it immediately after getting its data.

This will throw an exception if there is no such accessor class on the accessor search path.

Parameters:
Name Type Description
accessorName

The name to give to the instance.

accessorClass

Fully qualified accessor class name, e.g. 'net/REST'.

Source:
Returns:

An object containing the accessor and a unique array of modules used by the accessor.

(inner) instantiateTopLevel(accessorName, accessorClass)

Instantiate and return a top-level accessor. This will throw an exception if there is no such accessor class on the accessor search path.

Parameters:
Name Type Description
accessorName

The name to give to the instance.

accessorClass

Fully qualified accessor class name, e.g. 'net/REST'.

Source:

(inner) processCommandLineArguments(args)

Instantiate and invoke a composite accessor.

This function is useful for invoking the Node host on a composite accessor. This function calls process.exit() upon termination of the accessor.

Parameters:
Name Type Description
args

An array of command line arguments. For the values of the arguments, see the documentation for commonHost.processCommandLineArguments().

Source:

(inner) startHostShell()

Start an interactive version of this host as a shell. This will produce a prompt on stdout that accepts JavaScript statements on stdin and executes them.

Source: