Example usage for org.springframework.statemachine.support StateMachineUtils isPseudoState

List of usage examples for org.springframework.statemachine.support StateMachineUtils isPseudoState

Introduction

In this page you can find the example usage for org.springframework.statemachine.support StateMachineUtils isPseudoState.

Prototype

public static <S, E> boolean isPseudoState(State<S, E> state, PseudoStateKind kind) 

Source Link

Usage

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

private void entryToState(State<S, E> state, Message<E> message, Transition<S, E> transition,
        StateMachine<S, E> stateMachine, Collection<State<S, E>> sources, Collection<State<S, E>> targets) {
    if (state == null) {
        return;/*  w  w  w .ja v  a  2 s .c  om*/
    }
    log.trace("Trying Enter state=[" + state + "]");
    StateContext<S, E> stateContext = buildStateContext(Stage.STATE_ENTRY, message, transition, stateMachine,
            sources, targets);

    if (transition != null) {
        State<S, E> findDeep1 = findDeepParent(transition.getTarget());
        State<S, E> findDeep2 = findDeepParent(transition.getSource());
        boolean isComingFromOtherSubmachine = findDeep1 != null && findDeep2 != null
                && findDeep2 != currentState;

        boolean isSubOfSource = StateMachineUtils.isSubstate(transition.getSource(), currentState);
        boolean isSubOfTarget = StateMachineUtils.isSubstate(transition.getTarget(), currentState);

        if (transition.getKind() == TransitionKind.LOCAL
                && StateMachineUtils.isSubstate(transition.getSource(), transition.getTarget())
                && transition.getSource() == currentState) {
            return;
        } else if (transition.getKind() == TransitionKind.LOCAL
                && StateMachineUtils.isSubstate(transition.getTarget(), transition.getSource())
                && transition.getTarget() == currentState) {
            return;
        }

        if (currentState == transition.getSource() && currentState == transition.getTarget()) {
        } else if (!isSubOfSource && !isSubOfTarget && currentState == transition.getTarget()) {
        } else if (isComingFromOtherSubmachine) {
        } else if (!isSubOfSource && !isSubOfTarget && findDeep2 == null) {
        } else if (isSubOfSource && !isSubOfTarget && currentState == transition.getTarget()) {
            if (isDirectSubstate(transition.getSource(), transition.getTarget())
                    && transition.getKind() != TransitionKind.LOCAL && isInitial(transition.getTarget())) {
                return;
            }
        } else if (!isSubOfSource && !isSubOfTarget && (transition.getSource() == currentState
                && StateMachineUtils.isSubstate(currentState, transition.getTarget()))) {
        } else if (!isSubOfSource && !isSubOfTarget) {
            if (!StateMachineUtils.isTransientPseudoState(transition.getTarget())) {
                return;
            }
        }
    }

    // with linked joins, we need to enter state but should not notify.
    // state entries are needed to track join logic.
    if (!StateMachineUtils.isPseudoState(state, PseudoStateKind.JOIN)) {
        notifyStateEntered(
                buildStateContext(Stage.STATE_ENTRY, message, transition, getRelayStateMachine(), null, state));
    }
    log.debug("Enter state=[" + state + "]");
    state.entry(stateContext);
}

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

private boolean handleTriggerTrans(List<Transition<S, E>> trans, Message<E> queuedMessage) {
    boolean transit = false;
    for (Transition<S, E> t : trans) {
        if (t == null) {
            continue;
        }// w w w .j a  va2  s. c  o  m
        State<S, E> source = t.getSource();
        if (source == null) {
            continue;
        }
        State<S, E> currentState = stateMachine.getState();
        if (currentState == null) {
            continue;
        }
        if (!StateMachineUtils.containsAtleastOne(source.getIds(), currentState.getIds())) {
            continue;
        }

        // special handling of join
        if (StateMachineUtils.isPseudoState(t.getTarget(), PseudoStateKind.JOIN)) {
            if (joinSyncStates.isEmpty()) {
                List<State<S, E>> joins = ((JoinPseudoState<S, E>) t.getTarget().getPseudoState()).getJoins();
                joinSyncStates.addAll(joins);
            }
            joinSyncTransitions.add(t);
            boolean removed = joinSyncStates.remove(t.getSource());
            boolean joincomplete = removed & joinSyncStates.isEmpty();
            if (joincomplete) {
                for (Transition<S, E> tt : joinSyncTransitions) {
                    StateContext<S, E> stateContext = buildStateContext(queuedMessage, tt, relayStateMachine);
                    tt.transit(stateContext);
                    stateMachineExecutorTransit.transit(tt, stateContext, queuedMessage);
                }
                joinSyncTransitions.clear();
                break;
            } else {
                continue;
            }
        }

        StateContext<S, E> stateContext = buildStateContext(queuedMessage, t, relayStateMachine);
        try {
            stateContext = interceptors.preTransition(stateContext);
        } catch (Exception e) {
            // currently expect that if exception is
            // thrown, this transition will not match.
            // i.e. security may throw AccessDeniedException
            log.info("Interceptors threw exception", e);
            stateContext = null;
        }
        if (stateContext == null) {
            break;
        }

        try {
            transit = t.transit(stateContext);
        } catch (Exception e) {
            log.warn("Transition " + t + " caused error " + e);
        }
        if (transit) {
            stateMachineExecutorTransit.transit(t, stateContext, queuedMessage);
            interceptors.postTransition(stateContext);
            break;
        }
    }
    return transit;
}