spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.51k stars 598 forks source link

Transition with the same event in multiple regions #1111

Open Balint-Ivanics-KUKA opened 10 months ago

Balint-Ivanics-KUKA commented 10 months ago

Hi,

Multiple regions of the same state machine using the same event for transition don't react as I would expect based on the docs. "Whether you send one event or multiple events, result is always a sequence of results. This is so because in a presence multiple reqions, results will come back from multiple machines in those regions. This is shown with method sendEventCollect which gives a list of results." To me this suggested that multiple regions can accept the event but it looks like that is not the case.

If I have the following state machine:

    public void configure(StateMachineStateConfigurer<MyStateMachineState, MyStateMachineEvent> states)
            throws Exception
    {
        states
                .withStates()
                .initial(BasicState.ROOT)
                .and()
                .withStates()
                .parent(BasicState.ROOT)
                .region("region1")
                .initial(BasicState.CHILD11)
                .state(BasicState.CHILD12)
                .and()
                .withStates()
                .parent(BasicState.ROOT)
                .region("region2")
                .initial(BasicState.CHILD21)
                .state(BasicState.CHILD22);
    }

    public void configure(StateMachineTransitionConfigurer<MyStateMachineState, MyStateMachineEvent> transitions)
            throws Exception
    {
        transitions
                .withExternal().source(BasicState.CHILD11).target(BasicState.CHILD12).event(BasicEvent.EVENT)
                .and()
                .withExternal().source(BasicState.CHILD21).target(BasicState.CHILD22).event(BasicEvent.EVENT);
    }

then if I send a BasicEvent.EVENT only one of the regions will transition. I would have expected both to transition.

Is this the intended behavior?

Thanks

manhnt217 commented 4 months ago

I'm new to Spring state machine. I'm experiencing the same behaviour.