List of usage examples for org.springframework.statemachine.config.builders StateMachineStateConfigurer withStates
StateConfigurer<S, E> withStates() throws Exception;
From source file:com.example.StateMachineConfiguration.java
@Override public void configure(final StateMachineStateConfigurer<IssueStates, UserAction> states) throws Exception { states.withStates().initial(IssueStates.NO_PROBLEM) .states(Sets.mutable.of(IssueStates.values()).asUnmodifiable()); }
From source file:ru.asmsoft.p2p.fsm.NodeStateMachine.java
@Override public void configure(StateMachineStateConfigurer<NodeStates, NodeEvents> states) throws Exception { states.withStates().initial(NodeStates.CONNECTED).states(EnumSet.allOf(NodeStates.class)); }
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 . j a v a 2 s.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(); }