Chain

class ioiocore.chain.Chain(**kwargs)[source]

Bases: ProcessingElement

Base class for all chain types.

A chain is a processing element that contains a sequence of internal nodes connected together. Chains expose ports from their boundary nodes (first and/or last) to the outside world.

Subclasses: - IChain: Input chain (exposes input ports from first node) - OChain: Output chain (exposes output ports from last node) - IOChain: Input/Output chain (exposes both)

Inheriting classes must implement: - create_internal_nodes(): Returns the list of internal nodes

class Configuration(name=None, **kwargs)[source]

Bases: Configuration

Configuration class for Chain.

Parameters:

name (str)

class Keys[source]

Bases: Keys

Keys for the Chain configuration.

INTERNALS_ARE_DERIVED: bool = True

Whether the internal nodes are derived from this chain’s configuration rather than being state of their own.

When True – the default – serialize() omits them and a loader rebuilds them with create_internal_nodes(). That is the honest description of a chain whose composition is a function of its configuration, and it is the only arrangement that lets the loading process decide the composition.

Why that matters: a chain may legitimately build itself differently depending on where it is running. A consuming package that splits one pipeline across two hosts builds an acquisition node on the host that has the device and a network bridge on the host that does not. Embedding the internals defeats it exactly: the receiving side restores the sender’s composition and rebuilds the sender’s half, so the two ends are copies rather than complements.

Set it False on a chain whose internals cannot be rebuilt from configuration alone – one whose create_internal_nodes is not a function of config. Then the internals travel, and the loading process’s own view is overridden, which is the trade.

config: Configuration
create_implementation(**kwargs)[source]

Create the chain implementation with internal nodes.

abstractmethod create_internal_nodes()[source]

Create and return the list of internal nodes.

Returns:

List of internal nodes forming the processing chain.

Return type:

List[Node]

property internal_nodes: List[Node]

Get the list of internal nodes.

serialize()[source]

Serialize the chain.

The internal nodes are included only when this chain declares that they are not derived from its configuration – see INTERNALS_ARE_DERIVED. Omitting them is what lets the loading process build the composition it needs rather than replaying the writer’s.

Returns:

The serialized chain.

Return type:

dict

start()[source]

Start the chain and all internal nodes.

All or nothing: if an internal node raises, the nodes that had started are stopped again, the chain stays stopped, and the exception propagates. Starting a running chain does nothing.

stop()[source]

Stop the chain and all internal nodes.