pub struct PublishStateMachine {
state: PublishState,
}Expand description
Pure state machine for a subscription a PUBLISH opened. Transitions: Idle -> Publishing -> Active -> Done.
The two ends of the flow are the two halves of Section 4.1’s sentence: “A subscriber MUST send exactly one PUBLISH_OK or PUBLISH_ERROR in response to a PUBLISH”, and “the subscription can be … terminated by the subscriber using UNSUBSCRIBE, or terminated by the publisher using SUBSCRIBE_DONE”. Each event has a transition of its own even where two of them land in the same state, so that a refusal names the event that was refused, and so that each direction of the flow names its own half of it.
Fields§
§state: PublishStateImplementations§
Source§impl PublishStateMachine
impl PublishStateMachine
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new state machine in the PublishState::Idle state.
Sourcepub fn state(&self) -> PublishState
pub fn state(&self) -> PublishState
Returns the current state of the subscription.
fn step( &mut self, from: PublishState, to: PublishState, event: &str, ) -> Result<(), PublishError>
Sourcepub fn on_publish_received(&mut self) -> Result<(), PublishError>
pub fn on_publish_received(&mut self) -> Result<(), PublishError>
Idle -> Publishing (PUBLISH received from the peer).
Sourcepub fn on_publish_ok_sent(&mut self) -> Result<(), PublishError>
pub fn on_publish_ok_sent(&mut self) -> Result<(), PublishError>
Publishing -> Active (this endpoint answered PUBLISH_OK).
Sourcepub fn on_publish_error_sent(&mut self) -> Result<(), PublishError>
pub fn on_publish_error_sent(&mut self) -> Result<(), PublishError>
Publishing -> Done (this endpoint answered PUBLISH_ERROR).
Sourcepub fn on_unsubscribe_sent(&mut self) -> Result<(), PublishError>
pub fn on_unsubscribe_sent(&mut self) -> Result<(), PublishError>
Active -> Done (this endpoint sent UNSUBSCRIBE).
Only from Active: the draft gives the subscriber UNSUBSCRIBE for a subscription that is established, and a PUBLISH it has not answered yet is refused with PUBLISH_ERROR instead.
Sourcepub fn on_subscribe_done_received(&mut self) -> Result<(), PublishError>
pub fn on_subscribe_done_received(&mut self) -> Result<(), PublishError>
Active -> Done (the publishing peer sent SUBSCRIBE_DONE).
Sourcepub fn on_publish_sent(&mut self) -> Result<(), PublishError>
pub fn on_publish_sent(&mut self) -> Result<(), PublishError>
Idle -> Publishing (PUBLISH sent to the peer).
The mirror of Self::on_publish_received, and the same step: Section
4.1 opens with “A subscription can be initiated by either a publisher
or a subscriber”, so an offer looks the same from both ends and only
the event name says which end made it.
Sourcepub fn on_publish_ok(&mut self) -> Result<(), PublishError>
pub fn on_publish_ok(&mut self) -> Result<(), PublishError>
Publishing -> Active (the subscribing peer answered PUBLISH_OK).
Sourcepub fn on_publish_error(&mut self) -> Result<(), PublishError>
pub fn on_publish_error(&mut self) -> Result<(), PublishError>
Publishing -> Done (the subscribing peer answered PUBLISH_ERROR).
The offer is over rather than pending. Section 4.1: “Objects MUST NOT be sent for requests that end with an error.”
Sourcepub fn on_subscribe_done_sent(&mut self) -> Result<(), PublishError>
pub fn on_subscribe_done_sent(&mut self) -> Result<(), PublishError>
Active -> Done (this endpoint, as the publisher, sent SUBSCRIBE_DONE).
Sourcepub fn on_unsubscribe_received(&mut self) -> Result<(), PublishError>
pub fn on_unsubscribe_received(&mut self) -> Result<(), PublishError>
Active -> Done (the subscribing peer sent UNSUBSCRIBE).
The mirror of Self::on_unsubscribe_sent and the same step, on a
subscription this endpoint opened rather than one it took. Section 8.11
gives the message to the subscriber alone, so which end sends it
follows from which end made the offer.