List of usage examples for org.springframework.statemachine.config.builders StateMachineTransitionConfigurer withExternal
ExternalTransitionConfigurer<S, E> withExternal() throws Exception;
From source file:com.example.StateMachineConfiguration.java
@Override public void configure(final StateMachineTransitionConfigurer<IssueStates, UserAction> transitions) throws Exception { transitions.withExternal().source(IssueStates.NO_PROBLEM).event(UserAction.FIND_ISSUE) .target(IssueStates.CREATED).and().withExternal().source(IssueStates.CREATED) .event(UserAction.START_WORKING).target(IssueStates.IN_PROCESS).and().withExternal() .source(IssueStates.IN_PROCESS).event(UserAction.DONE_WORKING).target(IssueStates.FIXED).and() .withExternal().source(IssueStates.FIXED).event(UserAction.TEST_SUCCEEDED) .target(IssueStates.VERIFIED).and().withExternal().source(IssueStates.FIXED) .event(UserAction.TEST_FAILED).target(IssueStates.RE_OPEN).and().withExternal() .source(IssueStates.RE_OPEN).event(UserAction.START_WORKING).target(IssueStates.IN_PROCESS); }
From source file:ru.asmsoft.p2p.fsm.NodeStateMachine.java
@Override public void configure(StateMachineTransitionConfigurer<NodeStates, NodeEvents> transitions) throws Exception { transitions .withExternal().source(NodeStates.CONNECTED).target(NodeStates.IN_TRANSACTION) .event(NodeEvents.StartTransactionReceived).and().withExternal().source(NodeStates.IN_TRANSACTION) .target(NodeStates.UPDATED_BY_REMOTE).event(NodeEvents.UpdateReceived).and().withExternal() .source(NodeStates.UPDATED_BY_REMOTE).target(NodeStates.CONNECTED).event(NodeEvents.CommitReceived) .and().withExternal().source(NodeStates.UPDATED_BY_REMOTE).target(NodeStates.CONNECTED) .event(NodeEvents.RollbackReceived) .and().withExternal().source(NodeStates.CONNECTED).target(NodeStates.INCOMING_MESSAGE_RECEIVED) .event(NodeEvents.IncomingMessageArrived).and().withExternal() .source(NodeStates.INCOMING_MESSAGE_RECEIVED).target(NodeStates.CONNECTED) .event(NodeEvents.IncomingMessageAccepted).and().withExternal().source(NodeStates.CONNECTED) .target(NodeStates.STARTED_TRANSACTION).event(NodeEvents.StartTransactionSent).and().withExternal() .source(NodeStates.STARTED_TRANSACTION).target(NodeStates.CONNECTED) .event(NodeEvents.StartTransactionFailed).and().withExternal() .source(NodeStates.STARTED_TRANSACTION).target(NodeStates.UPDATING_REMOTE) .event(NodeEvents.UpdateRemoteNodes) .and().withExternal().source(NodeStates.UPDATING_REMOTE).target(NodeStates.CONNECTED) .event(NodeEvents.CommitSent).and().withExternal().source(NodeStates.UPDATING_REMOTE) .target(NodeStates.CONNECTED).event(NodeEvents.RollbackSent) .and().withExternal().source(NodeStates.CONNECTED).target(NodeStates.SENDING_UPDATE) .event(NodeEvents.UpdateMeRequestReceived).and().withExternal().source(NodeStates.SENDING_UPDATE) .target(NodeStates.CONNECTED).event(NodeEvents.UpdateByRequestSent) .and().withExternal().source(NodeStates.CONNECTED).target(NodeStates.WAIT_FOR_UPDATE_BY_REQUEST) .event(NodeEvents.UpdateMeRequestSent).and().withExternal() .source(NodeStates.WAIT_FOR_UPDATE_BY_REQUEST).target(NodeStates.CONNECTED) .event(NodeEvents.UpdateByRequestReceived); }
From source file:com.netflix.genie.agent.execution.statemachine.StateMachineAutoConfiguration.java
private void configureTransitions(final StateMachineBuilder.Builder<States, Events> builder, final Collection<Triple<States, Events, States>> eventDrivenTransitions, final Collection<States> statesWithErrorTransition) throws Exception { final StateMachineTransitionConfigurer<States, Events> transitionConfigurer = builder .configureTransitions();/*from w w w .j a v a 2 s . c o m*/ // Set up event-driven transitions for (Triple<States, Events, States> transition : eventDrivenTransitions) { final States sourceState = transition.getLeft(); final States targetState = transition.getRight(); final Events event = transition.getMiddle(); transitionConfigurer.withExternal().source(sourceState).target(targetState).event(event).and(); log.info("Configured event-driven transition: ({}) -> [{}] -> ({})", sourceState, event, targetState); } // Set up transitions to HANDLE_ERROR state. for (States state : statesWithErrorTransition) { transitionConfigurer.withExternal().source(state).target(States.HANDLE_ERROR).event(Events.ERROR).and(); log.info("Configured error transition: ({}) -> ({})", state, States.HANDLE_ERROR); } // Add transition from HANDLE_ERROR to END transitionConfigurer.withExternal().source(States.HANDLE_ERROR).target(States.END) .event(Events.HANDLE_ERROR_COMPLETE); }
From source file:org.springframework.statemachine.recipes.tasks.TasksHandler.java
private StateMachine<String, String> buildStateMachine(List<TaskWrapper> tasks, TaskExecutor taskExecutor) throws Exception { StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder(); int taskCount = topLevelTaskCount(tasks); builder.configureConfiguration().withConfiguration() .taskExecutor(taskExecutor != null ? taskExecutor : taskExecutor(taskCount)); StateMachineStateConfigurer<String, String> stateMachineStateConfigurer = builder.configureStates(); StateMachineTransitionConfigurer<String, String> stateMachineTransitionConfigurer = builder .configureTransitions();/*from w w w . ja va2s.c om*/ stateMachineStateConfigurer.withStates().initial(STATE_READY).fork(STATE_FORK) .state(STATE_TASKS, tasksEntryAction(), null).join(STATE_JOIN).choice(STATE_CHOICE) .state(STATE_ERROR); stateMachineTransitionConfigurer.withExternal().source(STATE_READY).target(STATE_FORK).event(EVENT_RUN) .and().withFork().source(STATE_FORK).target(STATE_TASKS); Iterator<Node<TaskWrapper>> iterator = buildTasksIterator(tasks); String parent = null; Collection<String> joinStates = new ArrayList<String>(); while (iterator.hasNext()) { Node<TaskWrapper> node = iterator.next(); if (node.getData() == null) { break; } String initial = STATE_TASKS_PREFIX + node.getData().id.toString() + STATE_TASKS_INITIAL_POSTFIX; String task = STATE_TASKS_PREFIX + node.getData().id.toString(); parent = node.getData().parent != null ? STATE_TASKS_PREFIX + node.getData().parent.toString() : STATE_TASKS; stateMachineStateConfigurer.withStates().parent(parent).initial(initial).state(task, runnableAction(node.getData().runnable, node.getData().id.toString()), null); if (node.getChildren().isEmpty()) { joinStates.add(task); } stateMachineTransitionConfigurer.withExternal().state(parent).source(initial).target(task); } stateMachineStateConfigurer.withStates().parent(STATE_ERROR).initial(STATE_AUTOMATIC) .state(STATE_AUTOMATIC, automaticAction(), null).state(STATE_MANUAL); stateMachineTransitionConfigurer.withJoin().sources(joinStates).target(STATE_JOIN).and().withExternal() .source(STATE_JOIN).target(STATE_CHOICE).and().withChoice().source(STATE_CHOICE) .first(STATE_ERROR, tasksChoiceGuard()).last(STATE_READY).and().withExternal().source(STATE_ERROR) .target(STATE_READY).event(EVENT_CONTINUE).action(continueAction()).and().withExternal() .source(STATE_AUTOMATIC).target(STATE_MANUAL).event(EVENT_FALLBACK).and().withInternal() .source(STATE_MANUAL).action(fixAction()).event(EVENT_FIX); return builder.build(); }