Driver#
- class Driver[源代码]#
基类:
ABC
Abstract base Driver class for the Driver API.
Methods
create_message
(content, message_type, ...[, ttl])Create a new message with specified parameters.
Get node IDs.
pull_messages
(message_ids)Pull messages based on message IDs.
push_messages
(messages)Push messages to specified node IDs.
send_and_receive
(messages, *[, timeout])Push messages to specified node IDs and pull the reply messages.
- abstract create_message(content: RecordSet, message_type: str, dst_node_id: int, group_id: str, ttl: float | None = None) Message [源代码]#
Create a new message with specified parameters.
This method constructs a new Message with given content and metadata. The run_id and src_node_id will be set automatically.
- 参数:
content (RecordSet) -- The content for the new message. This holds records that are to be sent to the destination node.
message_type (str) -- The type of the message, defining the action to be executed on the receiving end.
dst_node_id (int) -- The ID of the destination node to which the message is being sent.
group_id (str) -- The ID of the group to which this message is associated. In some settings, this is used as the FL round.
ttl (Optional[float] (default: None)) -- Time-to-live for the round trip of this message, i.e., the time from sending this message to receiving a reply. It specifies in seconds the duration for which the message and its potential reply are considered valid. If unset, the default TTL (i.e., common.DEFAULT_TTL) will be used.
- 返回:
message -- A new Message instance with the specified content and metadata.
- 返回类型:
- abstract pull_messages(message_ids: Iterable[str]) Iterable[Message] [源代码]#
Pull messages based on message IDs.
This method is used to collect messages from the SuperLink that correspond to a set of given message IDs.
- 参数:
message_ids (Iterable[str]) -- An iterable of message IDs for which reply messages are to be retrieved.
- 返回:
messages -- An iterable of messages received.
- 返回类型:
Iterable[Message]
- abstract push_messages(messages: Iterable[Message]) Iterable[str] [源代码]#
Push messages to specified node IDs.
This method takes an iterable of messages and sends each message to the node specified in dst_node_id.
- 参数:
messages (Iterable[Message]) -- An iterable of messages to be sent.
- 返回:
message_ids -- An iterable of IDs for the messages that were sent, which can be used to pull replies.
- 返回类型:
Iterable[str]
- abstract send_and_receive(messages: Iterable[Message], *, timeout: float | None = None) Iterable[Message] [源代码]#
Push messages to specified node IDs and pull the reply messages.
This method sends a list of messages to their destination node IDs and then waits for the replies. It continues to pull replies until either all replies are received or the specified timeout duration is exceeded.
- 参数:
messages (Iterable[Message]) -- An iterable of messages to be sent.
timeout (Optional[float] (default: None)) -- The timeout duration in seconds. If specified, the method will wait for replies for this duration. If None, there is no time limit and the method will wait until replies for all messages are received.
- 返回:
replies -- An iterable of reply messages received from the SuperLink.
- 返回类型:
Iterable[Message]
备注
This method uses push_messages to send the messages and pull_messages to collect the replies. If timeout is set, the method may not return replies for all sent messages. A message remains valid until its TTL, which is not affected by timeout.