/** * Gives the current {@link State} time to update. * @param context Reference to the context. */ public void handle(C context) { handle(null, context); }
/** * 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); }
@Override public void switchToRealTime() { checkState(stateMachine.isSupported(Trigger.REAL_TIME), "Can not switch to real time mode because clock is already stopped."); stateMachine.handle(Trigger.REAL_TIME, this); }
@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(); } }
@Override protected StateMachine<StateEvent, RouteFollowingVehicle> createStateMachine() { // when overriding, please see doc of super method! // reuse super implementation final StateMachine<StateEvent, RouteFollowingVehicle> fsm = super.createStateMachine(); // get ref to existing state final Wait wait = fsm.getStateOfType(Wait.class); // add new state final ExtraState extra = new ExtraState(); // add two new transitions return StateMachine.create(wait) .addTransition(wait, ExtraEvent.TEST_EVENT, extra) .addTransition(extra, DefaultEvent.DONE, wait) .addTransitionsFrom(fsm) .build(); }
public State<StateEvent, RouteFollowingVehicle> getState() { return stateMachine.getCurrentState(); }
StateMachine(State<T, C> start, ImmutableTable<State<T, C>, T, State<T, C>> table, boolean explRecurTrns) { eventDispatcher = new EventDispatcher(StateMachineEvent.values()); startState = start; currentState = start; transitionTable = table; explicitRecursiveTransitions = explRecurTrns; }
SubVehicle(VehicleDTO pDto, boolean allowDelayedRouteChanging) { super(pDto, allowDelayedRouteChanging); extraState = stateMachine.getStateOfType(ExtraState.class); }
@Override public boolean isTicking() { return !stateMachine.stateIsOneOf(SimpleState.values()); }
@Override public String toString() { return new StringBuilder("[Event ").append(getEventType()).append(" ") .append(previousState).append(" + ").append(trigger).append(" -> ") .append(newState).append("]").toString(); }
/** * Create a new {@link StateMachine} instance with the specified initial * state. This method returns a reference to the {@link StateMachineBuilder} * which allows for adding of transitions to the state machine. * @param initialState The start state of the state machine. * @param <T> The trigger type. * @param <C> The context type. * @return A reference to the {@link StateMachineBuilder} which is used for * creating the {@link StateMachine}. */ @CheckReturnValue public static <T, C> StateMachineBuilder<T, C> create( State<T, C> initialState) { return new StateMachineBuilder<>(initialState); }
@Override public String name() { return super.name() + name; }
@Nullable @Override public Events handle(@Nullable Events event, Context context) { super.handle(event, context); if (context == SPECIAL_CONTEXT) { return Events.START; } return null; } }
@Override public void switchToSimulatedTime() { checkState(stateMachine.isSupported(Trigger.SIMULATE), "Can not switch to simulated time mode because clock is already " + "stopped."); stateMachine.handle(Trigger.SIMULATE, this); }
/** * Gives the current {@link State} time to update. * @param context Reference to the context. */ public void handle(C context) { handle(null, context); }
@Override public ClockMode getClockMode() { return ((ClockState) stateMachine.getCurrentState()).getClockMode(); }
StateMachine(State<T, C> start, ImmutableTable<State<T, C>, T, State<T, C>> table, boolean explRecurTrns) { eventDispatcher = new EventDispatcher(StateMachineEvent.values()); startState = start; currentState = start; transitionTable = table; explicitRecursiveTransitions = explRecurTrns; }
/** * 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); }
@Override public String toString() { return new StringBuilder("[Event ").append(getEventType()).append(" ") .append(previousState).append(" + ").append(trigger).append(" -> ") .append(newState).append("]").toString(); }