nopasaran.controllers.protocol.WorkerProtocol¶
- class nopasaran.controllers.protocol.WorkerProtocol¶
Bases:
ProtocolBase protocol for worker communication.
This protocol handles the communication between workers and manages their status.
- __init__()¶
Methods
__init__()connectionLost(reason)Handle the connection loss.
Called when a connection is made.
dataReceived(encoded_json_data)Handle received data.
Initiate the disconnection process.
Get the current state as a JSON-encoded string.
Return a prefix matching the class name, to identify log messages related to this protocol instance.
makeConnection(transport)Make a connection to a transport and a server.
send_encoded_data(data)Send encoded data through the transport.
send_sync(content)Send a sync message to the remote endpoint.
Attributes
connectedfactoryis_activelocal_statusqueueremote_statustransport- connectionLost(reason)¶
Handle the connection loss.
This method is called when the connection is lost with the remote endpoint.
- Args:
reason: The reason for the connection loss.
- connectionMade()¶
Called when a connection is made.
This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.
- dataReceived(encoded_json_data)¶
Handle received data.
This method is called when data is received from the remote endpoint.
- Args:
encoded_json_data (bytes): The received data as bytes.
- disconnecting()¶
Initiate the disconnection process.
This method sets the local status to DISCONNECTING and sends the current state to the remote endpoint.
- get_current_state_json()¶
Get the current state as a JSON-encoded string.
- Returns:
bytes: The JSON-encoded current state.
- logPrefix()¶
Return a prefix matching the class name, to identify log messages related to this protocol instance.
- makeConnection(transport)¶
Make a connection to a transport and a server.
This sets the ‘transport’ attribute of this Protocol, and calls the connectionMade() callback.
- send_encoded_data(data)¶
Send encoded data through the transport.
This method encodes the provided data to JSON, base64, and sends it.
- Args:
data (dict): The data to encode and send.
- send_sync(content)¶
Send a sync message to the remote endpoint.
This method sends a sync message with the specified content to the remote endpoint.
- Args:
content: The content of the sync message.