From 9c5616817b048c061be46a36bd5eeb56a73e2a50 Mon Sep 17 00:00:00 2001 From: exp_jassuncao Date: Mon, 8 Jun 2020 22:57:00 +0100 Subject: [PATCH 1/3] Fixes internal transitions for parent states The correction for issue17 resulted in internal transitions in parent states not being executed when nested states are involved. When an event is not handled by a child state but can be accepted by an internal transition in a parent state, the actions associated with the internal state should be executed but without leaving the child state. --- .../foundation/fsm/impl/TransitionImpl.java | 9 ++------- .../foundation/issues/Issue17.java | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/squirrel-foundation/src/main/java/org/squirrelframework/foundation/fsm/impl/TransitionImpl.java b/squirrel-foundation/src/main/java/org/squirrelframework/foundation/fsm/impl/TransitionImpl.java index 3cb0691d..5e9de3a7 100644 --- a/squirrel-foundation/src/main/java/org/squirrelframework/foundation/fsm/impl/TransitionImpl.java +++ b/squirrel-foundation/src/main/java/org/squirrelframework/foundation/fsm/impl/TransitionImpl.java @@ -184,16 +184,11 @@ private void doTransitInternal(ImmutableState source, ImmutableState } @Override - public void internalFire(StateContext stateContext) { - // Fix issue17 - if(type==TransitionType.INTERNAL && stateContext. - getSourceState().getStateId()!=targetState.getStateId()) { - return; - } + public void internalFire(StateContext stateContext) { if(condition.isSatisfied(stateContext.getContext())) { ImmutableState newState = stateContext.getSourceState(); if(type==TransitionType.INTERNAL) { - newState = transit(stateContext); + transit(stateContext); } else { // exit origin states unwindSubStates(stateContext.getSourceState(), stateContext); diff --git a/squirrel-foundation/src/test/java/org/squirrelframework/foundation/issues/Issue17.java b/squirrel-foundation/src/test/java/org/squirrelframework/foundation/issues/Issue17.java index 15b4946c..a3c167f9 100644 --- a/squirrel-foundation/src/test/java/org/squirrelframework/foundation/issues/Issue17.java +++ b/squirrel-foundation/src/test/java/org/squirrelframework/foundation/issues/Issue17.java @@ -15,7 +15,7 @@ public class Issue17 { enum Issue17State {A, A1, A2} - enum Issue17Event {SAME, NEXT} + enum Issue17Event {SAME, NEXT, SAME_A2} @ContextInsensitive @StateMachineParameters(stateType=Issue17State.class, eventType=Issue17Event.class, contextType=Void.class) @@ -27,6 +27,12 @@ void onA1ToA2(Issue17State from, Issue17State to, Issue17Event cause) { void onSameWithinA(Issue17State from, Issue17State to, Issue17Event cause) { logger.append("onSameWithinA"); } + void onSameWithinA2(Issue17State from, Issue17State to, Issue17Event cause) { + logger.append("onSameWithinA2"); + } + void onExitA2(Issue17State from, Issue17State to, Issue17Event cause) { + logger.append("onExitA2"); + } String consumeLog() { final String result = logger.toString(); logger = new StringBuilder(); @@ -39,7 +45,9 @@ public void testIssue17() { final UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(Issue17StateMachine.class); builder.defineSequentialStatesOn(Issue17State.A, Issue17State.A1, Issue17State.A2); builder.internalTransition().within(Issue17State.A).on(Issue17Event.SAME).callMethod("onSameWithinA"); + builder.internalTransition().within(Issue17State.A2).on(Issue17Event.SAME_A2).callMethod("onSameWithinA2"); builder.localTransition().from(Issue17State.A1).to(Issue17State.A2).on(Issue17Event.NEXT).callMethod("onA1ToA2"); + builder.onExit(Issue17State.A2).callMethod("onExitA2"); Issue17StateMachine fsm = builder.newUntypedStateMachine(Issue17State.A); fsm.addTransitionDeclinedListener(new TransitionDeclinedListener() { @@ -51,8 +59,13 @@ public void transitionDeclined( }); fsm.start(); fsm.fire(Issue17Event.NEXT); + Assert.assertEquals("onA1ToA2", fsm.consumeLog()); fsm.fire(Issue17Event.SAME); - Assert.assertTrue(fsm.consumeLog().equals("onA1ToA2")); + Assert.assertEquals(Issue17State.A2, fsm.getCurrentState()); + Assert.assertEquals("onSameWithinA",fsm.consumeLog()); + fsm.fire(Issue17Event.SAME_A2); + Assert.assertEquals(Issue17State.A2, fsm.getCurrentState()); + Assert.assertEquals("onSameWithinA2",fsm.consumeLog()); } } From 586c6dc40881374d9d728264e30e6bba21db7f58 Mon Sep 17 00:00:00 2001 From: jassuncao Date: Wed, 8 Jul 2020 16:44:11 +0100 Subject: [PATCH 2/3] Prepare release 0.3.9-RC1 --- squirrel-foundation/pom.xml | 42 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/squirrel-foundation/pom.xml b/squirrel-foundation/pom.xml index 644c1978..9cc42374 100644 --- a/squirrel-foundation/pom.xml +++ b/squirrel-foundation/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.squirrelframework squirrel-foundation - 0.3.9-SNAPSHOT + 0.3.9-RC1 bundle squirrel foundation foundation module of squirrel framework which provided event driven infrastructure and a finite state machine implementation. @@ -191,18 +191,34 @@ + + + sonatype-nexus-staging + Nexus Staging Repo + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + sonatype-nexus-snapshots + Nexus Snapshot Repo + https://oss.sonatype.org/content/repositories/snapshots + + + + unofficial + + + unofficial + true + + + + + github + GitHub Squirrel Maven Packages + https://maven.pkg.github.com/jassuncao/squirrel + + + - - - sonatype-nexus-staging - Nexus Staging Repo - https://oss.sonatype.org/service/local/staging/deploy/maven2 - - - sonatype-nexus-snapshots - Nexus Snapshot Repo - https://oss.sonatype.org/content/repositories/snapshots - - From d79d7d11415301e1c5370b41d3e5c268e0efaf9e Mon Sep 17 00:00:00 2001 From: jassuncao Date: Wed, 8 Jul 2020 16:47:58 +0100 Subject: [PATCH 3/3] Reverts to SNAPSHOT version --- squirrel-foundation/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squirrel-foundation/pom.xml b/squirrel-foundation/pom.xml index 9cc42374..1ef1c3e0 100644 --- a/squirrel-foundation/pom.xml +++ b/squirrel-foundation/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.squirrelframework squirrel-foundation - 0.3.9-RC1 + 0.3.9-SNAPSHOT bundle squirrel foundation foundation module of squirrel framework which provided event driven infrastructure and a finite state machine implementation.