spring-statemachine

Spring State Machine - Attaching static data to states

孤者浪人 提交于 2020-05-07 08:17:49
问题 With spring state machine, we have states and events. I could not find any documentation on whether it is possible to attach static data to a state during configuration. For example, if there are the states S1 and S2 public void configure(StateMachineStateConfigurer<String, String> states) throws Exception { states.withStates() .initial("INIT") .end("END") .state("S1", null, exitAction()) .state("S2", entryAction()); } If we could attach static data during the above configuration (like a java

How to get exception thrown during state transition using spring state machine

China☆狼群 提交于 2020-01-24 17:42:07
问题 I am trying to understand, how an exception thrown by an action during a state transition is possible. I‘ve this simple state machine configured: transitions .withExternal() .source(State.A1) .target(State.A2) .event(Event.E1) .action(executeAnActionThrowingAnException()) In my service class, I injected my state machine and send this event E1: @Service public class MyService() { @Autowired private StateMachine<State, Event> stateMachine; public void executeMyLogic() { stateMachine.start()

Unable to Trigger an Event from Action

瘦欲@ 提交于 2019-12-24 07:48:49
问题 I am setting up spring state-machine transactions, i want to launch Event2 on completion of Event1 These are the states i have States -> "INITIAL", "SECOND", "THIRD" I have configured the transactions to send SECOND_EVENT from action of FIRST_EVENT as shown below transitions.withExternal() .source("INITIAL") .target("SECOND") .event("FIRST_EVENT") .action(new Action<String, String>() { @Override public void execute(StateContext<String, String> context) { System.out.println("FIRST_ACTION

The right way to reload and restart State Machine with different data set

 ̄綄美尐妖づ 提交于 2019-12-24 00:45:33
问题 I need the same SM to serve various records from the same db-table (can't create SM per each record). Would this be appropriate way to reinitialize SM with new states from another record OR can you advice a better approach please ? public static <S, E> void reinitStateMachine(Integer key, IStateMachineEnabledService sees, StateMachine<S, E> stateMachine, Class<? extends Enum> statesClazz) { String dbReadState; try { dbReadState = sees.findStateById(key); } catch (Exception e) { throw new

Persisting & Restoring Current State in Spring Statemachine

喜欢而已 提交于 2019-12-23 10:59:19
问题 I'm introducing Spring Statemachine into an existing project, with the hope of amalgamating and clarifying our business logic. We have various JPA entities with interconnected states and I'm having some trouble with setting a persisted state as the current state of an existing state machine. I'm using a StateMachineFactory to create a new StateMachine instance for each entity instance. I'm storing the current state of the StateMachine in a separate field for Hibernate to persist and ideally

Spring StateMachine - Configure from Database

寵の児 提交于 2019-12-22 01:01:21
问题 In all examples I have looked up online, the StateMachine is configured statically @Override public void configure(StateMachineTransitionConfigurer<BookStates, BookEvents> transitions) throws Exception { transitions .withExternal() .source(BookStates.AVAILABLE) .target(BookStates.BORROWED) .event(BookEvents.BORROW) .and() .withExternal() .source(BookStates.BORROWED) .target(BookStates.AVAILABLE) .event(BookEvents.RETURN) .and() .withExternal() .source(BookStates.AVAILABLE) .target(BookStates

[Spring]Spring-Statemachine 状态机

て烟熏妆下的殇ゞ 提交于 2019-12-19 13:03:19
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 介绍 Spring状态机为程序开发员提供了传统状态机和Spring应用程序使用,有以下特性: 易于使用的状态机的用例 层次的状态机结构缓解复杂状态机的配置 状态机提供更复杂的配置状态 使用触发器、转移、警卫以及动作 类型安全的配置适配器 状态机的事件监听器 IOC将状态机和bean整合 名词解释 State Machine 将状态结合、转移、事件整合到一起 State 一个不变的状态模型 主要由一个事件修改实体的状态 Extended State 扩展状态是一组特殊的变量保存在一个状态机来减少所需的数据量。 Transition 源状态和目标状态之间的关系,它可能是复合过度的一部分,将状态机配置从一个状态到另一个地方,响应状态机的一个特定类型的事件的发生。 Event 一个实体发送一个状态驱动各个状态的变化 Initial State 状态机特殊的开始状态. 初始状态标记在一个状态或者一个区域上. 一个状态的多个区域都可能回到初始状态 End State 一种最终状态,一种特殊的状态表示完成封闭区域,如果封闭区域直接包含在一个状态机状态机和其他地区也完成了,然后它意味着整个状态机完成。 History State 伪状态可以记住它的最后活动的状态, 存在两种类型历史状态. Choice State

BeanNotOfRequiredTypeException when using spring-statemachine and spring cloud slueth

匆匆过客 提交于 2019-12-13 06:40:19
问题 I am currently developing a microservice using spring-boot.I currently have an issue when using spring-state machine and spring-cloud-sleuth artifacts together. @Validated @RestController @SuppressWarnings({"squid:S00112"}) @RequestMapping() public class StatusController { @Autowired private QuoteService quoteService; @Autowired private StateMachine<StateMachineDefinition.States, StateMachineDefinition.Events> stateMachine; @Autowired private QuoteStateHandler quoteStateHandler; @Value("$

Spring Statemachine Forks

时间秒杀一切 提交于 2019-12-11 05:26:36
问题 I have made good progress with the state machines upto now. My most recent problem arised when I wanted to use a fork, (I'm using UML). The fork didn't work as it is supossed to and I think its because of the persistance. I persist my machine in redis. refer below image. This is my top level machine where Manage-commands is a Sub machine Reference And the top region is as it is. Now say I persisted some state in redis, from the below region, and next an ONLINE event comes, then the machine

Spring State Machine Error Handling not working

落爺英雄遲暮 提交于 2019-12-11 02:24:33
问题 I did all the setup for error handling @PostConstruct public void addStateMachineInterceptor() { stateMachine.getStateMachineAccessor().withRegion().addStateMachineInterceptor(interceptor); stateMachine.getStateMachineAccessor().doWithRegion(errorinterceptor); } created interceptor to handle error: @Service public class OrderStateMachineFunction<T> implements StateMachineFunction<StateMachineAccess<String, String>> { @Override public void apply(StateMachineAccess<String, String>