EA&UML日拱一卒-活动图::14.2 Behavior StateMachines (6)

来源:互联网 发布:软件项目管理发展前景 编辑:程序博客网 时间:2024/06/06 20:50

英文原文来自UML2.5,作者提供中文翻译。


14.2.3.8 Transitions(迁移)


A Transition is a single directed arc originating from a single source Vertex and terminating on a single target Vertex (the source and target may be the same Vertex), which specifies a valid fragment of a StateMachine Behavior. It may have an associated effect Behavior, which is executed when the Transition is traversed (executed).

迁移是一个从单个源顶点开始到单个目标顶点结束的单方向圆弧(源和目标可能是同一个顶点),它定义了状态机行为的一段。它可以有关联的效应行为,这个效应行为在迁移被通过(执行)的时候执行。


NOTE. The duration of a Transition traversal is undefined, allowing for different semantic interpretations, including both “zero” and non-“zero” time.

注意:通过迁移的期间是无定义的,允许有不同的语义解释,包括”0“和非"0"时间。


Transitions are executed as part of a more complex compound transition that takes a StateMachine execution from one stable state configuration to another. The semantics of compound transitions are described below.

迁移是作为更复杂的复合迁移的一部分被执行的。这个复合迁移使状态机从一个稳定状态构成执行到另一个。符合迁移的语义在后面定义。


In the course of execution, a Transition instance is said to be:

在执行的过程中,一个迁移实例被说成是:
· reached, when execution of its StateMachine execution has reached its source Vertex (i.e., its source State is in the active state configuration);

到达,当状态机执行到达它的源顶点(即,它的源状态处于活动状态构成);


· traversed, when it is being executed (along with any associated effect Behavior); and 

 通过,当它被执行(连同任何的关联效应行为)


· completed, after it has reached its target Vertex.

完成,当它到达目标顶点之后


A Transition may own a set of Triggers, each of which specifies an Event whose occurrence, when dispatched, may trigger traversal of the Transition. A Transition trigger is said to be enabled if the dispatched Event occurrence matches its Event type. When multiple triggers are defined for a Transition, they are logically disjunctive, that is, if any of them are enabled, the Transition will be triggered.

迁移可以拥有多 个触发条件,每个触发条件定义了一个事件,当事件发生被发送时,可以触发迁移的通过。如果发送的事件发生与事件类型匹配,就可以说触发条件处于有效状态。 当一个迁移定义了多个触发条件时,它们逻辑上是分离的,也就是说,只要它们中的任何一个处于有效状态,迁移就会被触发。


14.2.3.8.1 Transition kinds relative to source(与迁移源相关的迁移种类)


The semantics of a Transition depend on its relationship to its source Vertex. Three different possibilities are defined, depending on the value of the Transition’s kind attribute:

迁移的语义决定于它和它的源顶点的关系,根据迁移的种类属性的值,存在三种可能:


· kind = external means that the Transition exits its source Vertex. If the Vertex is a State, then executing this Transition will result in the execution of any associated exit Behavior of that State.

kind为external意味着迁移退出它的源顶点。如果该顶点是状态,执行这个迁移会导致那个状态所有的退出行为被执行。


· kind = local is the opposite of external, meaning that the Transition does not exit its containing State (and, hence, the exit Behavior of the containing State will not be executed). However, for local Transitions the target Vertex must be different from its source Vertex. A local Transition can only exist within a composite State.

kind为local和external相反,意味着迁移不退出包含它的状态(而且,因此,包含该迁移的状态的退出行为不会被执行)。但是对于局部迁移来讲,目标顶点必须和源顶点不同。局部迁移只能存在于组合状态中。


· kind = internal is a special case of a local Transition that is a self-transition (i.e., with the same source and target States), such that the State is never exited (and, thus, not re-entered), which means that no exit or entry Behaviors are executed when this Transition is executed. This kind of Transition can only be defined if the source Vertex is a State.

kind为internal是局部迁移的特殊情况,它是一个自迁移。(即源状态和目标状态相同),就是状态从未退出(而且也没有重新进入),它意味着当这个迁移执行的是有,没有进入和退出行为被执行。这种类型的迁移只有在源顶点是状态是才可以定义。


14.2.3.8.2 High-level (group) Transitions(高级(组)迁移)


Transitions whose source Vertex is a composite States are called high-level or group Transitions. If they are external, group Transitions result in the exiting of all substates of the composite State, executing any defined exit Behaviors
starting with the innermost States in the active state configuration. In case of local Transitions, the exit Behaviors of the source State and the entry Behaviors of the target State will be executed, but not those of the containing State.

如果迁移的源顶点为组合状态,那么称 之为高级或组迁移。如果是外部迁移,组迁移的结果是退出组合状态的所有子状态,从活动状态构成最内层状态开始执行所有定义了的退出行为。如果是局部迁移, 迁移源状态的退出迁移和迁移目标状态的进入行为将会被执行,包含它们的状态退出迁移和进入迁移则不会被执行。


14.2.3.8.3 Completion Transitions and completion events(完成迁移和完成事件)


A special kind of Transition is a completion Transition, which has an implicit trigger. The event that enables this trigger is called a completion event and it signifies that all Behaviors associated with the source State of the completion
Transition have completed execution. In case of simple States, a completion event is generated when the associated entry and doActivity Behaviors have completed executing. If no such Behaviors are defined, the completion event is generated upon entry into the State. For composite or submachine States, a completion event is generated under the following circumstances:

完成迁移是一种特殊的迁 移,它拥有一个隐含的触发条件。激活这个触发条件的事件被称为完成事件,它表示所有所有与完成迁移的源状态关联的行为都已经完全地被执行。在简单状态的情 况下,当关联的进入和doActivity行为结束执行时会生成一个完成事件。如果上述行为没有被定义,完成事件在进入状态时生成。对于组合或者子状态机 状态,完成事件在下列情况下产生:


· All internal activities (e.g., entry and doActivity Behaviors) have completed execution, and

所有的内部活动(即,进入和doActivity行为)已经执行完毕,而且


· if the State is a composite State, all its orthogonal Regions have reached a FinalState, or

如果是组合状态,那么它的所有正交区域都已经执行到完了状态,或者


· if the State is a submachine State, the submachine StateMachine execution has reached a FinalState. 

如果是子状态机状态,那么子状态机已经执行到完了状态。


Completion events have dispatching priority. That is, they are dispatched ahead of any pending Event occurrences in the event pool. If two or more completion events corresponding to multiple orthogonal Regions occur simultaneously (i.e., as a result of the same Event occurrence), the order in which such completion occurrences are processed is not defined. Completion of all top level Regions in a StateMachine corresponds to a completion of the Behavior of the StateMachine and results in its termination.

完成事件有优先发送权。也就是说,它们在事件池中等待处理的所有事件发生之前被发送。如果有两个或多个完成事件对 应同时执行的多个正交区域(即都是同一个事件发生的结果),这些完成事件被处理的顺序无定义。一个状态机中所有的最顶层区域的完成对应状态机的行为的完成 并且导致状态机的终止。


Transition guards (迁移监护条件)


A Transition may have an associated guard Constraint. Transitions that have a guard which evaluates to false are disabled. Guards are evaluated before the compound transition that contains them is enabled, unless they are on Transitions that originate from a choice Pseudostate. In the latter case, the guards are evaluated when the choice point is reached. A Transition that does not 

have an associated guard is treated as if it has a guard that is always true. 

迁移有一个关联的监护约束。如果迁移的监护条件的演算结果为假,则迁移无效。监护条件在包含它的复合迁移有效之前进行演算,除非它们属于源自选择伪状态的迁移。在后面的情况中,监护条件在迁移到选择点时进行演算。没有监护条件的迁移被看作是拥有一个永远为真的监护条件。


NOTE. A completion Transition may also have a guard.

完成迁移也可以有监护条件。


A guard constraint may involve tests of orthogonal States of the current StateMachine, or explicitly designated States of some reachable object (for example, “in State1” or “not in State2”). State names may be fully qualified by the nested States and Regions that contain them, yielding pathnames of the form “RegionA::State1::Region1::State2::State3”. This may be used in case the same State name occurs in different composite State Regions.

监护约束可以包含对当前状态机的正交状态,或者是某些可访问对象的明确设计的状态(例如”处于状态1“,或 者"不处于状态2“)进行检查。状态名可以被嵌套状态和包含它们的区域完全地限定,这时得到的是 “RegionA::State1::Region1::State2::State3”形式的路径名称。这种方法可以在不同组合状态区域中存在相同的状 态名称时使用。


14.2.3.8.4 Compound transitions(复合迁移)


As noted earlier, when an Event occurrence triggers an enabled Transition or a StateMachine execution is created, this can initiate traversal of a set of connected and nested Transitions and Vertices until a stable state configuration is
reached. In the general case, a trace of this traversal, known as a compound transition, can be represented by an acyclical directed graph. The root  (source) of this graph can be one of the following:

像前面说明的那样,当一个事件触发了一个有效的迁移,或者生成了一个状态机执行,就可以开始一 组相连和嵌套的迁移和顶点的遍历,直至到达了某个稳定状态构成。在通常的情况下,这个遍历的踪迹,就是所谓的复合迁移,可以被表现为一个非循环的,定向的 图。这个图的根(源)可以下列中的某一个:


· A Transition with one or more Triggers defined.

拥有一个或多个触发条件的迁移。


· A completion Transition.

完成迁移。


· A set of Transitions (including, possibly, completion Transitions) originating from different orthogonal Regions that converge on a common join Pseudostate.

从来自不同的正交区域聚集到共同的汇合伪状态上的一组迁移(可能包括完成迁移)


· A Transition originating from an initial Pseudostate of the topmost Region (i.e., a Region owned by the StateMachine); this variant applies only to cases when the StateMachine instance is created.

始于最顶层区域中的初始伪状态的迁移(即被状态机拥有的区域);这个变体只适用于状态机实例被创建的情况。


Branching in a compound transition execution occurs whenever an executing Transition performs a default entry into a State with multiple orthogonal Regions, with a separate branch created for each Region, or when a fork Pseudostate is encountered. The overall behavior that results from the execution of a compound transition is a partially ordered set of executions of Behaviors associated with the traversed elements, determined by the order in which the elements (Vertices and Transitions) are encountered. For example, if a Transition entering a compound State terminates on a substate of that State, then the effect Behavior of the Transition would be executed before the execution of the entry Behavior of the compound State, followed by the entry Behavior of the substate. If a fork Pseudostate is encountered in the traversal, then the effect Behaviors of the individual outgoing branches are, at least conceptually, executed concurrently with each other.

当执行中的迁移 以默认方式进入到一个包含多个正交区域的状态时为每个区域生成了一个单独的分支,或者遇到了分叉伪状态,都可以说复合迁移的执行发生了分支行为。复合迁移 执行的全部行为是一组部分有序的与遍历经过的元素关联的行为的执行,次序由到达元素(顶点和迁移)的顺序决定。例如,如果进入复合状态的迁移终止于该状态 的子状态,那么迁移的效应行为将会在复合状态的进入行为之前,子状态的进入行为之后执行。如果在迁移过程中遇到了分叉伪状态,那么每个离开分支的效应行 为,至少从概念上是同时执行的。


If a choice or join point is reached with multiple outgoing Transitions with guards, a Transition whose guard evaluates to true will be taken. If more than one guard evaluates to true, one of these Transitions is chosen for continuing the traversal. The algorithm for making this selection is undefined. In case of Transitions originating from a choice Pseudostate, if no guards evaluate to true when the Pseudostate is reached, the model is ill formed.

如果到达的选择或汇合点拥有多个带有监护条件的离开迁移,那么监护条件的演算结果为真的迁移会被选中。如果结果为真的监护条件超过一个,其中的一个会被选中。做出这种选择的算法无定义。当迁移离开一个选择伪状态,如果没有结果为真的监护条件,那么模型是病态的。


14.2.3.8.5 Transition ownership(迁移所有权)


The owner of a Transition is not explicitly constrained, though the Region in which it is contained must be owned directly or indirectly by the owning StateMachine. A suggested owner of a Transition is the innermost Region that
contains both its source and target Vertices. 

虽然包含它的区域直接或间接地被状态机拥有,但是迁移的所有者没有被明确地要求。一个推荐的拥有者是包含它的源顶点和目的顶点的最内层区域。


参考资料:

《OMG Unified Modeling Language TM (OMG UML) Version 2.5》

  URL:http://www.omg.org/spec/UML/2.5

阅读更多更新文章,请扫描下面二维码,关注微信公众号【面向对象思考】