In a UML2 state chart, how to model a condition that might already be active or is triggered?

494 views Asked by At

I am designing a state machine using UML2 statecharts.

There is an embedded "controller" state machine, which in the state WAITING_FOR_CONNECTION is waiting for an online connection to be established. The entire connection handling is performed in a second "communication" state machine.

When the controller enters the WAITING_FOR_CONNECTION state, and the connection is not yet established, it just waits for the trigger "connectionEstablished" to initiate the corresponding state transition. But what if the online connection is already available? There will be no trigger fired, and a guard on the connection status won't help, because the guard is evaluated once on a trigger only.

One solution I can think of is to have two transitions to the same target state: One default transition without explicit trigger but with a guard "isOnline", and one transition with trigger "connectionEstablished". A rather clumsy solution, I think.

What I am looking for is a "level trigger" instead of the usual "edge trigger" semantics. Does the UML2 state chart specification provide for such a trigger type? Comparable with then "when" condition in Modelica, for example. The controller would enter the WAITING_FOR_CONNECTION state and transition when the online connection became available.

2

There are 2 answers

0
Clifford On BEST ANSWER

You can use a null triggered transition. This is a transition with no tigger and only a guard, the guard in this case being "[isConnected]". The semantics are:

Null-triggered transitions trigger immediately upon completion of any actions-on-entry.

Bruce Powell-Douglass

Note that the trigger is evaluated only on entry, a second completeion transition or explicit connect/ transition is necessary for change-of-state. See slide 72 in the Bruce Powell-Douglass link above for an example.

Alternatively you could have a choice pseudo-state before the wait state that bypasses it if already connected. This differs from the null trigger in that no entry actions are performed, but if you have none in any case it will behave in the same manner.

0
Vladimir On

If no trigger is defined for transition it represents completion transition. Completion transition is automatically triggered by object which own state machine, after active state from which transition starts finished. Your problem would be solved by using guards on transition. You can use two transitions with the same trigger, but provide guard to both of them. Transition is fired if trigger correspond to event AND condition is fulfilled. The second solution could use CHOOSE element (similar to decision in activity). Incoming transition to choose should have trigger (if not defined it is completion transition again), and two or more outgoing transitions provide with guards to direct proper state. Outgoing transitions mus have not triggers ! For example outgoing transition with guard [isOnline == false] direct to WAITING_FOR_CONNECTION state. etc.

See diagram below:

enter image description here