У меня есть один файл 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...)
Заранее спасибо народ