Reputation: 41
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.
Upvotes: 1
Views: 2057
Reputation: 896
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 to running
or failure
, one can use the Guard condition. You can use an evaluation function to define if the Start
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
Upvotes: 2