我正在运行一个分层的Spring状态机,在遍历初始转换到状态之后,默认子状态停止,我想使用statemachine.getState()
.问题是,它只给了我父状态,我找不到一个明显的方法来检索父状态和子状态.
机器有states个这样的 struct :
StateMachineBuilder.Builder<ToolStates, ToolEvents> builder = StateMachineBuilder.builder();
builder.configureStates()
.withStates()
.initial(ToolStates.UP)
.state(ToolStates.UP, new ToolUpEventAction(), null)
.state(ToolStates.DOWN
.and()
.withStates()
.parent(ToolStates.UP)
.initial(ToolStates.STOPPED)
.state(ToolStates.STOPPED,new ToolStoppedEventAction(), null )
.state(ToolStates.IDLE)
.state(ToolStates.PROCESSING,
new ToolBeginProcessingPartAction(),
new ToolDoneProcessingPartAction());
...
builder.build();
ToolStates
和ToolEvents
只是枚举.在客户机类中,在运行上面的构建器代码之后,当我随后调用statemachine.getState().getId();
时,statemachine以statemachine.start();
启动,它给我UP
.在该调用之前,没有向statemachine发送任何事件.
希望这是一件非常明显的事情...
欢迎任何建议!