gpt4 book ai didi

java - Spring 状态机转换

转载 作者:行者123 更新时间:2023-12-02 13:10:15 26 4
gpt4 key购买 nike

我试图触发其他状态机的转换以进行自动状态机(SM),但它不起作用:初始操作(findCustomer())应该更改SM的初始状态,然后每个操作都会触发一个事件并依此类推直到最终状态。这是我的配置:

    @Configuration @EnableStateMachine public class CardStateMachineConfig extends EnumStateMachineConfigurerAdapter<CardStates, CardEvents> {


final private static Logger logger = LoggerFactory.getLogger(CardStateMachineConfig.class);

@Override
public void configure(StateMachineStateConfigurer<CardStates, CardEvents> states) throws Exception {
states.withStates().initial(CardStates.ACTIVE_STATUS).state(CardStates.ACTIVE_STATUS, findCustomer(), null)
.states(EnumSet.allOf(CardStates.class));

}

// @formatter:off
@Override
public void configure(StateMachineTransitionConfigurer<CardStates, CardEvents> transitions) throws Exception {




transitions.withExternal().source(CardStates.ACTIVE_STATUS).target(CardStates.CUSTOMER_FOUND).event(CardEvents.FIND_CUSTOMER).action(findCustomer())
.and().withExternal()
.source(CardStates.CUSTOMER_FOUND).target(CardStates.MOBILECARD_FOUND).event(CardEvents.CUSTOMER_FOUND).action(findMobileCard())
.and().withExternal()
.source(CardStates.FIND_MOBILECARD_FOUND).target(CardStates.WIRECARD_LOCKED_CARD).event(CardEvents.MOBILE_CARD_FOUND).action(wirecardLockCard());


}

// @formatter:on
@Override public void configure(StateMachineConfigurationConfigurer<CardStates, CardEvents> config)
throws Exception {
config.withConfiguration().autoStartup(true).listener(new MobileCardBlockProcessEventHandler());
}

@Bean public Action<CardStates, CardEvents> findCustomer() {

return (context) -> {
context.getStateMachine().sendEvent(CardEvents.CUSTOMER_FOUND);
};

}

@Bean public Action<CardStates, CardEvents> findMobileCard() {

return (context) -> {
context.getStateMachine().sendEvent(CardEvents.MOBILE_CARD_FOUND);
};
}
}

最佳答案

您有针对 CardStates.ACTIVE_STATUSCardStates.CUSTOMER_FOUND 的事件 CardEvents.FIND_CUSTOMER。从 findCustomer() 中,您发送事件 CardEvents.CUSTOMER_FOUND,该事件与 CardEvents.FIND_CUSTOMER 不同。

改变它,我认为它应该有效。我个人认为,我更喜欢通过匿名转换和选择状态来驱动自动机器。

关于java - Spring 状态机转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43980967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com