## 5 Model Transformations
### Execution and Implementation of the Model Transformations
```
1 IntegerreturnValue=this.DefaultReply;
2 if(this.InPort[1].RequestBuffer.size()==this.MaxRequestCount){
3//Mergerequests:
4 Integersum=0;
5 while(this.InPort[1].RequestBuffer.size()!=0){
6 Integerrequest=this.InPort[1].RequestBuffer.removeFirst();
7 if(request!=null){
8 sum=sum+request;
9}
10}
11 returnValue=OutPort[1].xOp(sum);
12}
13 returnreturnValue;
```

Listing 4: Connector behavior specification for the less frequent sender. ### The Request Barrier

The request barrier connector coordinates multiple requesters and a single provider. Figure 12 shows its structural configuration in the E1 model. The main functionality of the connector is to act as a barrier until all requesters make a request. It collects incoming requests in the single-copy request buffers. After the connector receives requests from each requester, it merges the requests stored in the request buffers into a single request and then forwards it to the provider. Listing 5 shows the connector behavior specification. The connector specification uses a boolean property _BarrierOn_ to keep track of the connector state. When a request is received, the connector behavior checks if the request buffer of each requester is empty. It sets the _BarrierOn_ flag to _true_ if one of the requesters has an empty request buffer, indicating that the corresponding requester did not make any request yet (lines 1-9). Setting the _BarrierOn_ flag to _true_ means the barrier is closed, and the requests cannot pass through. In this case, the connector does not forward requests to the provider. Instead, it replies to the requester with a default reply (lines 11, 12, and 28). ```
1 Integeri=1;
2 this.BarrierOn=false;
3 while(i<=REQ_CNT){
4 Integerrequest=this.InPort[i].RequestBuffer;
5 if(request==null){
6 this.BarrierOn=true;
7]
8i++;
9]
10
11 IntegerreturnValue=this.DefaultReply;
12 if(this.BarrierOn==false){
13//Mergerequests
14 IntegerrepagedRequest=0;
15i=1;
16 while(i<=REQ_CNT){
17 request=this.InPort[i].RequestBuffer;
18 if(request!=null){
19 mergedRequest+=request;
20//Invalidatetheconsumedrequest
21 this.InPort[i].RequestBuffer=null;
22]
23i++;
24]
25 returnValue=this.OutPort[1].XOp(mergedRequest);
26 this.BarrierOn=true;
27]
28 returnreturnValue;
```

Listing 5: Connector behavior specification for the request barrier. The connector sets the _BarrierOn_ flag to _false_ if all requesters have non-empty request buffers, indicating that each requester made at least one request. Setting the _BarrierOn_ flag to _false_ means the barrier is open, and requests can pass through. In this case, the connector merges multiple requests into a single request and sends the merged request to the provider (lines 13-28). Figure 12(a) shows the composite structure diagram, and Figure 12(c) shows the UML representation for the E2 model. The _ETtoE2_ model transformation replaces the enhanced connector in the E1 model with an object of the _connector class_ denoting the connector. The model transformation sets the multiplicity of the port _prvPort_ of the connector class to the number of requesters, which is 3. Figure 12(b) shows the internal structure of the connector class, which contains the _InPort_ property. Figure 12: E1 level UML model composite structure diagram for the request barrier connector. The InPort property is an instance of the RequestPortCls class. The transformation also sets the multiplicity of the InPort property to the number of requesters. One of the responsibilities of the InPort property is to differentiate between requests received from different requesters. The operations defined in the connector class can access the request received from a specific requester by indexing the InPort property with the requester index. If we do not use the InPort property, we should directly implement the operations declared in the coordinated interface inside the connector class. However, this implementation will cause subsequent requests to overwrite each other. Figure 13(a) shows the UML model for the connector class in the E3 model for the request barrier connector.