• Non ci sono risultati.

5.2 Generic Sequence Diagram

5.2.1 Conditional message

Given a SD sdi representing an interaction i∈ Interaction, a conditional message m ∈ i.message is a message whose associated action actx = m.action is characterized by a recurrence expression expr = actx.recurrence.body specified in a given language actx.recurrence.language. UML does not prescribe the language to be used for the specification of the expressions; we make then the following choice:

Interpretation 3 The language used for the specification of recurrence expressions is a C-like pseudo-code.

The recurrence expression expr conditions the action execution stating how many times action actx should be performed. We distinguish two types of recurrence expressions: the first type contains a condition clause, the action can be be performed at most one time and hence at most one message is sent; the second type contains an iteration clause, the action can be performed n, n∈ IN times and hence n messages can be sent. Actually a condition clause is an iteration clause restricted to a single occurrence. The graphical representation of a conditional message is shown in Figure 5.3: on the top left a message with conditional clause is shown, while on the top right a message with iteration clause is depicted.

Whether the action actx is executed or not depends on the evaluation at run-time of the recurrence expres-sion expr that may contain variables of the objects of the system. As our purpose is to perform static analysis evaluation of recurrence expressions is resolved probabilistically following the approach described in [2].

A conditional message m with condition clause is characterized by a recurrence expression expr of type:

IF <cond> <m specification>

where <cond> is the condition clause to be evaluated and <m specification> represents the execution of the action actx that causes the message m to be sent. Figure 5.3, bottom left, shows the corresponding revised translation of message m into LGSPN if the condition clause is not a tautology (i.e., <cond>6≡ true): the subnet of the original translationLSm= (Smmm) (see Definition 5) representing the communication specification (i.e., synchronous-asynchronous and delayed-instantaneous) is replaced with a rectangle with rounded corners since it remains unchanged. Also the sets of source and sink places (i.e., SOU RCEmand SINKm, respectively) are the same as forLSm; but with respect to LSm, a transition t11 is added, with input set equal to SOU RCEm

and with output set equal to SINKm, to represent the case in which the message is not sent because the condition

[cond]m /rj:cj /rl:cl

... ...

*[cond]m

/rj:cj /rl:cl

... ...

IF <cond> <m specification> WHILE <cond> <m specification>

Condition expression: Iteration expression:

SOURCEm

t1

SINKm t11

<m specification>

SOURCEm

t1

SINKm t11

<m specification>

Figure 5.3: Translation of a conditional message m into a LGSPN.

<cond> is not satisfied. Formally:

Definition 6 The LGSPN LS0m = (S0m0m0m) representing a conditional message with condition clause

<cond > is characterized by the set of transitions Tm0 = Tm∪ Θ(<cond >≡ true) {t11}, where Tm is the set of transitions defined forLSm(Definition 5). The input and output functions are defined as:

Im0(t) =





SOU RCEm if t = t11

Im(t) otherwise O0m(t) =





SINKm if t = t11

Om(t) otherwise

where Im(t), Om(t) are the input and output functions, respectively, defined forLSm. The weight function and the transition labeling function are defined as:

CHAPTER 5. TRANSLATION OF SEQUENCE DIAGRAMS 113

Wm0(t) =













pc if t = t1 1− pc if t = t11

Wm(t) otherwise

λ0m(t) =





τ if t = t11 λm(t) otherwise

where pc is a weight parameter specifying the probability that condition <cond > is satisfied and Wm(t) is the weight function defined forLSm. The set of places Pm0 and the functions Fm0 ={Π0m, Hm0, M0m00m} remain unchanged with respect to the translation defined for a non-conditional message (Definition 5).

To assign a value to the weight parameter pc we conform to the UML Profile for Schedulability, Performance and Time Specification [65]: indeed, when the conditional message m is stereotyped asPAstep it is possible to specify, through the associated tag PAprob, the probability that the communication will occur. In absence of the tag we can assign by default an equal weight to transitions t1and t11:

Enrichment 2 If the conditional message m is stereotyped asPAstep and the tag PAprob is associated to it, then pc = PAprob else pc = 0.5.

Observe that the LGSPN translation of a conditional message with condition clause being tautology is exactly the same translation obtained for a non-conditional message, or, vice-versa, a non-conditional message is a conditional message with a condition clause being a tautology.

A conditional message m with iteration clause is characterized by a recurrence expression expr of type:

W HILE <cond> <m specification>

where <cond > is the iteration clause to be evaluated and <m specification> represents the execution of the action actx that causes the message m to be sent. Figure 5.3, bottom right, shows the corresponding revised translation of message m into LGSPN if the iteration clause is not a tautology: the difference with respect to LS0mdefined in the previous case (Definition 6) is the addition of an output arc to the transition that represents either the termination of the execution of action actx or the consumption of the caused event by the state machine of the receiver. Formally:

Definition 7 The LGSPN LS00m = (S00m00m00m) representing a conditional message with iteration clause

<cond> is characterized by the set of transitions Tm00= Tm0, where Tm0 is the set of transitions defined forLS0m

(Definition 6). The output function is defined as:

O00m(t) =





SOU RCEm if t∈Θ(Asn){t3} ∪ Θ(Asn)h

∆(Timem){T3} ∪ ∆(Timem){t2}i O0m(t) otherwise

where O0m(t) is the output function defined forLS0m.

The set of places Pm00 and the functions Fm00={Π00m, Im00, Hm00,Wm00, M0m0000m00m} remain unchanged with respect to the translation defined for a conditional message with condition clause (Definition 6).

According to the UML Profile for Schedulability, Performance and Time Specification [65], message m can be stereotyped asPAstep in order to use the associated tag PArep that allows to specify the number of times the step is repeated.

Enrichment 3 If the conditional message m is stereotyped asPAstep and the tag PArep is associated to it, then pc = PArep+1PArep , else pc = 0.5.

Observe that when the iteration clause is a tautology, i.e., the recurrence expression is a while-true statement, then the corresponding translated LGSPN results into a cycle and the sink place is an isolated place.