Polish samples logging

- Add logging of internal transitions which makes things
  a bit more clear with showcase sample.
- Update showcase docs with clarification of use of
  nested states.
This commit is contained in:
Janne Valkealahti
2015-11-18 11:52:06 +00:00
parent 56abfab4f8
commit 07e6076e0b
2 changed files with 68 additions and 1 deletions

View File

@@ -161,10 +161,10 @@ send various event to it.
[source,text]
----
sm>sm start
Init foo to 0
Entry state S0
Entry state S1
Entry state S11
Init foo to 0
State machine started
sm>sm event A
@@ -180,6 +180,7 @@ Event C send
sm>sm event H
Switch foo to 1
Internal transition source=S0
Event H send
sm>sm event C
@@ -212,6 +213,65 @@ What happens in above sample:
variable `foo`. Then we simply go back using event _C_.
* Event _A_ is sent again and now _S1_ does a self transition because
guard evaluates true.
Let's take closer look of how hierarchical states and their event
handling works with a below example.
[source,text]
----
sm>sm variables
No variables
sm>sm start
Init foo to 0
Entry state S0
Entry state S1
Entry state S11
State machine started
sm>sm variables
foo=0
sm>sm event H
Internal transition source=S1
Event H send
sm>sm variables
foo=0
sm>sm event C
Exit state S11
Exit state S1
Entry state S2
Entry state S21
Entry state S211
Event C send
sm>sm variables
foo=0
sm>sm event H
Switch foo to 1
Internal transition source=S0
Event H send
sm>sm variables
foo=1
sm>sm event H
Switch foo to 0
Internal transition source=S2
Event H send
sm>sm variables
foo=0
----
What happens in above sample:
* We print extended state variables in various stages.
* With event _H_ we end up executing internal transition
which is logged with source state.
* It's also worth to pay attention to how event _H_ is handled in
different states _S0_, _S1_ and _S2_. This is a good example of how
hierarchical states and their event handling works. If state _S2_ is

View File

@@ -27,7 +27,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.statemachine.event.OnStateEntryEvent;
import org.springframework.statemachine.event.OnStateExitEvent;
import org.springframework.statemachine.event.OnTransitionEvent;
import org.springframework.statemachine.event.StateMachineEvent;
import org.springframework.statemachine.transition.TransitionKind;
@Configuration
public class CommonConfiguration {
@@ -64,6 +66,11 @@ public class CommonConfiguration {
} else if (event instanceof OnStateExitEvent) {
OnStateExitEvent e = (OnStateExitEvent)event;
log.info("Exit state " + e.getState().getId());
} else if (event instanceof OnTransitionEvent) {
OnTransitionEvent e = (OnTransitionEvent)event;
if (e.getTransition().getKind() == TransitionKind.INTERNAL) {
log.info("Internal transition source=" + e.getTransition().getSource().getId());
}
}
}