/** * Handle the specified trigger. * @param trigger The trigger that needs to be handled by the state machine. * If this results in an attempt to perform a transition which is not * allowed an {@link IllegalArgumentException} is thrown. * @param context Reference to the context. */ public void handle(@Nullable T trigger, C context) { T ev = trigger; do { if (ev != null) { changeState(ev, context); } ev = currentState.handle(trigger, context); } while (ev != null); }
final Map<State<?, ?>, Integer> idMap = newHashMap(); for (final State<?, ?> s : allStates) { builder.append(NODE).append(id).append(LABEL_OPEN).append(s.name()) .append(LABEL_CLOSE); idMap.put(s, id);
/** * Perform a state change if possible. * @param trigger The trigger that may initiate a state change. * @param context Reference to the context. */ protected void changeState(T trigger, C context) { checkArgument(transitionTable.contains(currentState, trigger), "The trigger %s is not supported when in state %s.", trigger, currentState); final State<T, C> newState = transitionTable.get(currentState, trigger); if (!newState.equals(currentState) || explicitRecursiveTransitions) { currentState.onExit(trigger, context); final State<T, C> oldState = currentState; currentState = newState; currentState.onEntry(trigger, context); eventDispatcher.dispatchEvent(new StateTransitionEvent<>(this, oldState, trigger, newState)); } }
final Map<State<?, ?>, Integer> idMap = newHashMap(); for (final State<?, ?> s : allStates) { builder.append(NODE).append(id).append(LABEL_OPEN).append(s.name()) .append(LABEL_CLOSE); idMap.put(s, id);
/** * Perform a state change if possible. * @param trigger The trigger that may initiate a state change. * @param context Reference to the context. */ protected void changeState(T trigger, C context) { checkArgument(transitionTable.contains(currentState, trigger), "The trigger %s is not supported when in state %s.", trigger, currentState); final State<T, C> newState = transitionTable.get(currentState, trigger); if (!newState.equals(currentState) || explicitRecursiveTransitions) { currentState.onExit(trigger, context); final State<T, C> oldState = currentState; currentState = newState; currentState.onEntry(trigger, context); eventDispatcher.dispatchEvent(new StateTransitionEvent<>(this, oldState, trigger, newState)); } }
@Override public void stop() { LOGGER.trace("stop"); checkState(stateMachine.isSupported(Trigger.STOP), "Can not stop time in current state: %s", stateMachine.getCurrentState().name()); final boolean rt = stateMachine.stateIs(realtimeState); stateMachine.handle(Trigger.STOP, this); if (!rt) { shutdownExecutor(); } }
/** * Handle the specified trigger. * @param trigger The trigger that needs to be handled by the state machine. * If this results in an attempt to perform a transition which is not * allowed an {@link IllegalArgumentException} is thrown. * @param context Reference to the context. */ public void handle(@Nullable T trigger, C context) { T ev = trigger; do { if (ev != null) { changeState(ev, context); } ev = currentState.handle(trigger, context); } while (ev != null); }