持久化到内存hashmap中
实现StateMachinePersist接口,并通过实现write和read方法,然后构造DefaultStateMachinePersister bean
FSMStateMachinePersist 实现接口 StateMachinePersist
package com.wtx.springboot2.statemachine;
import org.springframework.statemachine.StateMachineContext;
import org.springframework.statemachine.StateMachinePersist;
import org.springframework.statemachine.support.DefaultStateMachineContext;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @Author wtx
* @Date 2019/6/2
*/
@Component
public class FSMStateMachinePersist implements StateMachinePersist<FSMStates, FSMEvents, Integer> {
static Map<Integer, FSMStates> cache = new HashMap<>(16);
@Override
public void write(StateMachineContext<FSMStates, FSMEvents> stateMachineContext, Integer integer) throws Exception {
cache.put(integer, stateMachineContext.getState());
}