caf_components/gen_dynamic_container

Generic dynamic container component that encapsulates the life-cycle of other components.

Container membership changes at run-time.

We use a supervisor strategy similar to Erlang/OTP one-for-one: components are assumed to be independent, and if one of them dies we just restart that component. Order of component shutdown or start is arbitrary.

The child's spec.env can contain a boolean attribute __ca_temporary__ that disables component restart. This is useful when we rely on external mechanisms to restart components, as is the case with CAs.

The following required properties specify recovery behavior for non-temporary components:

    { maxRetries: number, retryDelay: number}

where maxRetries is the number of attempts before giving up, and retryDelay is the delay in msec between attempts.

Source:

Extends

Members

$ :Object.<string, Object>

Source:

A context to register children. We can pass an existing children context in $.$

Type:
  • Object.<string, Object>

__ca_isDynamicContainer__ :boolean

Source:

Run-time type information.

Type:
  • boolean

Methods

(static) create($, spec) → {Object}

Source:

Helper constructor method for a dynamic container component.

Description of types in file types.js.

Parameters:
Name Type Description
$ ctxType

A context containing references to other components.

spec specType

Configuration data for this component.

Throws:

If inputs are invalid.

Type
Error
Returns:

A new generic component.

Type
Object

__ca_allChildren__() → {Array.<string>}

Source:

Returns an array with the names of all the children that are currently active.

Returns:

The names of all active children.

Type
Array.<string>

__ca_deleteChild__(dataopt, childName, cb)

Source:

Deletes and shutdowns a child component.

This is an idempotent operation.

Parameters:
Name Type Attributes Description
data Object <optional>

An optional hint on how to delete the child.

childName string

A name for the child.

cb cbType

A callback to return an error if a child still exists and delete failed.

__ca_getChildSpec__(name) → {specType}

Source:

Returns the spec for a created child.

Parameters:
Name Type Description
name string

The name of the child component.

Returns:

The spec of a running child.

Type
specType

__ca_instanceChild__(dataopt, childSpec, cb)

Source:

Adds a new child component if it was not already created.

We avoid race conditions by using a queue to serialize child creation.

There is no guarantee that the returned child used the provided description, it could have already been created with a different one. Use __ca_deleteChild__ first to force a description.

Parameters:
Name Type Attributes Description
data Object <optional>

An optional hint on how to add the child.

childSpec Object

A child description.

cb cbType

A callback to return an error or the new (or existing) child.