4

I have an UML diagram as below : UMl

How to configure states and transitions in state machine from SI to END based on events....

 public class Config14
            extends EnumStateMachineConfigurerAdapter<States, Events> {
    
        @Override
        public void configure(StateMachineStateConfigurer<States, Events> states)
                throws Exception {
                                  .....

}



    @Override
            public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
                    throws Exception {
                                   .....
    }
}
bollam_rohith
  • 334
  • 4
  • 17

1 Answers1

2

Though it is late to answer, I will put my findings anyways. To achieve the show state transitions, you need to have a fork/join pseudo states. As it has been mentioned over here (https://www.uml-diagrams.org/state-machine-diagrams.html), Pseudostates are typically used to connect multiple transitions into more complex state transitions paths. And their respective definition is as follows:

Fork pseudostate vertices serve to split an incoming transition into two or more transitions terminating on orthogonal target vertices (i.e., vertices in different regions of a composite state).

Join pseudostate merges several transitions originating from source vertices in different orthogonal regions.

One should note that segments outgoing from a fork vertex must not have guards or triggers(same applies for a Join).

Your config should more or less be like the following:

@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
    states
        .withStates()
        .initial("SI")
        .fork("S1")
        .join("JOIN")
        .state("S11")
        .state("S12")
        .state("S2")
        .end("END")
        .and()
        .withStates()
            .parent("S1")
            .initial("S11")
            .end("S11") //not very sure about this
        .and()
        .withStates()
            .parent("S1")
            .initial("S12")
            .end("S12");
}

and

@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions.withExternal()
                .source("SI").target("S1").event("YOUR_EVENT")
             .and()
             .withExternal()
                .source("S2").target("END").event("YOUR_EVENT")
            .and()
            .withFork()
                .source("S1")
                .target("S11")
                .target("S12")
            .and()
            .withJoin()
                .source("S11")
                .source("S12")
                .target("JOIN");
}

For a sample, check https://github.com/amenski/statemachine

Aman
  • 1,627
  • 13
  • 19
  • With this example, I have below issue: After SI to S1, State machine shows current state as S11. now how to trigger S12 with some event. It does not accept any event for S12. Is it like subprocess state machine should not have any event based states? – c.sankhala Jun 06 '22 at 13:52
  • 1
    As I tried to point out about `Pseudostates`, you can't specify an event to go from a state to Pseudostates and vice-versa. So, with the above example you should have both S11 and S12 activated simultaneously once you reach S1 and join on S2 without needing any events. – Aman Jun 06 '22 at 15:18