nvflare.app_common.tie.connector module¶
- class Connector[source]¶
Bases:
ABC
,FLComponent
Connectors are used to integrate FLARE with an Applet (Server or Client) in run time. Each type of applet requires an appropriate connector to integrate it with FLARE’s Controller or Executor. The Connector class defines commonly required methods for all Connector implementations.
Constructor of Connector
- abstract configure(config: dict, fl_ctx: FLContext)[source]¶
Called by Controller/Executor to configure the connector. If any error occurs, this method should raise an exception.
- Parameters:
config – config data
fl_ctx – the FL context
Returns: None
- initialize(fl_ctx: FLContext)[source]¶
Called by the Controller/Executor to initialize the connector.
- Parameters:
fl_ctx – the FL context
Returns: None
- is_applet_stopped() -> (<class 'bool'>, <class 'int'>)[source]¶
Check whether the applet is already stopped
Returns: a tuple of (whether the applet is stopped, exit code)
- monitor(fl_ctx: FLContext, connector_stopped_cb)[source]¶
Called by Controller/Executor to monitor the health of the connector.
The monitor periodically checks the abort signal. Once set, it calls the connector’s stop() method to stop the running of the app.
The monitor also periodically checks whether the connector is already stopped (by calling the is_stopped method). If the connector is stopped, the monitor will call the specified connector_stopped_cb.
- Parameters:
fl_ctx – FL context
connector_stopped_cb – the callback function to be called when the connector is stopped.
Returns: None
- process_app_request(op: str, req: Shareable, fl_ctx: FLContext, abort_signal: Signal) Shareable [source]¶
Called by Controller/Executor to process a request from an applet on another site.
- Parameters:
op – the op code of the request
req – the request to be sent
fl_ctx – FL context
abort_signal – abort signal that could be triggered during the request processing
Returns: processing result as Shareable object
- send_request(target: str | None, op: str, request: Shareable, per_msg_timeout: float, tx_timeout: float, fl_ctx: FLContext | None) Shareable [source]¶
Send app request to the specified target via FLARE ReliableMessage.
- Parameters:
target – the destination of the request. If not specified, default to server.
op – the operation
request – operation data
per_msg_timeout – per-message timeout
tx_timeout – transaction timeout
fl_ctx – FL context. If not provided, this method will create a new FL context.
- Returns:
operation result
- set_abort_signal(abort_signal: Signal)[source]¶
Called by Controller/Executor to set the abort_signal.
The abort_signal is assigned by FLARE Controller/Executor. It is used by the Controller/Executor to tell the connector that the job has been aborted.
- Parameters:
abort_signal – the abort signal assigned by the caller.
Returns: None
- set_applet(applet: Applet)[source]¶
Set the applet that will be used to run app processing logic. Note that the connector is only responsible for starting the applet appropriately (in a separate thread or in a separate process).
- Parameters:
applet – the applet to be set
Returns: None
- abstract start(fl_ctx: FLContext)[source]¶
Called by Controller/Executor to start the connector. If any error occurs, this method should raise an exception.
- Parameters:
fl_ctx – the FL context.
Returns: None
- start_applet(app_ctx: dict, fl_ctx: FLContext)[source]¶
Start the applet set to the connector.
- Parameters:
app_ctx – the contextual info for running the applet
fl_ctx – FL context
Returns: None