• Nem Talált Eredményt

• For each unmapped edgeu0 z

0

→ v0 ofRHS, a new link identifiereis picked and removed from the unused model element universe, then a linka →e bof typet(z0)is assigned to pattern edge u0 z

0

→ v0 by matchingmRHS in a source and target object preserving way, and finally, it is added to the set of inserted links∆EM+, formally,

∀u0z0 v0 ∈ERHS\ELHS,∃e∈UN U :

e /∈U0N U∧t(z0) =t(e)∧mRHS

u0 z

0

→v0

=a→e b∧a→e b∈∆EM+.

• When all the inserted links are collected, they are added to modelM, formally, EM0 =EMc∪∆EM+.

Definition 22 Given a metamodelM M, and a matchingmfor a rulerin modelM,ruleris applied to the matching m in the model M yielding the derived model M0, (denoted by M =r,m⇒ M0) if deletion and insertion phases are executed in this order, and derived modelM0 is a well-formed instance of metamodelM M.

In the above definition, the well-formedness of the derived model is prescribed as a right application condition [37]. In practice, this means that effects of rule application have to be rolled back, if the derived model is not well-formed e.g., due to multiplicity constraint failure, or the existence of parallel edges of the same type.

When modeling complex systems, naturally, more than a single graph transformation rule is re-quired. A graph transformation system encapsulates a set of rules, which can be applied during the evolution of the system model.

Definition 23 Agraph transformation systemSGT = (M M, R)is a tuple that consists of the meta-modelM M, and the set of graph transformation rulesR.

Definition 24 Given a graph transformation systemSGT = (M M, R), agraph transformation run is a sequence of rule applications (denoted asMI =⇒Mn), which starts from an initial modelMIand which applies rules from the setR.

3.2 Modeling a distributed mutual exclusion algorithm

In this section, another running example describing a distributed mutual exclusion algorithm (with full specification in [60]) is specified by graph transformation. Compared to the object-relational mapping, this algorithm represents a different application scenario, in which the dynamic semantics of a visual language is defined by means of graph transformation in an operational way. The dissimilar application criteria and environment of this algorithm and its later reuse in this thesis are arguments for introducing a second running example.

In this domain, processes try to access shared resources. One requirement of the algorithm is that each resource may be accessed by at most one process at a time. This is achieved by using a token ring of processes. In the consecutive phases of the algorithm, a process may issue a request on a resource, the resource may eventually be held by a process, and finally, a process may release the resource. The right to access a resource is modeled by a token. The algorithm also contains a deadlock detection procedure, which has to track the processes that are blocked.

26 CHAPTER 3. COMPUTING BY GRAPH TRANSFORMATION

(a) Metamodel for the mutual exclusion problem

(b) A sample instance model

Figure 3.4: Metamodel and model for the mutual exclusion problem

3.2.1 Metamodels and instance models

The metamodel of the mutual exclusion problem is depicted in Fig. 3.4(a). It has only two classes:

ProcessandResource. Links of typenextorganize processes into a ring. The access right of a process to a resource is symbolized by the associationtoken. Associationsreleaseorrequestshow if a process releases or requests for a resource, respectively. A resource may also beheld_bya process. Links of typeblockedexpress if processes are directly or indirectly blocked by an already used resource. No inheritance is specified in the figure.

A well-formed instance model of this domain is shown in Fig. 3.4(b). It has four processes (p1

top4) and four links (n1ton4) of typenext, which organize processes into a ring. Four resources (r1

tor4) also appear in the model. Each resource is held by a separate process, which can be expressed by the four edges of typeheld_by(h1toh4) connecting the resources to the corresponding processes.

Furthermore, the instance model of Fig. 3.4(b) obviously satisfies all multiplicity constraints of the metamodel.

3.2.2 Graph transformation rules

The distribute mutual exclusion algorithm can be described by 13 graph transformation rules as pre-sented in Fig. 3.5.

(a) NewRule (Fig. 3.5(a)) searches for two consecutive processes p1 andp2 in the token ring, and places a new processpin betweenp1andp2.

(b) KillRule(Fig. 3.5(b)) searches for three consecutive processesp1,p, andp2in the token ring, and removes processpfrom the middle.

(c) MountRule(Fig. 3.5(c)) seeks for a processp, creates a new resourcer, and gives the initial access right (modeled by atokenlink) of resourcerto processp.

(d) UnmountRule(Fig. 3.5(d)) tries to find a processp, which has atokenfor resourcer, and removes the resource from the system.

(e) PassRule(Fig. 3.5(e)) gives the access right of processp1for resourcerto the following process

p2in the token ring, if processp1has not yet issued a request for resourcer.

3.2. MODELING A DISTRIBUTED MUTUAL EXCLUSION ALGORITHM 27

Figure 3.5: Rules describing the mutual exclusion algorithm

28 CHAPTER 3. COMPUTING BY GRAPH TRANSFORMATION

(f) RequestRule (Fig. 3.5(f)) expresses that if resourceris not yet held by processp, and processp

has not issued a request for any other resources, then it requires resourcer.

(g) TakeRule(Fig. 3.5(g)) gives access to a resourcerfor processp(expressed by aheld_byedge from

rtop), if processprequested for such a resourcer, for which it already had access right (i.e., a

token) as well.

(h) ReleaseRule(Fig. 3.5(h)) replaces theheld_byedge connecting resourcerto processpby arelease

edge, if processphas no requests for any resources.

(i) GiveRule(Fig. 3.5(i)) passes the token for a resourcerreleased by processp1to the next process

p2in the token ring.

(j) BlockedRule (Fig. 3.5(j)) expresses that if process p1 requests for a resource ralready held by another processp2, then processp1gets blocked by resourcer.

(k) WaitingRule(Fig. 3.5(k)) propagates the blocking of resourcer2from processp1to processp2, if

p2requests for a resourcer1held by processp1.

(l) IgnoreRule(Fig. 3.5(l)) liberates the blocking of resourceron processp, if processphas no access to any resources.

(m) UnlockRule(Fig. 3.5(m)) detects a deadlock at processp, which has access to a resourcer, which causes a blocking for the same process p. UnlockRuleunlocks the circular blocking by forcing processpto release resourcer.

For example, ReleaseRule (Fig. 3.5(h)) can be applied on the model that has been presented in Fig. 3.4(b). Let us suppose that in the pattern matching phase, p, hb and r of the precondition of

ReleaseRuleare mapped top1,h1andr1of the model, respectively. Since the selected processp1does not have any associated requests, the negative application condition does not prohibit the execution of the rule. In the updating phase, edgeh1is removed from the model, and a new edgerel1of typerelease

is created.