30. Monitoring State Machine
StateMachineMonitor可用于获取有关转换和操作执行时间的更多信息。 下面你可以看到这个接口是如何实现的。
public class TestStateMachineMonitor extends AbstractStateMachineMonitor<String, String> {
@Override
public void transition(StateMachine<String, String> stateMachine, Transition<String, String> transition, long duration) {
}
@Override
public void action(StateMachine<String, String> stateMachine, Action<String, String> action, long duration) {
}
}
一旦你有StateMachineMonitor的实现,它可以通过配置添加到状态机中,如下所示。
@Configuration
@EnableStateMachine
public class Config1 extends StateMachineConfigurerAdapter<String, String> {
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config)
throws Exception {
config
.withMonitoring()
.monitor(stateMachineMonitor());
}
@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
states
.withStates()
.initial("S1")
.state("S2");
}
@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
transitions
.withExternal()
.source("S1")
.target("S2")
.event("E1");
}
@Bean
public StateMachineMonitor<String, String> stateMachineMonitor() {
return new TestStateMachineMonitor();
}
}
检查示例第52章,监视以了解详细用法