Skip to content

hermes.base.nodes

The module is responsible for wrapping common functionality of Nodes. It implements the FSM and defines unified state transitions for all the Nodes.

node_interface - base interface for Node function.

node - abstract FSM-based Node with common state transition logic.

node_states - FSM states of the Node.

node_interface

Classes:

Name Description
NodeInterface

Interface for the Node components.

NodeInterface

Bases: ABC

Interface for the Node components.

_is_done abstractmethod property

_is_done: bool

Read-only property identifying if the Node completed operation.

Returns:

Name Type Description
bool bool

Whether the Node completed its function.

_activate_data_poller abstractmethod

_activate_data_poller() -> None

Start listening for new data from other Nodes.

_activate_kill_poller abstractmethod

_activate_kill_poller() -> None

Start listening for the KILL signal on the special PUB/SUB socket that coordinates program termination.

_deactivate_kill_poller abstractmethod

_deactivate_kill_poller() -> None

Stop listening for the KILL signal.

_get_sync_socket abstractmethod

_get_sync_socket() -> SyncSocket

Get reference to the socket used for synchronization of the Node to its master Broker.

Returns:

Type Description
SyncSocket

zmq.SyncSocket: ZeroMQ socket of the Node connected to the local master Broker.

_initialize abstractmethod

_initialize() -> None

Node-specific initialization procedure.

Pre-run setup of the backend specific to the Node implementaiton. Generic setup should be run first.

_log_source_tag abstractmethod classmethod

_log_source_tag() -> str

Read-only property uniquely identifying the Node.

Returns:

Name Type Description
str str

Unique key identifying the Node in the data exchange.

_on_poll abstractmethod

_on_poll(poll_res: tuple[list[SyncSocket], list[int]]) -> None

Callback to perform some logic everytime some data transactions are received by the Poller.

Generic entry-point for all types of Nodes, based on their active Poller settings. NOTE: if Node in JoinState, kill socket is no longer in the Poller and only higher-level logic is triggered.

Parameters:

Name Type Description Default
poll_res
tuple[list[SyncSocket], list[int]]

Reference to the complete captured result of listening by the Poller.

required

_on_sync_complete abstractmethod

_on_sync_complete() -> None

Callback to perform some logic after synchronization of Nodes is completed and indicated by the Broker.

_poll abstractmethod

_poll() -> tuple[list[SyncSocket], list[int]]

Block for new ZeroMQ data to collect at the Poller.

Listens for events when new data is received from or when new data can be written to sockets, based on the active Poller settings of the Node implementation.

Returns:

Type Description
tuple[list[SyncSocket], list[int]]

tuple[list[zmq.SyncSocket], list[int]]: Result of listening on the sockets registered by the Poller.

_send_kill_to_broker abstractmethod

_send_kill_to_broker() -> None

Send a slave KILL signal to the local Broker in case program termination by the slave Node is recorded.

_set_state abstractmethod

_set_state(state) -> None

User-defined logic for FSM state transition.

Parameters:

Name Type Description Default
state
Any

New state to transition to.

required

_trigger_stop abstractmethod

_trigger_stop() -> None

Trigger to the Node's internal procedures and background threads to gracefully wrap-up.

Producer: stops sampling data, continue sending already captured until none is left, with last message labeled 'END'. Consumer: continues listening to data until each of subscribed Producers sent the last message. Pipeline: continues listening to data to produce results until each data sources sent the last message, and then labels the last message with 'END'.

node

Classes:

Name Description
Node

Node

Bases: NodeInterface

Methods:

Name Description
__call__

Node objects are callable to start the FSM as entry-point.

__init__

Constructor of the Node parent class.

__call__

__call__()

Node objects are callable to start the FSM as entry-point.

__init__

__init__(
    host_ip: str = DNS_LOCALHOST,
    port_sync: str = PORT_SYNC_HOST,
    port_killsig: str = PORT_KILL,
) -> None

Parameters:

Name Type Description Default
host_ip
str

IP address of the local master Broker. Defaults to DNS_LOCALHOST.

DNS_LOCALHOST
port_sync
str

Local port to listen to for local master Broker's startup coordination. Defaults to PORT_SYNC_HOST.

PORT_SYNC_HOST
port_killsig
str

Local port to listen to for local master Broker's termination signal. Defaults to PORT_KILL.

PORT_KILL

_cleanup abstractmethod

_cleanup()

Release of generic Node resources, must be done after releasing higher-level resources.

_log_source_tag abstractmethod classmethod

_log_source_tag() -> str

Read-only property uniquely identifying the Node.

Returns:

Name Type Description
str str

Unique key identifying the Node in the data exchange.

_on_sync_complete abstractmethod

_on_sync_complete() -> None

Callback to perform some logic after synchronization of Nodes is completed and indicated by the Broker.

node_states

Classes:

Name Description
AbstractNodeState

Abstract class for the Node FSM.

JoinState

Gracefully exit state of the Node to coordinate closure to the local master Broker.

KillState

Termination state of the Node that gracefully processes the external KILL signal from the local master Broker.

RunningState

Running state of the Node with the steady-state main loop listening for data and triggering user-provided callbacks on it.

StartState

Starting state of the Node that initializes corresponding internal logic of the specified Node.

SyncState

Synchronization state of the Node to coordinate readiness to start working to the local master Broker.

AbstractNodeState

Bases: StateInterface

Abstract class for the Node FSM.

Can be externally triggered into the KILL state from any child State class.

Methods:

Name Description
__init__

Constructor of the AbstractNodeState parent class.

run

Run the logic of the currently selected state.

__init__

Parameters:

Name Type Description Default
context
NodeInterface

Reference to the Node object.

required

run abstractmethod

run() -> None

Run the logic of the currently selected state.

JoinState

Bases: AbstractNodeState

Gracefully exit state of the Node to coordinate closure to the local master Broker.

Methods:

Name Description
__init__

Constructor of the AbstractNodeState parent class.

__init__

Parameters:

Name Type Description Default
context
NodeInterface

Reference to the Node object.

required

KillState

Bases: AbstractNodeState

Termination state of the Node that gracefully processes the external KILL signal from the local master Broker.

Methods:

Name Description
__init__

Constructor of the AbstractNodeState parent class.

__init__

Parameters:

Name Type Description Default
context
NodeInterface

Reference to the Node object.

required

RunningState

Bases: AbstractNodeState

Running state of the Node with the steady-state main loop listening for data and triggering user-provided callbacks on it.

StartState

Bases: AbstractNodeState

Starting state of the Node that initializes corresponding internal logic of the specified Node.

Activates data poller in case Node goes into KillState.

Methods:

Name Description
__init__

Constructor of the AbstractNodeState parent class.

__init__

Parameters:

Name Type Description Default
context
NodeInterface

Reference to the Node object.

required

SyncState

Bases: AbstractNodeState

Synchronization state of the Node to coordinate readiness to start working to the local master Broker.