Class: Service

(protected) Service(settings)

The "Service" is a simple model for processing messages in a distributed system. Service instances are public interfaces for outside systems, and typically advertise their presence to the network. To implement a Service, you will typically need to implement all methods from this prototype. In general, `connect` and `send` are the highest-priority jobs, and by default the `fabric` property will serve as an I/O stream using familiar semantics.

Constructor

(protected) new Service(settings)

Create an instance of a Service.
Parameters:
Name Type Description
settings Object Configuration for this service.
Properties
Name Type Attributes Default Description
networking Boolean <optional>
true Whether or not to connect to the network.
@data Object <optional>
Internal data to assign.
Properties:
Name Type Description
map The "map" is a hashtable of "key" => "value" pairs.
Source:

Methods

(async) _GET(path) → {Promise}

Retrieve a value from the Service's state.
Parameters:
Name Type Description
path String Path of the value to retrieve.
Source:
Returns:
Resolves with the result.
Type
Promise

(async) _PUT(path, value, commitopt) → {Promise}

Store a value in the Service's state.
Parameters:
Name Type Attributes Default Description
path String Path to store the value at.
value Object Document to store.
commit Boolean <optional>
false Sign the resulting state.
Source:
Returns:
Resolves with with stored document.
Type
Promise

(async) _registerActor(actor) → {Promise}

Register an Actor with the Service.
Parameters:
Name Type Description
actor Object Instance of the Actor.
Source:
Returns:
Resolves upon successful registration.
Type
Promise

(async) _send(message)

Sends a message.
Parameters:
Name Type Description
message Mixed Message to send.
Source:

beat() → {Service}

Compute latest state.
Source:
Fires:
  • Message#event:beat
Returns:
Type
Service

(async) connect(notify) → {Promise}

Attach to network.
Parameters:
Name Type Default Description
notify Boolean true Commit to changes.
Source:
Returns:
Resolves to Fabric.
Type
Promise

get(path) → {Mixed}

Retrieve a key from the State.
Parameters:
Name Type Description
path Path Key to retrieve.
Source:
Returns:
Type
Mixed

handler(message) → {Service}

Default route handler for an incoming message. Follows the Activity Streams 2.0 spec: https://www.w3.org/TR/activitystreams-core/
Parameters:
Name Type Description
message Activity Message object.
Source:
Returns:
Chainable method.
Type
Service

init()

Called by Web Components. TODO: move to @fabric/http/types/spa
Source:

lock(durationopt) → {Boolean}

Attempt to acquire a lock for `duration` seconds.
Parameters:
Name Type Attributes Default Description
duration Number <optional>
1000 Number of milliseconds to hold lock.
Source:
Returns:
true if locked, false if unable to lock.
Type
Boolean

(async) route(msg) → {Promise}

Resolve a State from a particular Message object.
Parameters:
Name Type Description
msg Message Explicit Fabric Message.
Source:
Returns:
Resolves with resulting State.
Type
Promise

(async) send(channel, message) → {Service}

Send a message to a channel.
Parameters:
Name Type Description
channel String Channel name to which the message will be sent.
message String Content of the message to send.
Source:
Returns:
Chainable method.
Type
Service

set(path) → {Mixed}

Set a key in the State to a particular value.
Parameters:
Name Type Description
path Path Key to retrieve.
Source:
Returns:
Type
Mixed

(async) start()

Start the service, including the initiation of an outbound connection to any peers designated in the service's configuration.
Source:

tick() → {Number}

Move forward one clock cycle.
Source:
Returns:
Type
Number

trust(source) → {Service}

Explicitly trust all events from a known source.
Parameters:
Name Type Description
source EventEmitter Emitter of events.
Source:
Returns:
Instance of Service after binding events.
Type
Service