2

I have been using Spring State-machines for a while now and I have come across a situation where there has been a need to re-use a sub-machine in two different state-machines. I realized that the same submachine cannot be used in the same state-machine, is it the same with different machines as well?

Elaborating, if the sub-machine is in a different root element,isn't it possible to link it to a state machine in another root element?

  • what's the use-case? It's not clear if you want to share a submachine and keep it consistent between the parent state machines, or if you want to progress the submachine independently. You can work with the submachine configuration - e.g. persist the state and / or configuration - then initialize as many other submachines you want - attach them anywhere and hydrate back the persisted state. – hovanessyan Sep 25 '19 at 07:30
  • Okay, so I have two different UML based state-machines with two configurations.There is a set of states that do the same thing in both so I want to create a sub-machine and use it in both above state-machines so that, that part of the flow doesn't have to be duplicated in each. – Sachini Wickramaratne Sep 25 '19 at 09:04
  • Okay in this case my assumption is that it should be possible to use StateMachineFactory to initialize 2 instances of your sub-state machine and attach them to a parent SM. But this is solving a technical dept issue, which could be solved later on as well. Maybe use the duplicate configuration for now and make it work - write some tests using StateMachineTestPlanBuilder and then refactor to remove the configuration duplication. – hovanessyan Sep 25 '19 at 10:21

0 Answers0