Java Code Examples for org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer

The following examples show how to use org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
        throws Exception {
    transitions
            .withExternal()
            .source(States.SI)
            .target(States.S1)
            .event(Events.E1)
            .and()
            .withExternal()
            .source(States.S3)
            .target(States.S4)
            .event(Events.E4)
            .and()
            .withFork()
            .source(States.S1)
            .target(States.S2)
            .target(States.S3)
            .and()
            .withJoin()
            .source(States.S2)
            .source(States.S4)
            .target(States.S5);
}
 
Example 2
Source Project: cloudbreak   Source File: AbstractFlowConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
private void configure(StateMachineStateConfigurer<S, E> stateConfig, StateMachineTransitionConfigurer<S, E> transitionConfig,
        FlowEdgeConfig<S, E> flowEdgeConfig, Iterable<Transition<S, E>> transitions) throws Exception {
    StateConfigurer<S, E> stateConfigurer = stateConfig.withStates().initial(flowEdgeConfig.initState).end(flowEdgeConfig.finalState);
    ExternalTransitionConfigurer<S, E> transitionConfigurer = null;
    Collection<S> failHandled = new HashSet<>();
    for (Transition<S, E> transition : transitions) {
        transitionConfigurer = transitionConfigurer == null ? transitionConfig.withExternal() : transitionConfigurer.and().withExternal();
        AbstractAction<S, E, ?, ?> action = getAction(transition.source);
        if (action != null) {
            stateConfigurer.state(transition.source, action, null);
        }
        transitionConfigurer.source(transition.source).target(transition.target).event(transition.event);
        if (action != null && transition.getFailureEvent() != null && !Objects.equals(transition.target, flowEdgeConfig.defaultFailureState)) {
            action.setFailureEvent(transition.getFailureEvent());
            S failureState = Optional.ofNullable(transition.getFailureState()).orElse(flowEdgeConfig.defaultFailureState);
            stateConfigurer.state(failureState, getAction(failureState), null);
            transitionConfigurer.and().withExternal().source(transition.source).target(failureState).event(transition.getFailureEvent());
            if (!failHandled.contains(failureState)) {
                failHandled.add(failureState);
                transitionConfigurer.and().withExternal().source(failureState).target(flowEdgeConfig.finalState).event(flowEdgeConfig.failureHandled);
            }
        }
    }
    stateConfigurer.state(flowEdgeConfig.finalState, getAction(FlowFinalizeAction.class), null);
}
 
Example 3
Source Project: tutorials   Source File: ForkJoinStateMachineConfiguration.java    License: MIT License 6 votes vote down vote up
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions.withExternal()
            .source("SI").target("SFork").event("E1")
            .and().withExternal()
                .source("Sub1-1").target("Sub1-2").event("sub1")
            .and().withExternal()
                .source("Sub2-1").target("Sub2-2").event("sub2")
            .and()
            .withFork()
                .source("SFork")
                .target("Sub1-1")
                .target("Sub2-1")
            .and()
            .withJoin()
                .source("Sub1-2")
                .source("Sub2-2")
                .target("SJoin");
}
 
Example 4
@Override
  public void configure(StateMachineTransitionConfigurer<States, Events> transitions) throws Exception {
      // @formatter:off
transitions
	.withExternal()
	.source(States.SI).target(States.S1).event(Events.E1)
	.and()
	.withExternal()
	.source(States.S1).target(States.S2).event(Events.E2);
// @formatter:on
  }
 
Example 5
@Override
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
        throws Exception {
    transitions
            .withChoice()
            .source(States.S1)
            .first(States.S2, s2Guard())
            .then(States.S3, s3Guard())
            .last(States.S4)
            .and()
            .withExternal()
            .source(States.SI)
            .target(States.S1)
            .event(Events.E1);
}
 
Example 6
@Override
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
        throws Exception {
    transitions
            .withHistory()
            .source(States.S2H)
            .target(States.S22)
            .and()
            .withExternal()
            .source(States.S1)
            .target(States.S2)
            .event(Events.E2)
            .and()
            .withExternal()
            .source(States.S2)
            .target(States.S1)
            .event(Events.E1)
            .and()
            .withExternal()
            .source(States.S2)
            .target(States.S21)
            .event(Events.E21)
            .and()
            .withExternal()
            .source(States.S21)
            .target(States.S22)
            .event(Events.E22)
            .and()
            .withExternal()
            .source(States.S2)
            .target(States.S2H)
            .event(Events.E2H)
            .and()
            .withExternal()
            .source(States.S22)
            .target(States.S221)
            .event(Events.E221);
}
 
Example 7
@Override
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
        throws Exception {
    transitions
            .withHistory()
            .source(States.S2H)
            .target(States.S22)
            .and()
            .withExternal()
            .source(States.S1)
            .target(States.S2)
            .event(Events.E2)
            .and()
            .withExternal()
            .source(States.S2)
            .target(States.S1)
            .event(Events.E1)
            .and()
            .withExternal()
            .source(States.S2)
            .target(States.S21)
            .event(Events.E21)
            .and()
            .withExternal()
            .source(States.S21)
            .target(States.S22)
            .event(Events.E22)
            .and()
            .withExternal()
            .source(States.S2)
            .target(States.S2H)
            .event(Events.E2H)
            .and()
            .withExternal()
            .source(States.S22)
            .target(States.S221)
            .event(Events.E221);
}
 
Example 8
@Override
public void configure(StateMachineTransitionConfigurer<StateEnum, EventEnum> transitions) throws Exception {
    transitions
            .withExternal()
            .source(StateEnum.S1)
            .target(StateEnum.S2)
            .event(EventEnum.E1)
            .and()
            .withExternal()
            .source(StateEnum.S2)
            .target(StateEnum.S1)
            .event(EventEnum.E2);
}
 
Example 9
Source Project: tools-journey   Source File: StatemachineConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(StateMachineTransitionConfigurer<TurnstileStates, TurnstileEvents> transitions)
        throws Exception {
    transitions
            .withExternal()
            .source(TurnstileStates.Unlocked).target(TurnstileStates.Locked)
            .event(TurnstileEvents.PUSH).action(customerPassAndLock())
            .and()
            .withExternal()
            .source(TurnstileStates.Locked).target(TurnstileStates.Unlocked)
            .event(TurnstileEvents.COIN).action(turnstileUnlock())
    ;
}
 
Example 10
Source Project: tutorials   Source File: HierarchicalStateMachineConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions.withExternal()
            .source("SI").target("SF").event("end")
            .and().withExternal()
            .source("SUB1").target("SUB2").event("se1")
            .and().withExternal()
            .source("SUB2").target("SUBEND").event("s-end");
}
 
Example 11
Source Project: tutorials   Source File: SimpleStateMachineConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions
      .withExternal()
      .source("SI")
      .target("S1")
      .event("E1")
      .action(initAction())
      .and()
      .withExternal()
      .source("S1")
      .target("S2")
      .event("E2")
      .and()
      .withExternal()
      .source("SI")
      .target("S3")
      .event("E3")
      .and()
      .withExternal()
      .source("S3")
      .target("S4")
      .event("E4")
      .and()
      .withExternal()
      .source("S4")
      .target("S5")
      .event("E5")
      .and()
      .withExternal()
      .source("S5")
      .target("SF")
      .event("end")
      .guard(simpleGuard());
}
 
Example 12
Source Project: tutorials   Source File: JunctionStateMachineConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions.withExternal()
            .source("SI").target("SJ").event("E1")
            .and()
            .withJunction()
            .source("SJ")
            .first("high", highGuard())
            .then("medium", mediumGuard())
            .last("low")
            .and().withExternal()
            .source("low").target("SF").event("end");
}
 
Example 13
Source Project: tutorials   Source File: SimpleEnumStateMachineConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
public void configure(StateMachineTransitionConfigurer<ApplicationReviewStates, ApplicationReviewEvents> transitions) throws Exception {
    transitions.withExternal()
            .source(ApplicationReviewStates.PEER_REVIEW).target(ApplicationReviewStates.PRINCIPAL_REVIEW).event(ApplicationReviewEvents.APPROVE)
            .and().withExternal()
            .source(ApplicationReviewStates.PRINCIPAL_REVIEW).target(ApplicationReviewStates.APPROVED).event(ApplicationReviewEvents.APPROVE)
            .and().withExternal()
            .source(ApplicationReviewStates.PEER_REVIEW).target(ApplicationReviewStates.REJECTED).event(ApplicationReviewEvents.REJECT)
            .and().withExternal()
            .source(ApplicationReviewStates.PRINCIPAL_REVIEW).target(ApplicationReviewStates.REJECTED).event(ApplicationReviewEvents.REJECT);
}