石墨消解仪后端服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.8 KiB

  1. package com.iflytop.gd.app.config;
  2. import com.iflytop.gd.common.enums.CraftEvents;
  3. import com.iflytop.gd.common.enums.CraftStates;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.statemachine.config.EnableStateMachineFactory;
  6. import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
  7. import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
  8. import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
  9. import java.util.EnumSet;
  10. @Configuration
  11. @EnableStateMachineFactory
  12. public class CraftsStateMachineConfig
  13. extends StateMachineConfigurerAdapter<CraftStates, CraftEvents> {
  14. @Override
  15. public void configure(StateMachineStateConfigurer<CraftStates, CraftEvents> states) throws Exception {
  16. states
  17. .withStates()
  18. .initial(CraftStates.READY)
  19. .states(EnumSet.allOf(CraftStates.class));
  20. }
  21. @Override
  22. public void configure(StateMachineTransitionConfigurer<CraftStates, CraftEvents> trans) throws Exception {
  23. trans
  24. // 启动
  25. .withExternal()
  26. .source(CraftStates.READY)
  27. .target(CraftStates.RUNNING)
  28. .event(CraftEvents.START)
  29. .and()
  30. // 单步完成(保持 RUNNING)
  31. .withInternal()
  32. .source(CraftStates.RUNNING)
  33. .event(CraftEvents.STEP_COMPLETE)
  34. .and()
  35. // 暂停
  36. .withExternal()
  37. .source(CraftStates.RUNNING)
  38. .target(CraftStates.PAUSED)
  39. .event(CraftEvents.PAUSE)
  40. .and()
  41. // 恢复
  42. .withExternal()
  43. .source(CraftStates.PAUSED)
  44. .target(CraftStates.RUNNING)
  45. .event(CraftEvents.RESUME)
  46. .and()
  47. // 用户手动停止:RUNNING → STOPPED
  48. .withExternal()
  49. .source(CraftStates.RUNNING)
  50. .target(CraftStates.STOPPED)
  51. .event(CraftEvents.STOP)
  52. .and()
  53. // 用户手动停止:PAUSED → STOPPED
  54. .withExternal()
  55. .source(CraftStates.PAUSED)
  56. .target(CraftStates.STOPPED)
  57. .event(CraftEvents.STOP)
  58. .and()
  59. // 出错
  60. .withExternal()
  61. .source(CraftStates.RUNNING)
  62. .target(CraftStates.ERROR)
  63. .event(CraftEvents.ERROR_OCCUR)
  64. .and()
  65. // 正常完成
  66. .withExternal()
  67. .source(CraftStates.RUNNING)
  68. .target(CraftStates.FINISHED)
  69. .event(CraftEvents.FINISH);
  70. }
  71. }