Example usage for org.springframework.statemachine.state ForkPseudoState getForks

List of usage examples for org.springframework.statemachine.state ForkPseudoState getForks

Introduction

In this page you can find the example usage for org.springframework.statemachine.state ForkPseudoState getForks.

Prototype

public List<State<S, E>> getForks() 

Source Link

Usage

From source file:org.springframework.statemachine.support.AbstractStateMachine.java

private void switchToState(State<S, E> state, Message<E> message, Transition<S, E> transition,
        StateMachine<S, E> stateMachine) {
    if (!isInitialTransition(transition) && !StateMachineUtils.isTransientPseudoState(state)
            && !callPreStateChangeInterceptors(state, message, transition, stateMachine)) {
        return;/* w  w w . j av a2 s.  c o  m*/
    }

    StateContext<S, E> stateContext = buildStateContext(Stage.STATE_CHANGED, message, transition, stateMachine);
    State<S, E> toState = followLinkedPseudoStates(state, stateContext);
    PseudoStateKind kind = state.getPseudoState() != null ? state.getPseudoState().getKind() : null;
    if (kind != null && (kind != PseudoStateKind.INITIAL && kind != PseudoStateKind.JOIN
            && kind != PseudoStateKind.FORK)) {
        callPreStateChangeInterceptors(toState, message, transition, stateMachine);
    }

    // need to check for from original state passed in
    kind = toState.getPseudoState() != null ? toState.getPseudoState().getKind() : null;
    if (kind == PseudoStateKind.FORK) {
        exitCurrentState(toState, message, transition, stateMachine);
        ForkPseudoState<S, E> fps = (ForkPseudoState<S, E>) toState.getPseudoState();
        for (State<S, E> ss : fps.getForks()) {
            callPreStateChangeInterceptors(ss, message, transition, stateMachine);
            setCurrentState(ss, message, transition, false, stateMachine, null, fps.getForks());
        }
    } else {
        Collection<State<S, E>> targets = new ArrayList<>();
        targets.add(toState);
        setCurrentState(toState, message, transition, true, stateMachine, null, targets);
    }

    callPostStateChangeInterceptors(state, message, transition, stateMachine);

    stateMachineExecutor.execute();
    if (isComplete()) {
        stop();
    }
}