This is the code markup for the above diagram in Mermaid format.
sequenceDiagram participant server participant client participant SAG client->>server: ReceiveMsgs client->>server: ReceiveBatons server->>client: SendMsg{1} server->>client: SendMsg{2} client->>client: processMsg{1} server->>client: SendMsg{3} server->>client: SendMsg{4} client->>client: processMsg{2} SAG->>+server: SuspendStarted Note over server: Baton sent for last msg? - No server->>+SAG: AcquireWakeLease SAG->>-server: zx::EventPair SAG->>server: Resume server->>-SAG: <ACK>{SuspendStarted} server->>SAG: <ACK>{Resume} server->>client: SendBaton{idx: 4} client->>client: processMsg{3} client->>client: processMsg{4} client->>client: dropBaton{4} SAG->>+server: SuspendStarted Note over server: Baton send for last msg? - Yes server->>-SAG: Ack{SuspendStarted} SAG->>Fuchsia Suspend HAL: RequestSuspend
To facilitate optimistic lease management there are some helper classes for servers and clients which are in the lib subdirectory. The current implementations are based on some assumptions about how servers and clients communicate as well as what signal prompts state synchronization between the two. This state synchronization referred to, with a nod to cache management, as a “flush”. In the future the library will likely grow to support more client-server scenarios.
Servers probably want to use things from sequence_server.rs such as SequenceServer
. The SequenceServer
is effectively a builder for a MessageSendTracker
. Servers should follow these steps:
SequenceServer
.SequenceServer::manage()
.MessageSendTracker
returned from (2) when a message is sent.MessageSendTracker::set_requester
when a new baton request arrives.The server does not need to mint batons or do anything related to when suspends and resumes happen, that is handled automatically.
Clients should use SequenceClient
to manage baton-related communication with the server. The client should call process_message
to indicate to SequenceClient
when the client processed a message. The client does not need to do anything related to handling batons, SequenceClient
manages the hanging-GET requests for the batons and holding on to the batons until the client tells SequenceClient
it saw the message. process_message
returns a baton if the message processed has an associated baton, but the client does not need to retain the baton. Returning the baton is mostly useful if a client wants to pass the baton on to a client it may have.