Run to Completion for a State Machine #910
Replies: 2 comments
-
There's a lot of things missing from theories/specs and a lot of details are left to an actual implementation. #811 also talked about restoring machine into terminal states of a regions which are joined(substate with two regions all having terminal states). This is also one of those corner cases where I'm not sure if machine should ever be in a state where all substate regions are actually in a terminal state as that should terminate enclosing state and go forward if there's join or anonymous transition. I've been thinking if having some sort of a recipes would help people to handle errors better. |
Beta Was this translation helpful? Give feedback.
-
Thanks @jvalkeal @mehmetsalgar and sorry I missed this discussion being posted.
For my purposes undefined is desired and expected - I need an error to immediately halt execution with any further calls to the state machine throwing an exception. The database transaction should be rolled back so no change would be made to state, which is left consistent. How can the state machine have transitioned to state B if the transition handler hasn't executed correctly?
What about bugs in actions like NullPointerException? This isn't something an Action can handle; I need such exceptions to be propagated to the invoker of the event so they know the request failed and to ensure the transaction is rolled back. I can't have a situation where unhandled exceptions are silently swallowed/developers are expected to handle all possible errors in an inversion of normal Java error handling semantics. |
Beta Was this translation helpful? Give feedback.
-
Lately, I saw an issue in the github, complaining about State Machine is not propagating an Exception during a transition (#901).
I like to say some words about the run to completion concept of the state machine, which you can read also here Run to Completion RTC2. lots of Java developers having problem to understand it.
When a State Machine receives an Event being in a StateA and starts a transition, if this transition leads to another StateB, it can't stop in the middle, it should lead to the another State, if it stops, it is undefined, is it in StateA or in StateB. Here come the name 'Run to Completion', State Machine theorie has no concept of Java Exception, for that reason Spring State Machine can just not stop during an Action while a transition throws an Exception.
It is developer responsiblity inside of the Action to have strategies to prevent that Exception.
Beta Was this translation helpful? Give feedback.
All reactions