Spring 状态机:可能的事件
Spring State Machine: possible events
是否可以从当前状态获取可能事件的列表?
StateMachine<State, Event> stateMachine = stateMachineService.acquireStateMachine(machineId);
stateMachine.sendEvent(event);
stateMachine.getState() // get possible events from State
我找到的唯一解决方案是:
stateMachine.getTransitions().stream()
.filter(transition -> transition.getSource().getId().equals(stateMachine.getState().getId()))
.map(transition -> transition.getTrigger().getEvent())
.collect(Collectors.toList());
是否可以从当前状态获取可能事件的列表?
StateMachine<State, Event> stateMachine = stateMachineService.acquireStateMachine(machineId);
stateMachine.sendEvent(event);
stateMachine.getState() // get possible events from State
我找到的唯一解决方案是:
stateMachine.getTransitions().stream()
.filter(transition -> transition.getSource().getId().equals(stateMachine.getState().getId()))
.map(transition -> transition.getTrigger().getEvent())
.collect(Collectors.toList());