How does Spring Statemachine handle two transitions that has the same source state?
For example:
- Source State: ready
- Event: start
- One transition will be lead to the target state
running
, another one will befailure
Any help would be appreciated.
How does Spring Statemachine handle two transitions that has the same source state?
For example:
running
, another one will be failure
Any help would be appreciated.
The scenario you described above can be achieved in two ways.
In case of failure to process the incoming event (
Start
), machine would remain in the original state (ready
). The transition is only completed when event is process successfully.However, if you really need to get away from
ready
state and move torunning
orfailure
, one can use the Guard condition. You can use an evaluation function to define if theStart
event was successful or not and define to which state machine should go to.This can be achieved using a Choice pseudo-state that is protected by a Guard class, based on machine configuration and Guard evaluation, machine would move to the expected state
The official doc for reference on how to make the implementation is here