0

我有一个最初采用这种方式的 scxml 文件

<?xml version="1.0" ?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="s1">
    <state id="s1">
        <transition event="s1.success" target="s2"/>
        <transition event="s1.failure" target="failure"/>
    </state>
    <state id="s2">
        <transition event="s2.success" target="s3"/>
        <transition event="s2.failure" target="failure"/>
    </state>
    <state id="s3">
        <transition event="s3.success" target="s4"/>
        <transition event="s3.failure" target="failure"/>
    </state>
    <state id="s4">
        <transition event="s4.success" target="s5"/>
        <transition event="s4.failure" target="failure"/>
    </state>
    <state id="s5">
        <transition event="s5.success" target="s6"/>
        <transition event="s5.failure" target="failure"/>
    </state>
    <state id="s6">
        <transition event="s6.success" target="s7"/>
        <transition event="s6.failure" target="failure"/>
    </state>
    <state id="s7">
        <transition event="s7.success" target="s8"/>
        <transition event="s7.failure" target="failure"/>
    </state>
    <state id="s8">
        <transition event="s8.success" target="s9"/>
        <transition event="s8.failure" target="failure"/>
    </state>
    <state id="s9">
        <transition event="s9.success" target="success"/>
        <transition event="s9.failure" target="failure"/>
    </state>
    <final id="success" />
    <final id="failure" />
</scxml>

并在这些状态下执行,我有一个像这样的java代码

SCXMLExecutor engine = new SCXMLExecutor();
engine.setRootContext(SCXML statemachine);
engine.setStateMachine(new JexlContext());

engine.go();     // This line triggers the events of statechart file and all the events are executed sequentially

现在,我正在尝试引入一些并行性并将 scxml 文件更改为如下所示

<?xml version="1.0" ?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="s1">
    <parallel id = "Parallel>
        <state id = "Issue_1">
            <state id="s1">
                <transition event="s1.success" target="s2"/>
                <transition event="s1.failure" target="failure"/>
            </state>
            <state id="s2">
                <transition event="s2.success" target="s3"/>
                <transition event="s2.failure" target="failure"/>
            </state>
            <state id="s3">
                <transition event="s3.success" target="s4"/>
                <transition event="s3.failure" target="failure"/>
            </state>
            <state id="s4">
                <transition event="s4.success" target="s5"/>
                <transition event="s4.failure" target="failure"/>
            </state>
            <state id="s5">
                <transition event="s5.success" target="s6"/>
                <transition event="s5.failure" target="failure"/>
            </state>
        </state>
        <state id = "Issue_2">
            <state id="s6">
                <transition event="s6.success" target="s7"/>
                <transition event="s6.failure" target="failure"/>
            </state>
            <state id="s7">
                <transition event="s7.success" target="s8"/>
                <transition event="s7.failure" target="failure"/>
            </state>
            <state id="s8">
                <transition event="s8.success" target="s9"/>
                <transition event="s8.failure" target="failure"/>
            </state>
            <state id="s9">
                <transition event="s9.success" target="success"/>
                <transition event="s9.failure" target="failure"/>
            </state>
        </state>
    </parallel>
    <final id="success" />
    <final id="failure" />
</scxml>

现在,我在执行这些并行包含的状态 Issue_1 和 Issue_2 时遇到了一些麻烦。

我试过的

if("parallel".equals(stateId)) {
            
            List<EnterableState> states = ((TransitionalState) entered).getChildren();

            // Above list gives me all the children states inside parallel. Like Issue_1, Issue_2
            for(EnterableState s: states) {
                 
                 SCXMLExecutor engine = new SCXMLExecutor();
                 engine.setRootContext(SCXML statemachine);
                 engine.setStateMachine(new JexlContext());

                 engine.go()
           }
}

但这从根状态开始,我无法按顺序或并行运行像 Issue_1 和 Issue_2 这样的父状态。

我尝试使用

stateMachine.setInitial(s.getId()); **This did not work**

我期望知道什么?

  • 实现并行可执行状态机的巧妙方法是什么
  • 或者,至少,我怎样才能从给定状态启动 SCXMLExecutor(如 "Issue_1" ... )

先谢谢各位

4

0 回答 0