Gets this RaftStateMachine
s internal state. This function should
convert the state tracked inside this state machine (e.g. with one or
multiple variables) into RaftData
and return it. The returned
state is used to resolve the promise returned by
RaftController.propose()
and to
provide the values for
RaftController.getState()
and
RaftController.observeState()
.
This RaftStateMachine
's internal state. Must be of type
RaftData
.
getState()
and setState()
are counterparts. Setting the state
of one state machine instance to the state of another one
(SM1.setState(SM2.getState())
) should result in both state machines
representing the exact same state and behaving exactly the same regarding
new state machine inputs.
Defines how inputs proposed with
RaftController.propose()
affect this
RaftStateMachine
s internal state after they were committed.
The input that should be processed. Is of type
RaftData
.
Sets this RaftStateMachine
s internal state. This function should use
the provided state
to set the state tracked inside this state machine.
The structure of the provided state is implicitly defined inside
getState()
. See remarks of getState()
.
The state this state machine should be set to. Is of type
RaftData
.
Generated using TypeDoc
Users of the
RaftController
have to implement aRaftStateMachine
and provide an instance of it in theRaftControllerOptions
when bootstrapping the controller. The provided state machine will be used internally to describe the state shared between all agents with correspondingRaftController
s.A call to
RaftController.propose()
will triggerthis.processInput()
after the input has been committed. After that the state is retrieved withthis.getState()
and then used to resolve the promise returned by the initialRaftController.propose()
call.A typical
RaftStateMachine
implementation keeps track of some form of state (e.g. a variable of typeMap
) and defines how inputs affect this state insideprocessInput()
.getState()
andsetState()
are used to access the tracked state.An example
RaftStateMachine
implementation of a key value store looks like this: