【发布时间】:2019-02-17 08:15:04
【问题描述】:
假设我们有 3 个状态 S1、S3、S3 和一个错误状态 E1。 S* 状态具有分别执行 A1、A2、A3 的动作。如果 A1、A2、A3 中的任何一个导致抛出异常,则状态机应该转到 E1。有没有一种方法可以定义一个通用转换,如果任何操作引发异常,则转到 E1?还是我必须明确说明每个状态的转换
states.withStates()
.initial(START)
.end(END)
.end(ERROR)
.state(S1, A1())
.state(S2, A2())
.state(S3, A3())
//Is this the only way of defining error transition? Can I dry it up?
transitions
.withExternal()
.source(S1)
.event(ErrorEvent)
.target(E1)
.and()
.withExternal()
.source(S2)
.event(ErrorEvent)
.target(E1)
.and()
.withExternal()
.source(S3)
.event(ErrorEvent)
.target(E1)
我希望有一种方法可以以某种方式将其干燥。如果我有 10 个州,那么这样做就太重复了。
【问题讨论】:
-
我也一直在寻找解决这个问题的方法,但我找不到任何有用的东西。我认为使用 SM 配置适配器是不可能的。