State machine transition

A transition represents a change in the state of the machine, it is defined by an event id, an eventual condition, an eventual set of actions to perform, and usually a next state.

Each state can have any number of transitions.

Normal transition

A normal transition is when the next exists and it is not the current state.

Let's have a look at the traffic light state machine:

Suppose the current state is Yellow and the event EvTimerYellow is triggered. A transition begins from the state Yellow to Red:

  1. Set the current state from Yellow to null
  2. Execute the onExit content of the state Yellow, it turns the yellow light off and stop the yellow timer.
  3. Execute the eventual action content of the transition, in this case, nothing.
  4. Execute the onEntry content of the state Red, it turns the red light on and start the red timer.
  5. Set the current state to the Red.

Self transition

An self transition is when the next state is itself, in this case, onExit and onEntry are executed.

Internal transition

An internal transition is when the next state is not present, in this case, onExit and onEntry are not executed.

Actions

When present, actions in a transition are executed upon receiving an event. To be precise, actions are executed after the onExit but before the onEntry

Actions can be defined in the action attribute:

Actions can be also defined with an action element:

Furthermore, actions can be defined as a sequence of action elements:

Condition

A condition can be added so that the transition is triggered only when the event is received and the condition is true.

The condition can also be as an element, this is useful when the condition contains character such as the double quote, which cannot be present in an attribute:

In some cases where some symbols such as &, < and > are used, the condition must be placed inside CDATA element:

Transition order

Multiple transitions can have the same event, but beware that the transition order depends of the condition strength. The transition without guard, if any, must be the last one.