nvflare.fuel.data_event.data_bus module¶
- class DataBus[source]¶
Bases:
EventPubSub
Singleton class for a simple data bus implementation.
This class allows components to subscribe to topics, publish messages to topics, and store/retrieve messages associated with specific keys and topics.
Create a new instance of the DataBus class. This method ensures that only one instance of the class is created (singleton pattern). The databus
- get_data(key: Any) Any [source]¶
Retrieve a stored data associated with a key and topic.
- Parameters:
key (Any) – The key associated with the stored message.
- Returns:
The stored datum if found, or None if not found.
- Return type:
Any
- publish(topics: List[str], datum: Any) None [source]¶
Publish a data to one or more topics, notifying all subscribed callbacks.
- Parameters:
topics (List[str]) – A list of topics to publish the data to.
datum (Any) – The data to be published to the specified topics.
- put_data(key: Any, datum: Any) None [source]¶
Store a data associated with a key and topic.
- Parameters:
key (Any) – The key to associate with the stored message.
datum (Any) – The message to be stored.
- subscribe(topics: List[str], callback: Callable[[str, Any, DataBus], None]) None [source]¶
Subscribe a callback function to one or more topics.
- Parameters:
topics (List[str]) – A list of topics to subscribe to.
callback (Callable) – The callback function to be called when messages are published to the subscribed topics.