Home Reference Source
public class | source

Host

Static Method Summary

Static Public Methods
public static

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

key: string: *

Get the key of this host

public get

Get information on the machine that this host is running on

public get

process: Object: {"pid": *, "name": *, "version": *, "platform": *, "arch": *}

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

_key: *

private

_machine: {"id": *, "ip": *}

private

_peers: {}

private

_servers: {}

private

Method Summary

Public Methods
public

authorizeToken(token: String): *

Authorize a request token.

public

async call(id: String, method: String, data: Object): *

Call a method of an instance

public

async compile(options: Object): Object

Compile a library

public

async create(type: string, options: options): Object

Create a new instance of a type

public

async destroy(id: String): *

Destroy an instance

public

async discoverPeers()

Discover peers

public

async environs(): Array

Get the execution environments supported by this host

public

async generateToken(host: String): *

Generate a request token

public

async get(id: String): *

Get an instance

public

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

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

async shutdown(id: *): boolean

public

async spawn(options: {}): {"id": *, "manifest": *, "key": *}

public

spawnPeer(peer: Object): [type]

Spawn a peer from an inactive host manifest

public

async start(options: {}): Promise

Start serving this host

public

async startup(id: *): {"path": *}

public

stop(options: {}): Promise

Stop serving this host

public

view()

View this host in the browser

Static Public Methods

public static isSuperUser(): * source

Is the user running this process a super user?

Return:

*

public static tempDir(): * source

Get the current Stencila temporary directory

Return:

*

public static userDir(): * source

Get the current user's Stencila data directory

Return:

*

Public Constructors

public constructor() source

Public Members

public get id: * source

Get unique ID of this host

public get key: string: * source

Get the key of this host

Return:

string

Host's authentication key

public get machine: Object: * source

Get information on the machine that this host is running on

Used for resolving data pointers (amongst other things)

Return:

Object

Machine information

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)

Return:

Object

Process information

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

public get urls: array: * source

Get a list of URLs for this host

Return:

array

Array of strings

Private Members

private _counts: {} source

private _heartbeat: * source

private _id: string 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:

NameTypeAttributeDescription
token String

Token string (usually from the Authorization header of a HTTP request)

Return:

*

public async call(id: String, method: String, data: Object): * source

Call a method of an instance

Params:

NameTypeAttributeDescription
id String

Instance identifier

method String

Name of instance method

data Object

An object to apply the method to

Return:

*

public async compile(options: Object): Object source

Compile a library

Params:

NameTypeAttributeDescription
options Object

Options for the NodeContext.compileLibrary method

Return:

Object

Library node including bundle, the path to the bundle created

public async create(type: string, options: options): Object source

Create a new instance of a type

Params:

NameTypeAttributeDescription
type string

Type of instance

options options

Arguments to be passed to type constructor

Return:

Object

Identier and newly created instance

public async destroy(id: String): * source

Destroy an instance

Params:

NameTypeAttributeDescription
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 environs(): Array source

Get the execution environments supported by this host

Return:

Array

A list of supported execution environment

public async generateToken(host: String): * source

Generate a request token

Params:

NameTypeAttributeDescription
host String

The id of the host

Return:

*

public async get(id: String): * source

Get an instance

Params:

NameTypeAttributeDescription
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.

Return:

Date

Date/time of last heartbeat

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.

Return:

Object

Manifest object

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:

NameTypeAttributeDescription
objectPattern {"id": *, "manifest": *, "key": *}
  • default: {"id":null,"manifest":null,"key":null}
child *

Return:

*

public async requestPeer(peer: *, method: string, path: string, data: undefined): * source

Params:

NameTypeAttributeDescription
peer *
method string
  • optional
  • default: GET
path string
  • optional
  • default:
data undefined
  • optional
  • default: undefined

Return:

*

public resolve(id: String): Object source

Resolve an instance identifier to an instance

Params:

NameTypeAttributeDescription
id String

Instance identifier

Return:

Object

The instance

public run(options: {}): * source

Start serving this host and wait for connections indefinitely

Params:

NameTypeAttributeDescription
options {}
  • optional
  • default: {}

Return:

*

public async shutdown(id: *): boolean source

Params:

NameTypeAttributeDescription
id *

Return:

boolean

public async spawn(options: {}): {"id": *, "manifest": *, "key": *} source

Params:

NameTypeAttributeDescription
options {}
  • optional
  • default: {}

Return:

{"id": *, "manifest": *, "key": *}

public spawnPeer(peer: Object): [type] source

Spawn a peer from an inactive host manifest

Params:

NameTypeAttributeDescription
peer Object

A peer object including manifest

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:

NameTypeAttributeDescription
options {}
  • optional
  • default: {}

Return:

Promise

public async startup(id: *): {"path": *} source

Params:

NameTypeAttributeDescription
id *

Return:

{"path": *}

public stop(options: {}): Promise source

Stop serving this host

Params:

NameTypeAttributeDescription
options {}
  • optional
  • default: {}

Return:

Promise

public view() source

View this host in the browser

Opens the default browser at the URL of this host