2016-09-22 107 views
0

我倾向于SSM,打击是我的演示配置:Spring Statemachine is statefull?

@Override 
    public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception { 
     config.withConfiguration() 
       .autoStartup(true) 
       .listener(listener()); 
    } 

    @Override 
    public void configure(StateMachineStateConfigurer<States, Events> states) throws Exception { 
     states.withStates() 
       .initial(States.S_1) 
       .state(States.S_1, myAction(), null) 
       .end(States.S_END) 
       .states(EnumSet.allOf(States.class)); 
    } 

    @Override 
    public void configure(StateMachineTransitionConfigurer<States, Events> transitions) throws Exception { 
     transitions 
       .withExternal() 
       .source(States.S_1).target(States.S_2).event(Events.E1).action(myAction()); 
    } 

我发送两个事件的机器,但它onece运行。

stateMachine.sendEvent(Events.E1); 
stateMachine.sendEvent(Events.E1); 

ssm是否有状态,我该如何让它运行无状态?

我只是想用它来定义我的业务流程。

回答

2

那么它看起来像事件E1将机器从S_1S_2。由于机器已处于状态S_2并且从S_1S_2的转换不能发生,因此再次发送该事件将不起作用。

不确定你的意思是使机器无状态?

+0

我的意思是我想要SSM定义我的业务程序,如“创建一个订单”,需要首先保存订单信息数据库,第二次发送订单确定电子邮件,第三个nofify处理器流程订单。如果创建另一个订单,它将运行相同的过程。但是,如果状态机改变了状态,它就不能这样做。 – gpengtao

1

状态机是有状态的目标是要在保存状态的反应......和事件确实状态变化......

我觉得你的情况,你可能不希望一个状态机,但一个“简单”的服务层