spring-projects / spring-statemachine

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

Hierarchical States:How do I get the child state #1034

Open FrostedMonkey opened 2 years ago

FrostedMonkey commented 2 years ago

When I use ObjectStateMachine to retrieve the current state machine state, I get the top-level state. How do I get the child state

ArtemChistyakov commented 2 years ago

@FrostedMonkey

State<States, Events> getState(State<States, Events> initialState) {
        if (!initialState.isSubmachineState()) {
            return initialState;
        }
        StateMachine<States, Events> submachine = 
        ((AbstractState<States, Events>) initialState).getSubmachine();
        State<States, Events> state = submachine.getState();
        return getState(state);
    }