# 1.2. Connectors¶

This section documents the capabilities of the connector objects, with which the decorated methods are replaced. Instances of the following classes replace the decorated methods, so they are enhanced with the functionality of a connector. These classes are not instantiated by code outside the Connectors package.

## 1.2.1. Connectors for setter methods¶

class connectors.connectors.SingleInputConnector(instance, method, observers, laziness, parallelization, executor)

A connector-class that replaces setter methods, so they can be used to connect different objects in a processing chain.

Parameters: instance – the instance of which the method is replaced by this connector method – the unbound method, that is replaced by this connector observers – the names of output methods that are affected by passing a value to this connector laziness – a flag from the connectors.Laziness enum. See the set_laziness() method for details parallelization – a flag from the connectors.Parallelization enum. See the set_parallelization() method for details executor – an Executor instance, that can be created with the connectors.executor() function. See the set_executor() method for details
connect(connector)

Connects this InputConnector to an output.

Parameters: connector – the Connector instance to which this connector shall be connected the instance of which this InputConnector has replaced a method
disconnect(connector)

Disconnects this InputConnector from an output, to which is has been connected.

Parameters: connector – a Connector instance from which this connector shall be disconnected the instance of which this Connector has replaced a method
set_executor(executor)

Sets the executor, which handles the computations, when the data is retrieved through this connector. An executor can be created with the connectors.executor() function. It manages the order and the parallelization of the computations, when updating the data in a processing chain. If multiple connectors in a processing chain need to be computed, the executor of the connector, which started the computations, is used for all computations.

Parameters: executor – an Executor instance, that can be created with the connectors.executor() function
set_laziness(laziness)

Configures the lazy execution of the connector. Normally the connectors are executed lazily, which means, that any computation is only started, when the result of a processing chain is requested. For certain use cases it is necessary to disable this lazy execution, though, so that the values are updated immediately as soon as new data is available. There are different behaviors for the (non) lazy execution, which are described in the connectors.Laziness enum.

Parameters: laziness – a flag from the connectors.Laziness enum
set_parallelization(parallelization)

Specifies, if and how the execution of this connector can be parallelized. The choices are no parallelization, the execution in a separate thread and the execution in a separate process. This method specifies a hint, which level of parallelization is possible with the connector. If the executor of the connector, through which the computation is started, does not support the specified level, the next simpler one will be chosen. E.g. if a connector can be parallelized in a separate process, but the executor only allows threads or sequential execution, the connector will be executed in a separate thread.

Parameters: parallelization – a flag from the connectors.Parallelization enum
class connectors.connectors.MultiInputConnector(instance, method, remove_method, replace_method, observers, laziness, parallelization, executor)

A connector-class that replaces special setter methods, that allow to pass multiple values, so they can be used to connect different objects in a processing chain.

Parameters: instance – the instance of which the method is replaced by this connector method – the unbound method, that is replaced by this connector remove_method – an unbound method, that is used to remove data, that has been added through this connector replace_method – an unbound method, that is used to replace data, that has been added through this connector observers – the names of output methods that are affected by passing a value to this connector laziness – a flag from the connectors.Laziness enum. See the set_laziness() method for details parallelization – a flag from the connectors.Parallelization enum. See the set_parallelization() method for details executor – an Executor instance, that can be created with the connectors.executor() function. See the set_executor() method for details
__getitem__(key)

Allows to use a multi-input connector as multiple single-input connectors.

The key, under which a virtual single-input connector is accessed, shall also be returned the data ID, under which the result of the connected output is stored.

Parameters: key – a key for accessing a particular virtual single-input connector a MultiInputItem, which enhances the decorated method with the functionality of the virtual single-input connector
connect(connector)

Connects this InputConnector to an output.

Parameters: connector – the Connector instance to which this connector shall be connected the instance of which this InputConnector has replaced a method
disconnect(connector)

Disconnects this InputConnector from an output, to which is has been connected.

Parameters: connector – a Connector instance from which this connector shall be disconnected the instance of which this Connector has replaced a method
set_executor(executor)

Sets the executor, which handles the computations, when the data is retrieved through this connector. An executor can be created with the connectors.executor() function. It manages the order and the parallelization of the computations, when updating the data in a processing chain. If multiple connectors in a processing chain need to be computed, the executor of the connector, which started the computations, is used for all computations.

Parameters: executor – an Executor instance, that can be created with the connectors.executor() function
set_laziness(laziness)

Configures the lazy execution of the connector. Normally the connectors are executed lazily, which means, that any computation is only started, when the result of a processing chain is requested. For certain use cases it is necessary to disable this lazy execution, though, so that the values are updated immediately as soon as new data is available. There are different behaviors for the (non) lazy execution, which are described in the connectors.Laziness enum.

Parameters: laziness – a flag from the connectors.Laziness enum
set_parallelization(parallelization)

Specifies, if and how the execution of this connector can be parallelized. The choices are no parallelization, the execution in a separate thread and the execution in a separate process. This method specifies a hint, which level of parallelization is possible with the connector. If the executor of the connector, through which the computation is started, does not support the specified level, the next simpler one will be chosen. E.g. if a connector can be parallelized in a separate process, but the executor only allows threads or sequential execution, the connector will be executed in a separate thread.

Parameters: parallelization – a flag from the connectors.Parallelization enum

## 1.2.2. Connectors for getter methods¶

class connectors.connectors.OutputConnector(instance, method, caching, parallelization, executor)

A connector-class that replaces getter methods, so they can be used to connect different objects.

Parameters: instance – the instance of which the method is replaced by this connector method – the unbound method that is replaced by this connector caching – True, if caching shall be enabled, False otherwise. See the set_caching() method for details parallelization – a flag from the connectors.Parallelization enum. See the set_parallelization() method for details executor – an Executor instance, that can be created with the connectors.executor() function. See the set_executor() method for details
connect(connector)

A method for connecting this output connector to an input connector.

Parameters: connector – the input connector to which this connector shall be connected the instance of which this OutputConnector has replaced a method
disconnect(connector)

A method for disconnecting this output connector from an input connector, to which it is currently connected.

Parameters: connector – the input connector from which this connector shall be disconnected the instance of which this OutputConnector has replaced a method
set_caching(caching)

Specifies, if the result value of this output connector shall be cached. If caching is enabled and the result value is retrieved (e.g. through a connection or by calling the connector), the cached value is returned and the replaced getter method is not called unless the result value has to be re-computed, because an observed setter method has changed a parameter for the computation. In this case, the getter method is only called once, independent of the number of connections through which the result value has to be passed.

Parameters: caching – True, if caching shall be enabled, False otherwise
set_executor(executor)

Sets the executor, which handles the computations, when the data is retrieved through this connector. An executor can be created with the connectors.executor() function. It manages the order and the parallelization of the computations, when updating the data in a processing chain. If multiple connectors in a processing chain need to be computed, the executor of the connector, which started the computations, is used for all computations.

Parameters: executor – an Executor instance, that can be created with the connectors.executor() function
set_parallelization(parallelization)

Specifies, if and how the execution of this connector can be parallelized. The choices are no parallelization, the execution in a separate thread and the execution in a separate process. This method specifies a hint, which level of parallelization is possible with the connector. If the executor of the connector, through which the computation is started, does not support the specified level, the next simpler one will be chosen. E.g. if a connector can be parallelized in a separate process, but the executor only allows threads or sequential execution, the connector will be executed in a separate thread.

Parameters: parallelization – a flag from the connectors.Parallelization enum
class connectors.connectors.MultiOutputConnector(instance, method, caching, parallelization, executor, keys)

A connector-class that replaces getter methods, which accept one parameter, so they can be used as a multi-output connector, which can be connected to different objects.

Multi-output connectors can either be used to route a dynamic number of values to a multi-input connector. Or the argument for the []-operator can be used to parameterize the getter method.

Parameters: instance – the instance of which the method is replaced by this connector method – the unbound method that is replaced by this connector caching – True, if caching shall be enabled, False otherwise. See the set_caching() method for details parallelization – a flag from the connectors.Parallelization enum. See the set_parallelization() method for details executor – an Executor instance, that can be created with the connectors.executor() function. See the set_executor() method for details keys – an unbound method, that returns the keys for which this multi-output connector shall compute values, when it is connected to a multi-input connector
__getitem__(key)

Allows to use a multi-output connector as multiple single-output connectors.

Parameters: key – a key for accessing a particular virtual single-output connector a connectors._common._multioutput_item.MultiOutputItem, which enhances the decorated method with the functionality of the virtual single-output connector
connect(connector)

A method for connecting this output connector to an input connector. This is only allowed with multi-input connectors. In order to establish a connection to a single-input connector, use the [] operator to specify, which value shall be passed through the connection.

Parameters: connector – the input connector to which this connector shall be connected the instance of which this OutputConnector has replaced a method
disconnect(connector)

A method for disconnecting this output connector from an input connector, to which it is currently connected.

Parameters: connector – the input connector from which this connector shall be disconnected the instance of which this OutputConnector has replaced a method
set_caching(caching)

Specifies, if the result value of this output connector shall be cached. If caching is enabled and the result value is retrieved (e.g. through a connection or by calling the connector), the cached value is returned and the replaced getter method is not called unless the result value has to be re-computed, because an observed setter method has changed a parameter for the computation. In this case, the getter method is only called once, independent of the number of connections through which the result value has to be passed.

Parameters: caching – True, if caching shall be enabled, False otherwise
set_executor(executor)

Sets the executor, which handles the computations, when the data is retrieved through this connector. An executor can be created with the connectors.executor() function. It manages the order and the parallelization of the computations, when updating the data in a processing chain. If multiple connectors in a processing chain need to be computed, the executor of the connector, which started the computations, is used for all computations.

Parameters: executor – an Executor instance, that can be created with the connectors.executor() function
set_parallelization(parallelization)

Specifies, if and how the execution of this connector can be parallelized. The choices are no parallelization, the execution in a separate thread and the execution in a separate process. This method specifies a hint, which level of parallelization is possible with the connector. If the executor of the connector, through which the computation is started, does not support the specified level, the next simpler one will be chosen. E.g. if a connector can be parallelized in a separate process, but the executor only allows threads or sequential execution, the connector will be executed in a separate thread.

Parameters: parallelization – a flag from the connectors.Parallelization enum