Generic State Machine Manager

Design Features

Inspiration

Overview

StateMachines are first registered with the StateMachineManager, which I will refer to as simply the Manager. Every call to Manager::cycle() processes a single event. A single event corresponds to running on a single state machine. The Manager accesses the contents of the Controller and manipulates it. A single Controller is shared amongst all state machines registered with the Manager.

There are two types of events UserEvents and SystemEvents. UserEvents are passed to StateMachine::cycle() while SystemEvents are not. StateMachine::cycle() accepts a &mut Controller and a UserEvent. The StateMachine uses the functions in the Controller to add/remove events from the event queue; all functions do this except for timer related functions. SystemEvents are consumed by the manager and used to modify the Controller internals or send data or notifications to outside the state machine group.

Node based StateMachine Manager (in development)

Goals

In practice the design should give at most three message streams connected to a particular state machine down:

I/O

The new StateMachineManager owns:

The StateMachineManager is responsible for:

https://github.com/knox-networks/core/blob/67f7dc6ac57f5c6650d82ce0019e65a31278ae93/common/src/statemachine/nodestate_machine.rs#L65-L74

NodeStore is responsible for:

This allows NodeStore storage to:

https://github.com/knox-networks/core/blob/67f7dc6ac57f5c6650d82ce0019e65a31278ae93/common/src/state_machine/storage.rs#L10-L16

Node based TimeoutManager (in development)

Considerations: - only one timer is active per StateId<K>, State machines should not have to keep track of Operation::Set(Instant::now()) emitted to notifications. Thus, all timers should be indexable by StateId<K>. - A newer Operation::Set for the same StateId<K> should override an old timer. - A timeout should emit a Signal that is pertinent to the related state machine.

Approach: * TimeoutManager implements a per tick polling approach to resolving timeouts: https://github.com/knox-networks/core/blob/83d57647e38a55c5cfecacca8c89ebe98d45ab68/common/src/statemachine/timeout.rs#L170-L193 * TimeoutManager accepts two types of inputs, set and cancel (timeout): https://github.com/knox-networks/core/blob/83d57647e38a55c5cfecacca8c89ebe98d45ab68/common/src/statemachine/timeout.rs#L85-L89 * Timeouts are stored within the TimeoutLedger: https://github.com/knox-networks/core/blob/83d57647e38a55c5cfecacca8c89ebe98d45ab68/common/src/state_machine/timeout.rs#L25-L32 * TimeoutLedger contains a BTreeMap that indexes IDs by Instant and a HashMap that indexes Instants by ID This double indexing allows timeout cancellations to go through without providing the Instant that they were meant to remove