ch02s02.html 14 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <html><head>
  2. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  3. <title>Concepts</title><link rel="stylesheet" href="boostbook.css" type="text/css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.75.2"><link rel="home" href="index.html" title="Meta State Machine (MSM)"><link rel="up" href="ch02.html" title="Chapter&nbsp;2.&nbsp;UML Short Guide"><link rel="prev" href="ch02.html" title="Chapter&nbsp;2.&nbsp;UML Short Guide"><link rel="next" href="ch02s03.html" title="Added concepts"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Concepts</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;2.&nbsp;UML Short Guide</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch02s03.html">Next</a></td></tr></table><hr></div><div class="sect1" title="Concepts"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e116"></a>Concepts</h2></div></div></div><p>Thinking in terms of state machines is a bit surprising at first, so let us
  4. have a quick glance at the concepts.</p><div class="sect2" title="State machine, state, transition, event"><div class="titlepage"><div><div><h3 class="title"><a name="d0e121"></a>State machine, state, transition, event </h3></div></div></div><p>A state machine is a concrete model describing the behavior of a system.
  5. It is composed of a finite number of states and transitions.</p><p>
  6. <span class="inlinemediaobject"><img src="../images/sm.gif"></span></p><p>A simple state has no sub states. It can have data, entry and exit
  7. behaviors and deferred events. One can provide entry and exit behaviors
  8. (also called actions) to states (or state machines), which are executed
  9. whenever a state is entered or left, no matter how. A state can also have
  10. internal transitions which cause no entry or exit behavior to be called. A
  11. state can mark events as deferred. This means the event cannot be processed
  12. if this state is active, but it must be retained. Next time a state not
  13. deferring this event is active, the event will be processed, as if it had
  14. just been fired. </p><p><span class="inlinemediaobject"><img src="../images/state.gif"></span></p><p>A transition is the switching between active states, triggered by an
  15. event. Actions and guard conditions can be attached to the transition. The
  16. action executes when the transition fires, the guard is a Boolean operation
  17. executed first and which can prevent the transition from firing by returning
  18. false.</p><p>
  19. <span class="inlinemediaobject"><img src="../images/transition.jpg"></span></p><p>An initial state marks the first active state of a state machine. It has
  20. no real existence and neither has the transition originating from it.</p><p>
  21. <span class="inlinemediaobject"><img src="../images/init_state.gif"></span></p></div><div class="sect2" title="Submachines, orthogonal regions, pseudostates"><div class="titlepage"><div><div><h3 class="title"><a name="d0e151"></a>Submachines, orthogonal regions, pseudostates </h3></div></div></div><p>A composite state is a state containing a region or decomposed in two or
  22. more regions. A composite state contains its own set of states and regions. </p><p>A submachine is a state machine inserted as a state in another state
  23. machine. The same submachine can be inserted more than once. </p><p>Orthogonal regions are parts of a composite state or submachine, each
  24. having its own set of mutually exclusive set of states and transitions. </p><p><span class="inlinemediaobject"><img src="../images/regions.gif" width="60%"></span></p><p>UML also defines a number of pseudo states, which are considered important
  25. concepts to model, but not enough to make them first-class citizens. The
  26. terminate pseudo state terminates the execution of a state machine (MSM
  27. handles this slightly differently. The state machine is not destroyed but no
  28. further event processing occurs.). </p><p><span class="inlinemediaobject"><img src="../images/terminate.gif"></span></p><p>An exit point pseudo state exits a composite state or a submachine and
  29. forces termination of execution in all contained regions.</p><p><span class="inlinemediaobject"><img src="../images/exit.gif" width="60%"></span></p><p>An entry point pseudo state allows a kind of controlled entry inside a
  30. composite. Precisely, it connects a transition outside the composite to a
  31. transition inside the composite. An important point is that this mechanism
  32. only allows a single region to be entered. In the above diagram, in region1,
  33. the initial state would become active. </p><p><span class="inlinemediaobject"><img src="../images/entry_point.gif"></span></p><p>There are also two more ways to enter a submachine (apart the obvious and
  34. more common case of a transition terminating on the submachine as shown in
  35. the region case). An explicit entry means that an inside state is the target
  36. of a transition. Unlike with direct entry, no tentative encapsulation is
  37. made, and only one transition is executed. An explicit exit is a transition
  38. from an inner state to a state outside the submachine (not supported by
  39. MSM). I would not recommend using explicit entry or exit. </p><p><span class="inlinemediaobject"><img src="../images/explicit.gif"></span></p><p>The last entry possibility is using fork. A fork is an explicit entry into
  40. one or more regions. Other regions are again activated using their initial
  41. state. </p><p><span class="inlinemediaobject"><img src="../images/fork.gif" width="70%"></span></p></div><div class="sect2" title="History"><div class="titlepage"><div><div><h3 class="title"><a name="d0e194"></a>
  42. <span class="command"><strong><a name="uml-history"></a></strong></span>History </h3></div></div></div><p>UML defines two kinds of history, shallow history and deep history.
  43. Shallow history is a pseudo state representing the most recent substate of a
  44. submachine. A submachine can have at most one shallow history. A transition
  45. with a history pseudo state as target is equivalent to a transition with the
  46. most recent substate as target. And very importantly, only one transition
  47. may originate from the history. Deep history is a shallow history
  48. recursively reactivating the substates of the most recent substate. It is
  49. represented like the shallow history with a star (H* inside a
  50. circle).</p><p>
  51. <span class="inlinemediaobject"><img src="../images/history.gif" width="60%"></span></p><p>History is not a completely satisfying concept. First of all, there can be
  52. just one history pseudo state and only one transition may originate from it.
  53. So they do not mix well with orthogonal regions as only one region can be
  54. &#8220;remembered&#8221;. Deep history is even worse and looks like a last-minute
  55. addition. History has to be activated by a transition and only one
  56. transition originates from it, so how to model the transition originating
  57. from the deep history pseudo state and pointing to the most recent substate
  58. of the substate? As a bonus, it is also inflexible and does not accept new
  59. types of histories. Let's face it, history sounds great and is useful in
  60. theory, but the UML version is not quite making the cut. And therefore, MSM
  61. provides a different version of this useful concept. </p></div><div class="sect2" title="Completion transitions / anonymous transitions"><div class="titlepage"><div><div><h3 class="title"><a name="d0e208"></a><span class="command"><strong><a name="uml-anonymous"></a></strong></span>Completion transitions / anonymous
  62. transitions</h3></div></div></div><p>Completion events (or transitions), also called anonymous transitions, are
  63. defined as transitions having no defined event triggering them. This means
  64. that such transitions will immediately fire when a state being the source of
  65. an anonymous transition becomes active, provided that a guard allows it.
  66. They are useful in modeling algorithms as an activity diagram would normally
  67. do. In the real-time world, they have the advantage of making it easier to
  68. estimate how long a periodically executed action will last. For example,
  69. consider the following diagram. </p><p><span class="inlinemediaobject"><img src="../images/completion.gif"></span></p><p>The designer now knows at any time that he will need a maximum of 4
  70. transitions. Being able to estimate how long a transition takes, he can
  71. estimate how much of a time frame he will need to require (real-time tasks
  72. are often executed at regular intervals). If he can also estimate the
  73. duration of actions, he can even use graph algorithms to better estimate his
  74. timing requirements. </p></div><div class="sect2" title="Internal transitions"><div class="titlepage"><div><div><h3 class="title"><a name="d0e220"></a><span class="command"><strong><a name="UML-internal-transition"></a></strong></span> Internal transitions </h3></div></div></div><p>Internal transitions are transitions executing in the scope of the active
  75. state, being a simple state or a submachine. One can see them as a
  76. self-transition of this state, without an entry or exit action
  77. called.</p></div><div class="sect2" title="Conflicting transitions"><div class="titlepage"><div><div><h3 class="title"><a name="d0e226"></a>
  78. <span class="command"><strong><a name="transition-conflict"></a></strong></span>Conflicting transitions </h3></div></div></div><p>If, for a given event, several transitions are enabled, they are said to
  79. be in conflict. There are two kinds of conflicts: </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>For a given source state, several transitions are defined,
  80. triggered by the same event. Normally, the guard condition in
  81. each transition defines which one is fired.</p></li><li class="listitem"><p>The source state is a submachine or simple state and the
  82. conflict is between a transition internal to this state and a
  83. transition triggered by the same event and having as target
  84. another state.</p></li></ul></div><p>The first one is simple; one only needs to define two or more
  85. rows in the transition table, with the same source and trigger, with a
  86. different guard condition. Beware, however, that the UML standard wants
  87. these conditions to be not overlapping. If they do, the standard says
  88. nothing except that this is incorrect, so the implementer is free to
  89. implement it the way he sees fit. In the case of MSM, the transition
  90. appearing last in the transition table gets selected first, if it returns
  91. false (meaning disabled), the library tries with the previous one, and so
  92. on.</p><p>
  93. <span class="inlinemediaobject"><img src="../images/conflict1.gif"></span></p><p>In the second case, UML defines that the most inner transition gets
  94. selected first, which makes sense, otherwise no exit point pseudo state
  95. would be possible (the inner transition brings us to the exit point, from
  96. where the containing state machine can take over). </p><p><span class="inlinemediaobject"><img src="../images/conflict2.gif" width="60%"></span></p><p>MSM handles both cases itself, so the designer needs only concentrate on
  97. its state machine and the UML subtleties (not overlapping conditions), not
  98. on implementing this behavior himself. </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch02s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;2.&nbsp;UML Short Guide&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Added concepts</td></tr></table></div></body></html>