-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec1ee55
commit 5f4dd40
Showing
11 changed files
with
181 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
fsm/src/main/java/top/atluofu/fsm/config/OrderPersistHandlerConfig.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
fsm/src/main/java/top/atluofu/fsm/config/OrderStateMachineFactoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package top.atluofu.fsm.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.statemachine.config.EnableStateMachineFactory; | ||
import org.springframework.statemachine.config.StateMachineConfigurerAdapter; | ||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer; | ||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer; | ||
import top.atluofu.fsm.model.Events; | ||
import top.atluofu.fsm.model.States; | ||
|
||
/** | ||
* @ClassName: OrderStateMachineFactoryConfig | ||
* @description: OrderStateMachineFactoryConfig | ||
* @author: 有罗敷的马同学 | ||
* @datetime: 2023Year-12Month-01Day-8:36 | ||
* @Version: 1.0 | ||
*/ | ||
@Configuration | ||
@EnableStateMachineFactory(name = "orderStateMachineFactory") | ||
public class OrderStateMachineFactoryConfig extends StateMachineConfigurerAdapter<String, String> { | ||
@Override | ||
public void configure(StateMachineStateConfigurer<String, String> states) | ||
throws Exception { | ||
states.withStates() | ||
.initial(States.ORDER_WAIT_PAY.toString()) | ||
.state(States.ORDER_WAIT_SEND.toString()) | ||
.state(States.ORDER_WAIT_RECEIVE.toString()) | ||
.end(States.ORDER_FINISH.toString()); | ||
} | ||
|
||
@Override | ||
public void configure(StateMachineTransitionConfigurer<String, String> transitions) | ||
throws Exception { | ||
transitions.withExternal() | ||
.source(States.ORDER_WAIT_PAY.toString()) | ||
.target(States.ORDER_WAIT_SEND.toString()) | ||
.event(Events.PAY_ORDER.toString()) | ||
.and() | ||
.withExternal() | ||
.source(States.ORDER_WAIT_SEND.toString()) | ||
.target(States.ORDER_WAIT_RECEIVE.toString()) | ||
.event(Events.SEND_ORDER.toString()) | ||
.and() | ||
.withExternal() | ||
.source(States.ORDER_WAIT_RECEIVE.toString()) | ||
.target(States.ORDER_FINISH.toString()) | ||
.event(Events.RECEIVE_ORDER.toString()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
fsm/src/main/java/top/atluofu/fsm/config/OrderStatePersistConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package top.atluofu.fsm.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.ConfigurableBeanFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.statemachine.StateMachine; | ||
import org.springframework.statemachine.config.StateMachineFactory; | ||
import org.springframework.statemachine.recipes.persist.PersistStateMachineHandler; | ||
import top.atluofu.fsm.listener.OrderStatePersistChangeListener; | ||
|
||
/** | ||
* @ClassName: OrderStatePersistConfig | ||
* @description: OrderStatePersistConfig | ||
* @author: 有罗敷的马同学 | ||
* @datetime: 2023Year-12Month-01Day-8:53 | ||
* @Version: 1.0 | ||
*/ | ||
@Configuration | ||
public class OrderStatePersistConfig { | ||
@Autowired | ||
private StateMachineFactory<String, String> orderStateMachineFactory; | ||
@Autowired | ||
private OrderStatePersistChangeListener persistStateChangeListener; | ||
|
||
@Bean | ||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) | ||
public PersistStateMachineHandler getPersistStateMachineHandler() { | ||
StateMachine<String, String> orderStateMachine = orderStateMachineFactory.getStateMachine(); | ||
PersistStateMachineHandler handler = new PersistStateMachineHandler(orderStateMachine); | ||
handler.addPersistStateChangeListener(persistStateChangeListener); | ||
return handler; | ||
} | ||
|
||
} |
74 changes: 0 additions & 74 deletions
74
fsm/src/main/java/top/atluofu/fsm/config/StateMachineConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.