當前位置:首頁 > 芯聞號 > 充電吧
[導讀] 英文原文來自UML2.5,作者提供中文翻譯。 14.2.3.9 Event Processing for StateMachines(狀態(tài)機事件處理) 14.2.3.9.1 The ru

英文原文來自UML2.5,作者提供中文翻譯。


14.2.3.9 Event Processing for StateMachines(狀態(tài)機事件處理)


14.2.3.9.1 The run-to-completion paradigm(執(zhí)行到完成樣式)


The processing of Event occurrences by a StateMachine execution conforms to the general semantics defined in Clause 13. Upon creation, a StateMachine will perform its initialization during which it executes an initial compound transition prompted by the creation, after which it enters a wait point. In case of StateMachine Behaviors, a wait point is represented by a stable state configuration. It remains thus until an Event stored in its event pool is dispatched. This Event is evaluated and, if it matches a valid Trigger of the StateMachine and there is at least one enabled Transition that can be triggered by that Event occurrence, a single StateMachine step is executed. A step involves executing a compound transition and terminating on a stable state configuration (i.e., the next wait point). This cycle then repeats until either the StateMachine completes its Behavior or until it is asynchronously terminated by some external agent.

狀態(tài)機執(zhí)行對于事件發(fā)生的處理符合 在13節(jié)中定義的通常語義。創(chuàng)建之后,狀態(tài)機將會執(zhí)行初期化動作,在這個動作中它會執(zhí)行一個由創(chuàng)建引起的初始復合遷移,然后它進入等待點。在狀態(tài)機行為的 場景,等待點通過穩(wěn)定狀態(tài)構成來表現(xiàn)。這種狀態(tài)一直維持直到保存在事件池中的事件被發(fā)送。這個事件被處理處理,如果它與狀態(tài)機的有效的觸發(fā)條件相匹配而且 至少有一個有效的遷移可以被那個事件發(fā)生觸發(fā),狀態(tài)機會執(zhí)行一步。這一步會啟動執(zhí)行一個復合遷移并停止于一個穩(wěn)定狀態(tài)構成(即下一個等待點)。重復這個循 環(huán)直至狀態(tài)機完成了它的行為或者它被某些外部的代理者異步終止。


StateMachines can respond to any of the Event types described in Clause 13 as well as to completion events (see above).

狀態(tài)機可以對13節(jié)中描述的任何事件類型或者完成事件(是參見前面)做出反應。


NOTE. As explained above, completion events have priority and will be dispatched ahead of any pending Event occurrences in the event pool.

注意:前面講到過,完成事件擁有更高的優(yōu)先級,會在事件池中等待處理的事件之前被發(fā)送。


Event occurrences are detected, dispatched, and processed by the StateMachine execution, one at a time.

事件發(fā)生被狀態(tài)機執(zhí)行檢測,發(fā)送和處理,一次一個。


NOTE. The order of event dispatching is left undefined, allowing for varied scheduling algorithms.

事件發(fā)送的順序沒有定義,允許不同的調度算法。


This cycle is referred to as the run-to-completion paradigm, and the corresponding StateMachine step is called a run-to-completion step. Run-to-completion means that, in the absence of exceptions or asynchronous destruction of the context Classifier object or the StateMachine execution, a pending Event occurrence is dispatched only after the processing of the previous occurrence is completed and a stable state configuration has been reached. That is, an Event occurrence will never be dispatched while the StateMachine execution is busy processing the previous one. This behavioral paradigm was chosen to avoid complications arising from concurrency conflicts that may arise when a StateMachine tries to respond to multiple concurrent or overlapping events.

這個循環(huán)被稱為執(zhí)行到完成樣式,對應的狀態(tài)機步驟被成為執(zhí)行到完成步驟。執(zhí)行到完成意味著,除非發(fā) 生例外,或者異步析構一個上下文類目或狀態(tài)機執(zhí)行,等待中的事件發(fā)生只有在前一次事件發(fā)生處理完成而且到達了穩(wěn)定狀態(tài)構成時才能被發(fā)送。也就是說,在狀態(tài) 機執(zhí)行正忙于處理前一個事件時,另一個事件發(fā)生永遠不會被發(fā)送。選擇這個行為樣式是為了避免當狀態(tài)機響應多個并發(fā)或重疊的事件時引起并發(fā)沖突而導致的復雜 度上升。


When an Event occurrence is detected and dispatched, it may result in one or more Transitions being enabled for firing.If no Transition is enabled and the corresponding Event type is not in any of the deferrableTriggers lists of the active state configuration, the dispatched Event occurrence is discarded and the run-to-completion step is completed trivially.

當一個事件發(fā)生被檢測并發(fā)送,它可能導致一個或多個有效的遷移被觸發(fā)。如果沒有遷移處于有效狀態(tài)而且相應的事件類型不在活動狀態(tài)構成的任何一個可延期觸發(fā)條件列表中,發(fā)送的事件發(fā)生被拋棄,該執(zhí)行到完成步驟結束而不做任何事情。


Due to the presence of orthogonal Regions, it is possible that multiple Transitions (in different Regions) can be triggered by the same Event occurrence. The order in which these Transitions are executed is left undefined. Each
orthogonal Region in the active state configuration that does not contain nested orthogonal Regions (i.e., a “bottomlevel” Region) can fire at most one Transition as a result of the current Event occurrence. When all orthogonal Regions have finished executing the Transition, the current Event occurrence is fully consumed, and the run-to-completion step is completed.

由于正交區(qū)域的存在,可能有(處于不同區(qū)域的)多個遷移被同一 個事件發(fā)生觸發(fā)。遷移被執(zhí)行的次序沒有被定義。作為當前事件的結果,處于活動狀態(tài)構成中的每個不含嵌套正交區(qū)域的正交區(qū)域(即底層區(qū)域)可以觸發(fā)至多一個 遷移。當所有的正交區(qū)域的遷移執(zhí)行都已經(jīng)結束,當前的事件發(fā)生被完全消費,該執(zhí)行到完成步驟結束。


As mentioned above, it is possible for multiple mutually exclusive Transitions in a given Region to be enabled for firing by the same Event occurrence. In those cases, only one is selected and executed. Which of the enabled Transitions is chosen is determined by the Transition selection algorithm described below.

如上面所講,在一個給定的區(qū)域中,可能有多個互斥的遷移變?yōu)橛行Ф鴾蕚浔煌粋€事件發(fā)生觸發(fā)。在這種情況下,只有一個被選中而執(zhí)行。哪個有效遷移會被選中決定于下面描述的選擇算法。


During a Transition, a number of actions Behaviors may be executed. If such a Behavior includes a synchronous invocation call on another object executing a StateMachine, then the Transition step is not completed until the invoked
object method completes its run-to-completion step.?

在遷移過程中,可以有一系列的動作行為被執(zhí)行。如果這樣一個行為包括一個對另外一個使用狀態(tài)機的對象的同步調用,那么遷移步驟直到被調用的對象方法結束后,它的執(zhí)行到完成步驟之后才會結束。


Run-to-completion may be implemented in various ways. For active Classes, it may be realized by an event-loop running in its own thread, and that reads event occurrences from a pool. For passive Classes it may be implemented
using a monitor.

執(zhí)行到完成可以通過不同的方式實現(xiàn)。對于主動類,可以通過它自己線程內(nèi)部的事件循環(huán)來實現(xiàn),并且通過它從池中讀取事件發(fā)生。對于被動類,可以通過監(jiān)視者實現(xiàn)。


IMPLEMENTATION NOTE. Run-to-completion is often mistakenly interpreted as implying that an executing StateMachine cannot be interrupted, which, of course would lead to priority inversion issues in some time-sensitive systems. However, this is not the case; in a given implementation a thread executing a StateMachine step can be suspended, allowing higher-priority threads to run, and, once it is allocated processor time again by the underlying thread scheduler, it can safely resume its execution and complete its event processing.

實現(xiàn)注意事項:執(zhí)行到完成通常被錯誤的解釋,認為執(zhí)行中的狀態(tài)機不能被中 斷,因此會在某些時間敏感的系統(tǒng)中導致優(yōu)先級倒置的問題。但實際上不會發(fā)生那樣的情況;對于一個給定的實現(xiàn),執(zhí)行狀態(tài)機步驟的線程可以被阻塞,允許高優(yōu)先 級的線程執(zhí)行,而且,當?shù)讓拥木€程調度再次為其分配處理時間時,可以安全地恢復執(zhí)行并完成它的事件處理。


14.2.3.9.2 Enabled Transitions(有效遷移)


A Transition is enabled if and only if:

遷移只有在下列情況才是有效的:


? All of its source States are in the active state configuration.

它所有的源狀態(tài)都處于活動狀態(tài)構成中。


? At least one of the triggers of the Transition has an Event that is matched by the Event type of the dispatched Event occurrence. In case of Signal Events, any occurrence of the same or compatible type as specified in the Trigger will match. If one of the Triggers is for an AnyReceiveEvent, then either a Signal or CallEvent satisfies this Trigger, provided that there is no other Signal or CallEvent Trigger for the same Transition or any other Transition having the same source Vertex as the Transition with the AnyReceiveEvent trigger (see also 13.3.1).

至少有一個遷移的觸發(fā)條件得到了通過分發(fā)的事件發(fā)生的事件類型匹配的事件。在單個事件的情況下,任何被觸發(fā)條件定義的相同 或兼容類型的事件發(fā)生都會被匹配。如果有一個對象為AnyReceiveEvent的觸發(fā)條件,那么信號或調用事件都可以滿足這個觸發(fā)條件,只要同一個遷 移沒有其他的信號或事件觸發(fā)條件,同時沒有其他的同源遷移具有AnyReceiveEvent觸發(fā)條件(參見13.3.1)。


? If there exists at least one full path from the source state configuration to either the target state configuration or to a dynamic choice Pseudostate in which all guard conditions are true (Transitions without guards are treated as
if their guards are always true).

如果存在至少一個完整路徑從源狀態(tài)構成到目標狀態(tài)構成或者監(jiān)護條件為真的動態(tài)選擇偽狀態(tài)(沒有監(jiān)護條件的遷移被認為監(jiān)護條件永遠為真)


As more than one Transition may be enabled by the same Event occurrence, being enabled is a necessary but not sufficient condition for the firing of a Transition.

可以有多于一個遷移因為同一個事件變成有效狀態(tài),所以變成有效狀態(tài)是觸發(fā)遷移的必要條件而不是充分條件。


14.2.3.9.3 Conflicting Transitions(遷移沖突)


It is possible for more than one Transition to be enabled within a StateMachine. If that happens, then such Transitions may be in conflict with each other. For example, consider the case of two Transitions originating from the same State, triggered by the same event, but with different guards. If that event occurs and both guard conditions are true, then at most one of those Transitions can fire in a given run-to-completion step.

在一個狀態(tài)機中可能存在多個有效的遷移。如果這樣的情況發(fā)生了,那么這些遷移就可能彼此沖 突。例如,考慮發(fā)源于同一個狀態(tài)的兩個遷移的情況,它們接受同一個事件,但是有著不同的監(jiān)護條件。如果那個事件發(fā)生并且兩個監(jiān)護條件的結果都為真,那么在 一個給定的執(zhí)行到完成步驟中至多有一個遷移被觸發(fā)。


Two Transitions are said to conflict if they both exit the same State, or, more precisely, that the intersection of the set of States they exit is non-empty. Only Transitions that occur in mutually orthogonal Regions may be fired simultaneously. This constraint guarantees that the new active state configuration resulting from executing the set of Transitions is well formed.

如果兩個遷移都源于同一個狀態(tài),或者更加準確地講,它們的源狀態(tài)集合之間有交集,就可以說它們彼此沖突。只有發(fā)生于彼此正交的區(qū)域中的遷移可以被同時觸發(fā)。這個約束保證一組遷移執(zhí)行以后新的活動狀態(tài)構成是結構良好的。


An internal Transition in a State conflicts only with Transitions that cause an exit from that State.

狀態(tài)中內(nèi)部遷移只會和引起狀態(tài)退出的遷移發(fā)生沖突。


14.2.3.9.4 Firing priorities(觸發(fā)優(yōu)先級)


In situations where there are conflicting Transitions, the selection of which Transitions will fire is based in part on an implicit priority. These priorities resolve some but not all Transition conflicts, as they only define a partial ordering. The priorities of conflicting Transitions are based on their relative position in the state hierarchy. By definition, a Transition originating from a substate has higher priority than a conflicting Transition originating from any of its containing States.

在存在沖突遷移的情況下,哪個遷移被觸發(fā)某種程度上有隱含的優(yōu)先級決定的。因為只定義了部分的順序, 所以這個優(yōu)先級只可以解決某些但不是全部的遷移沖突。沖突遷移的優(yōu)先級決定于它們在狀態(tài)層級中的相對位置。根據(jù)定義,起源于子狀態(tài)的遷移的優(yōu)先級要高于與 之沖突的,起源于包含那個子狀態(tài)的狀態(tài)的遷移。


The priority of a Transition is defined based on its source State. The priority of Transitions chained in a compound transition is based on the priority of the Transition with the most deeply nested source State.

遷移的優(yōu)先級取決于它的源狀態(tài)。復合遷移中的遷移鏈的優(yōu)先級決定于有著最深嵌套層級的源狀態(tài)。


In general, if t1 is a Transition whose source State is s1, and t2 has source s2, then:

通常情況下,如果t1是源自狀態(tài)s1的遷移,t2是源自狀態(tài)s2的遷移,那么:

? If s1 is a direct or indirectly nested substate of s2, then t1 has higher priority than t2.

如果s1直接或間接地被嵌套于s2,那么t1的優(yōu)先級高于t2.
? If s1 and s2 are not in the same state configuration, then there is no priority difference between t1 and t2.

如果s1和s2沒有處于同一個狀態(tài)構成,那么t1,t2的優(yōu)先級相同。


14.2.3.9.5 Transition selection algorithm(遷移選擇算法)


The set of Transitions that will fire are the Transitions in the Regions of the current state configuration that satisfy the following conditions:

在當前狀態(tài)構成的區(qū)域中滿足下列條件的遷移集合將會被觸發(fā):


? All Transitions in the set are enabled.

所有屬于集合的遷移都處于有效狀態(tài)


? There are no conflicting Transitions within the set.

集合中沒有沖突遷移


? There is no Transition outside the set that has higher priority than a Transition in the set (that is, enabled Transitions with highest priorities are in the set while conflicting Transitions with lower priorities are left out).

集合外不存在優(yōu)先級高于集合內(nèi)遷移的遷移(也就是說,具有最高優(yōu)先級的有效遷移都在集合里而優(yōu)先級較低的沖突遷移留在了集合外邊)。

This can be implemented by a greedy selection algorithm, with a straightforward traversal of the active state configuration. States in the active state configuration are traversed starting with the innermost nested simple States and
working outwards. For each State at a given level, all originating Transitions are evaluated to determine if they are enabled. This traversal guarantees that the priority principle is not violated. The only non-trivial issue is resolving
Transition conflicts across orthogonal States on all levels. This is resolved by terminating the search in each orthogonal State once a Transition inside any one of its components is fired.?

這可以通過使用貪心算法直接遍歷活動狀態(tài)構成來實 現(xiàn)。可以從最內(nèi)層嵌套的簡單狀態(tài)開始向外,遍歷活動狀態(tài)構成中的狀態(tài)。對于給定層級的每個狀態(tài),所有的初始遷移都被確認以決定是否有效。這個遍歷保證優(yōu)先 級規(guī)則不會被違反。唯一有意義的問題是解決所有層次中跨越正交狀態(tài)的遷移沖突。這個問題是這樣解決的:只要狀態(tài)的任何一個元素中的遷移被觸發(fā),就停止正交 狀態(tài)中的搜索。


14.2.3.9.6 Transition execution sequence(遷移執(zhí)行順序)


Every Transition, except for internal and local Transitions, causes exiting of a source State, and entering of the target State. These two States, which may be composite, are designated as the main source and the main target of a Transition respectively.

除了內(nèi)部或局部遷移的所有遷移,都會引起退出源狀態(tài)和進入目標狀態(tài)。這兩個狀態(tài),可能是組合狀態(tài),被分別定義為總起源狀態(tài)和總目標狀態(tài)。


The main source is a direct substate of the Region that contains the source States, and the main target is the substate of the Region that contains the target States.

總起源狀態(tài)是包含源狀態(tài)的區(qū)域的直接子狀態(tài),而總目標狀態(tài)是包含所有目標狀態(tài)的區(qū)域的子狀態(tài)。


NOTE. A Transition from one Region to another in the same immediate enclosing composite State is not allowed.

注意:從處于直接屬于同一個組合狀態(tài)的一個區(qū)域遷移到另一個區(qū)域是不允許的。


Once a Transition is enabled and is selected to fire, the following steps are carried out in order:

當一個遷移處于有效狀態(tài)并被選中而觸發(fā),下面的步驟被按順序執(zhí)行:

1 Starting with the main source State, the States that contain the main source State are exited according to the rules of State exit (or, composite State exit if the main source State is nested) as described earlier.

從總起源狀態(tài)開始,包含總起源狀態(tài)的狀態(tài)根據(jù)狀態(tài)的退出規(guī)則退出(或者如果總起源狀態(tài)是被嵌套的,那么包含它的組合狀態(tài)退出)。


2 The series of State exits continues until the first Region that contains, directly or indirectly, both the main source and main target states is reached. The Region that contains both the main source and main target states is called their least common ancestor. At that point, the effect Behavior of the Transition that connects the subconfiguration of source States to the sub-configuration of target States is executed. (A “sub-configuration” here refers to that subset of a full state configuration contained within the least common ancestor Region.)

一系列的狀態(tài)退出動作繼續(xù)執(zhí)行直至到達同時包含(直接或間接)總起源狀態(tài)和總目標狀態(tài)的區(qū)域。同時包含總起源狀態(tài)和總目標 狀態(tài)的區(qū)域被稱作它們的最小共同祖先。這時,連接源狀態(tài)子構成和目標狀態(tài)子構成的遷移的效應行為被執(zhí)行。(子構成在這里指的是完整的狀態(tài)構成中被最小共同 祖先區(qū)域包含的那部分。)


3 The configuration of States containing the main target State is entered, starting with the outermost State in the least common ancestor Region that contains the main target State. The execution of Behaviors follows the rules
of State entry (or composite State entry) described earlier.?

包含總目標狀態(tài)的狀態(tài)構成的進入動作,從包含總目標狀態(tài)的最小共同祖先區(qū)域中的最外層狀態(tài)開始。這些行為的執(zhí)行遵守前面定義的狀態(tài)進入(或組合狀態(tài)進入)的原則。


This transition execution algorithm is illustrated by the StateMachine example in Figure 14.2. In this case, when event “sig” is dispatched while the StateMachine is in State “S11” (the main source), the following sequence of actions will
be executed:

遷移執(zhí)行算法通過圖14.2中的狀態(tài)機例子來說明。在這個例子中,當狀態(tài)機處于狀態(tài)S11(總起源狀態(tài))時,事件“sig"被發(fā)送,動作將會按照下面的順序被執(zhí)行:

xS11; t1; xS1; t2; eT1; eT11; t3; eT111


參考資料:

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

? URL:http://www.omg.org/spec/UML/2.5
閱讀更多更新文章,請掃描下面二維碼,關注微信公眾號【面向對象思考】


本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或將催生出更大的獨角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯(lián)合牽頭組建的NVI技術創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術創(chuàng)新聯(lián)...

關鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉