Java源码示例:org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer
示例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);
}
示例2
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);
}
示例3
@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");
}
示例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
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例9
@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())
;
}
示例10
@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");
}
示例11
@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());
}
示例12
@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");
}
示例13
@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);
}