microsoft-healthcare-madison / argonaut-subscription-client-ui

Client UI for testing the Argonaut Subscription changes.
MIT License
1 stars 2 forks source link

Comm status card #17

Open madaster97 opened 3 years ago

madaster97 commented 3 years ago

Overview

Created a state machine for handling different types of events as a client (events as in receiving SubscriptionStatus resources).

Under the Playground scenario, the panel Manually trigger communication events contains a UI for raising events to the state machine.

Defining State

Subscription clients (subscribers) are primarily concerned with the following:

The easiest way to encapsulate this was using 4 properties:

  1. A type that says whether the client's connection to the server is broken or not
  2. lastReceived - The last server event the client received, either from a notification or a $events call
  3. missingEvents -The list of server events the client knows happened, but hasn't received
  4. receivedEvents - The list of server events the client just received. We do not keep an exhaustive list of all received events, since a client can process these as they are received. Note that if an event is re-sent to the client, it will not be re-surfaced here.

Defining Events (Actions upon the Client's State, not specific server events)

There are 4 types of events that can be raised to the client:

  1. notify - A notification sent to the client with included server events
  2. heartbeat - A notification sent to the client without any included events
  3. recover - The outcome of a $events call with included server events
  4. heartbeat-miss - To represent the client's heartbeat-period being exceeded

State Machine Algorithm

This is the rough algorithm I used to take an existing state and a new event (action) and create a new state:

  1. Compare eventsSinceSubscriptionStart to the last received value, if it's less than or equal, proceed to step 3
  2. Use eventsSinceSubscriptionStart to calculate a new list of missing events based on the previous state. Effectively ignore any included events until after this step
  3. If the event included any server events, try to add those to the list of missing events. This list will either be new (calculated from step 2) or existing (if skipped).