Skip to content

Commit

Permalink
send durin parallel is broken in scxml0.9, dont fire events on send i…
Browse files Browse the repository at this point in the history
…n parallel
  • Loading branch information
LeroyR committed Jun 6, 2024
1 parent 2ceb518 commit ae194ee
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,16 @@ public boolean fireEventFromSkill(final String event) {
TriggerEvent evts = new TriggerEvent(event, TriggerEvent.SIGNAL_EVENT);
try {
logger.debug("FIRE SKILL Event: " + event);
logger.trace("All Current states:");
if (logger.isTraceEnabled()) for(Object s : scxmlExecutor.getCurrentStatus().getAllStates()) {
if (s instanceof State) {
State state = (State) s;
logger.trace("- " + state.getId());
} else {
logger.trace(s);
}

}
//checkEventTransitions(event);
scxmlExecutor.triggerEvent(evts);
} catch (ModelException me) {
Expand Down Expand Up @@ -702,7 +712,7 @@ private void actionCheck(List<Action> actions) {
+ ((Send) a).getEvent());
//Somehow we dont always execute event actions and fire events?
//So we just fire manually
fireEvent(((Send) a).getEvent());
//fireEvent(((Send) a).getEvent());
//checkEventTransitions(((Send) a).getEvent());
} else if (a instanceof Assign) {
Assign action = (Assign) a;
Expand Down Expand Up @@ -732,10 +742,15 @@ private void actionCheck(List<Action> actions) {
public void onEntry(final TransitionTarget entered) {

logger.debug("#OnEntry: " + entered.getId());
logger.trace("Current states:");
if (logger.isTraceEnabled()) for(Object s : scxmlExecutor.getCurrentStatus().getStates()) {
State state = (State) s;
logger.trace("- " + state.getId());
logger.trace("All Current states:");
if (logger.isTraceEnabled()) for(Object s : scxmlExecutor.getCurrentStatus().getAllStates()) {
if (s instanceof State) {
State state = (State) s;
logger.trace("- " + state.getId());
} else {
logger.trace(s);
}

}
logger.debug(this.scxmlExecutor.getCurrentStatus().toString());
actionCheck(entered.getOnEntry().getActions());
Expand Down Expand Up @@ -806,13 +821,21 @@ public void onExit(final TransitionTarget exited) {
if (exited instanceof Parallel) {
Parallel parallel = (Parallel) exited;
logger.trace("exited is instance of parallel " + exited.getId());
this.pauseMachine();
for (Object s : parallel.getChildren()) {
if (s instanceof TransitionTarget) {
TransitionTarget t = (TransitionTarget) s;

StateID stateId = new StateID(statePrefix, t.getId());
stopAndRemoveState(stateId, true);
}
}
// Removing all active states to be sure
Set<StateID> keys = new HashSet<>(activeStates.keySet());
for (StateID key : keys) {
stopAndRemoveState(key, true);
}
this.continueStateMachine();
} else {
logger.trace("exited is not parallel " + exited.getId() + " "
+ exited.getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,28 @@ public void testOptionalParameter() throws TransformerException, TimeoutExceptio
assertTrue(TestTools.testStatemachine(conf, sm, test));
}

// @Test
// public void testParallelWorking() throws TransformerException, TimeoutException {
// final String sm = "parallelWorking.xml";
// final String conf = "TestConfig.xml";
//
// LoadingResults res = TestTools.loadStatemachine(sm);
// assertTrue(res.success());
//
// TestListener test = TestListener.newEndFatal();
// assertTrue(TestTools.testStatemachine(conf, sm, test));
// }
//
// @Test
// public void testParallelBugged() throws TransformerException, TimeoutException {
// final String sm = "parallelBugged.xml";
// final String conf = "TestConfig.xml";
//
// LoadingResults res = TestTools.loadStatemachine(sm);
// assertTrue(res.success());
//
// TestListener test = TestListener.newEndFatal();
// assertTrue(TestTools.testStatemachine(conf, sm, test));
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="init">
<datamodel>
<data id="#_STATE_PREFIX" expr="'de.unibi.citec.clf.bonsai.skills.'"/>
<data id="condition1" expr="false"/>
<data id="condition2" expr="false"/>
<data id="condition3" expr="false"/>
</datamodel>

<state id="init" initial="Nop#init">
<state id="Nop#init">
<transition event="Nop.fatal" target="Parallel"/>
</state>
</state>

<parallel id="Parallel">
<onentry>
<assign name="condition1" expr="false"/>
<assign name="condition2" expr="false"/>
<assign name="condition3" expr="false"/>
</onentry>

<!-- Transitions that leave parallel have to be defined on the parallel state -->
<transition event="strand.done" cond="condition1 and condition2 and condition3" target="Wait#After"/>

<state id="stand1" initial="Nop">
<state id="Nop">
<transition event="Nop.fatal">
<assign name="condition1" expr="true"/>
<send event="strand.done"/>
</transition>
</state>
</state>

<state id="stand2" initial="Wait">
<state id="Wait">
<datamodel>
<data id="#_TIMEOUT" expr="'1000'"/>
</datamodel>
<transition event="Wait.*" target="Wait#dummy">
<assign name="condition2" expr="true"/>
</transition>
</state>

<state id="Wait#dummy">
<datamodel>
<data id="#_TIMEOUT" expr="'100'"/>
</datamodel>
<transition event="Wait.*"/>
</state>
</state>

<state id="srand3" initial="Wait2">
<state id="Wait2">
<datamodel>
<data id="#_TIMEOUT" expr="'2000'"/>
</datamodel>
<transition event="Wait2.success">
<assign name="condition3" expr="true"/>
<send event="strand.done"/>
</transition>
<transition event="Wait2.fatal"/>
</state>
</state>


</parallel>

<state id="Wait#After">
<transition event="Wait.*" target="End"/>
</state>

<state id="Fatal" final="true"/>

<state id="End" final="true"/>
</scxml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="init">
<datamodel>
<data id="#_STATE_PREFIX" expr="'de.unibi.citec.clf.bonsai.skills.'"/>
<data id="condition1" expr="false"/>
<data id="condition2" expr="false"/>
<data id="condition3" expr="false"/>
</datamodel>

<state id="init" initial="Nop#init">
<state id="Nop#init">
<transition event="Nop.fatal" target="Parallel"/>
</state>
</state>

<parallel id="Parallel">
<onentry>
<assign name="condition1" expr="false"/>
<assign name="condition2" expr="false"/>
<assign name="condition3" expr="false"/>
</onentry>

<!-- Transitions that leave parallel have to be defined on the parallel state -->
<transition event="strand.done" cond="condition1 and condition2 and condition3" target="Wait#After"/>

<state id="Nop">
<transition event="Nop.fatal">
<assign name="condition1" expr="true"/>
<send event="strand.done" delay="1000"/>
</transition>

</state>

<state id="Wait">
<datamodel>
<data id="#_TIMEOUT" expr="'1000'"/>
</datamodel>
<transition event="Wait.success">
<assign name="condition2" expr="true"/>
<send event="strand.done" delay="1000"/>
</transition>
<transition event="Wait.fatal"/>
</state>

<state id="Wait2">
<datamodel>
<data id="#_TIMEOUT" expr="'10000'"/>
</datamodel>
<transition event="Wait2.success">
<assign name="condition3" expr="true"/>
<send event="strand.done" delay="1000"/>
</transition>
<transition event="Wait2.fatal"/>
</state>
</parallel>

<state id="Wait#After">
<transition event="Wait.success" target="End"/>
<transition event="Wait.fatal"/>
</state>

<state id="Fatal" final="true"/>

<state id="End" final="true"/>
</scxml>

0 comments on commit ae194ee

Please sign in to comment.