Host
Static Method Summary
Static Public Methods | ||
public static |
isSuperUser(): * Is the user running this process a super user? |
|
public static |
tempDir(): * Get the current Stencila temporary directory |
|
public static |
userDir(): * Get the current user's Stencila data directory |
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public get |
id: * Get unique ID of this host |
|
public get |
Get the key of this host |
|
public get |
Get information on the machine that this host is running on |
|
public get |
Get information on the process that this host is running in |
|
public get |
servers: array: * Get a list of server names for this host |
|
public get |
types: * Get specifications for context types provided by this Host, including types provided by peer Hosts. |
|
public get |
urls: array: * Get a list of URLs for this host |
Private Members | ||
private |
_counts: {} |
|
private |
_heartbeat: * |
|
private |
|
|
private |
_instances: {} |
|
private |
_key: * |
|
private |
_machine: {"id": *, "ip": *} |
|
private |
_peers: {} |
|
private |
_servers: {} |
|
private |
_started: * |
Method Summary
Public Methods | ||
public |
authorizeToken(token: String): * Authorize a request token. |
|
public |
Call a method of an instance |
|
public |
Compile a library |
|
public |
Create a new instance of a type |
|
public |
Destroy an instance |
|
public |
async discoverPeers() Discover peers |
|
public |
Get the execution environments supported by this host |
|
public |
async generateToken(host: String): * Generate a request token |
|
public |
Get an instance |
|
public |
Update this host's heartbeat Can be called explictly by a peer (i.e. |
|
public |
Get a manifest for this host |
|
public |
async register() Register as a host for the current execution environment. |
|
public |
registerPeer(objectPattern: {"id": *, "manifest": *, "key": *}, child: *): * |
|
public |
async requestPeer(peer: *, method: string, path: string, data: undefined): * |
|
public |
Resolve an instance identifier to an instance |
|
public |
run(options: {}): * Start serving this host and wait for connections indefinitely |
|
public |
|
|
public |
async spawn(options: {}): {"id": *, "manifest": *, "key": *} |
|
public |
Spawn a peer from an inactive host manifest |
|
public |
Start serving this host |
|
public |
async startup(id: *): {"path": *} |
|
public |
Stop serving this host |
|
public |
view() View this host in the browser |
Static Public Methods
Public Constructors
public constructor() source
Public Members
public get machine: Object: * source
Get information on the machine that this host is running on
Used for resolving data pointers (amongst other things)
public get process: Object: {"pid": *, "name": *, "version": *, "platform": *, "arch": *} source
Get information on the process that this host is running in
Used by peer hosts to check that this host is runing (amongst other things)
public get servers: array: * source
Get a list of server names for this host
Servers are identified by the protocol shorthand
e.g. http
for HostHttpServer
Return:
array | Array of strings |
public get types: * source
Get specifications for context types provided by this Host, including types provided by peer Hosts.
Types which are provided by this Host directly are marked
with local: true
, and those provided by peers with
local: false
Private Members
private _counts: {} source
private _heartbeat: * source
private _instances: {} source
private _key: * source
private _machine: {"id": *, "ip": *} source
private _peers: {} source
private _servers: {} source
private _started: * source
Public Methods
public authorizeToken(token: String): * source
Authorize a request token.
Throws an error if the token is invalid.
Params:
Name | Type | Attribute | Description |
token | String | Token string (usually from the |
Return:
* |
public async call(id: String, method: String, data: Object): * source
Call a method of an instance
Return:
* |
public async compile(options: Object): Object source
Compile a library
Params:
Name | Type | Attribute | Description |
options | Object | Options for the |
public async create(type: string, options: options): Object source
Create a new instance of a type
Params:
Name | Type | Attribute | Description |
type | string | Type of instance |
|
options | options | Arguments to be passed to type constructor |
public async destroy(id: String): * source
Destroy an instance
Params:
Name | Type | Attribute | Description |
id | String | Instance identifier |
Return:
* |
public async discoverPeers() source
Discover peers
Looks for peer hosts in the following locations (on Linux, equivalents on other OSs):
/tmp/stencila/hosts
- hosts that are currently active (i.e. running)~/.stencila/hosts
- hosts that are installed but inactive
This method is intended to be robust to errors in peer files etc and will only register an active peer if it can connect to it and access its key file
public async generateToken(host: String): * source
Generate a request token
Params:
Name | Type | Attribute | Description |
host | String | The id of the host |
Return:
* |
public async get(id: String): * source
Get an instance
Params:
Name | Type | Attribute | Description |
id | String | Instance identifier |
Return:
* |
public heartbeat(): Date source
Update this host's heartbeat
Can be called explictly by a peer (i.e. PUT /!heartbeat
)
but also called by the post
, get
, put
and delete
methods
above.
public async manifest(): Object source
Get a manifest for this host
The manifest describes the host and it's capabilities. It is used by peer hosts to determine which "types" this host provides and which "instances" have already been instantiated.
public async register() source
Register as a host for the current execution environment.
Registering a host involves creating a file node.json
inside of
the current environment's directory within the the user's
Stencila data directory (see userDir()
).
public registerPeer(objectPattern: {"id": *, "manifest": *, "key": *}, child: *): * source
Params:
Name | Type | Attribute | Description |
objectPattern | {"id": *, "manifest": *, "key": *} |
|
|
child | * |
Return:
* |
public async requestPeer(peer: *, method: string, path: string, data: undefined): * source
Return:
* |
public resolve(id: String): Object source
Resolve an instance identifier to an instance
Params:
Name | Type | Attribute | Description |
id | String | Instance identifier |
public run(options: {}): * source
Start serving this host and wait for connections indefinitely
Params:
Name | Type | Attribute | Description |
options | {} |
|
Return:
* |
public async spawn(options: {}): {"id": *, "manifest": *, "key": *} source
Params:
Name | Type | Attribute | Description |
options | {} |
|
Return:
{"id": *, "manifest": *, "key": *} |
public spawnPeer(peer: Object): [type] source
Spawn a peer from an inactive host manifest
Params:
Name | Type | Attribute | Description |
peer | Object | A peer object including |
Return:
[type] | [description] |
public async start(options: {}): Promise source
Start serving this host
Currently, HTTP is the only server available
for hosts. We plan to implement a HostWebsocketServer
soon.
Params:
Name | Type | Attribute | Description |
options | {} |
|
public async startup(id: *): {"path": *} source
Params:
Name | Type | Attribute | Description |
id | * |
Return:
{"path": *} |
public stop(options: {}): Promise source
Stop serving this host
Params:
Name | Type | Attribute | Description |
options | {} |
|
public view() source
View this host in the browser
Opens the default browser at the URL of this host