Module: caf_ca/gen_handler

Generic CA handler plug.

A handler combines custom application methods with private state.

CAF binds methods to the handler object, enabling user code to access CA state using this, i.e., a traditional, non-functional, object abstraction.

Source:

Extends

Members

__ca_isHandler__ :boolean

Run-time type information.

Type:
  • boolean
Source:

scratch :Object

Contains anything, but it is not guaranteed to be preserved across message invocations.

Scratch is used for caching since in most cases it will be preserved across messages.

It can also help debugging, since its value is never rolled back.

Type:
  • Object
Source:

state :Object

JSON-serializable representation of a CA's private state.

The contents of this variable are always checkpointed before any state externalization.

The key __ca_version__ refers to the schema version for this.state.

Type:
  • Object
Source:

Methods

__ca_destroy__(dataopt, cb)

Destroys this CA permanently by deleting its checkpointed state.

Destroyed CAs cannot be resumed and input/output queues are immediately discarded.

Parameters:
Name Type Attributes Description
data Object <optional>

An optional hint on how to perform the shutdown.

cb cbType

A callback function to continue after clean-up.

Source:

__ca_pulse__(cb)

Enables autonomous computation by processing pulse messages that CAF periodically sends to all CAs.

Parameters:
Name Type Description
cb cbType

A callback to continue after pulse.

Source:

__ca_upgrade__(newVersion, cb)

Versions the checkpointed state of a resumed CA so that is consistent with its expected version props.$.stateVersion, set in file ca.json.

A resumed CA always calls this function once, just before it starts processing messages.

The default policy is to use semantic versioning, and automatically upgrade the version if newVersion satifies ^oldVersion (first non-zero number cannot change, but the next ones can). Otherwise, we return an error in the callback.

It is expected that applications will override this function to upgrade between non-compatible versions.

Parameters:
Name Type Description
newVersion string

The new version label after upgrading the state.

cb cbType

A callback to continue after versioning the state.

Source:

__external_ca_multi__(multiArgs, cb)

A method that aggregates multiple method invocations in a single message. The failure of one of them will abort changes for all of them, as if they were all executed in one transaction.

SECURITY WARNING: Granting access to this method means that ANY method of this CA can be called

type of invocationType is {method: string, meta : Array., args: Array.<caf.json>}

Parameters:
Name Type Description
multiArgs Array.<invocationType>

An array

cb cbType

A callback to return the results of the last method.

Source:

__external_ca_touch__(cb)

A dummy method that ensures a CA is active.

The 'Touch' method should not have any side-effects and is present in all CAs.

It also returns in the callback metadata of the methods (an object with keys the method names, and values and array with the argument names)

Touch makes latency of the first command in a session more predictable. It can also guarantee that pulse methods are regularly invoked after a failure, even without active clients.

Parameters:
Name Type Description
cb cbType

A callback to continue after 'touch'. It returns an object with CA methods metadata, where a key is a method name and a value is an array with arguments names.

Source: