Completion transitions

Completion transitions enable a transition to occur automatically when a state’s activities are completed or when all of its child states have completed their activities. This means that instead of explicitly triggering a transition with an explicit event, completion transitions are triggered internally by the implicit completion event which is derived from the completion status of the state or its children. This can be very helpful in situations where the statechart models activity sequences or processes which can terminate or complete. Completions transitions are typically used with composite states which contain regions whith behavior that completes with a final states. Composite state which have only final states as active substates are considered as completed. Completion transitions react to completion events which indicate that the state completed. Let’s take a look at the following example.

The example defines a state Complex Task which controls a process consisting of two parallel activities A and B represented by the two subregions. As soon as both activities are finished by entering their final states then Complex Task becomes completed and a completion event is raised which triggers the completion transition to Done state. Completion transition by definition have no trigger and no guard but may define a transition action. This example also shows that leaf states (non composite states) like state Step A can define completion transitions. Here the local completion transition to the final state is automatically taken without any delay. This is useful if a sequence of steps which follow each other immediately and unconditionally should be modeled. So completion transitions help in modeling processes and activities using state machines.

Beyond this example there are several other details you should know about completions transitions. Completion transitions are immediately taken when the transition’s source state is " completed" and they have priority over any other events, thus they are dispatched before any other pending event occurrences in the event pool.
This also means that these kinds of transitions implicitly raises completion events, which are raised and consumed throughout the statechart’s execution (and with that, they are present in the code generated from it).

A state is considered completed when all of its entry actions are executed (if there are any). A Composite states is considered completed when all of its subregions reach their final state . This means completion transitions can only be used with composite states if all subregions contain a final state.

Completion transitions can’t be used with source states that contain local reactions. Those states do not complete and adding a completion transition is considered as an error. A validation check will add a error message: “Completion transition is not allowed with local reactions”.

Defining other transitions with trigger(s) from the same leaf state as the completion transition will raise a warning with a message: “Dead transition. This transition can not be taken due to completion transition.” This is because these will never be taken due to the precedence of the completion transition. Also defining multiple completion transitions from the same state will result in a warning for both transitions with the message: "Multiple completion transition. There should be only one completion transition from state ..."

This feature is compatible with OMG UML 2.5.1 specification. (For more details please see the corresponding documentation under chapter