## 5 Model Transformations
### Execution and Implementation of the Model Transformations
When a request arrives, the connector behavior sends the request to the provider indicated by the _Index_ property, storing the reply in a local variable _result_. Then, it increments the _Index_ property and applies a modulo operation to prevent the value of _Index_ from overflowing past the number of providers. Finally, the connector behavior returns the value stored in the _result_ as a reply to the requester. A buffering mechanism is not required for this connector since it does not send requests to multiple providers simultaneously. The connector can also coordinate multiple requesters by sending the request it receives from any requester to the providers in a round-robin order. Additionally, based on this specification, we can define a _random destination sender_ connector, which forwards incoming requests to a random provider using a similar behavior specification. We can achieve this by modifying the ALF code in line 2 to use a call to a random number generator. ### The Multiple Destination Sender

In this type of coordination, there are multiple providers. There can be a single requester or multiple requesters. When a requester makes a request, the connector sends the request to all providers. Then, the connector merges the replies from the providers into a single reply and sends it back to the original requester. The requester does not know that the requests are sent to more than one provider. Therefore, the coordination happens in an exogenous style. Listing 1 shows the connector behavior in ALF. The behavior forwards the request to each connected provider by iterating over the _OutPort_ property of the connector (lines 1-5). It stores replies from the providers in the single-copy buffers. After each provider returns with a reply, the behavior executes a reply merge strategy by summing up the returned values (lines 8-19). Note that ALF mandates the _null_ check in line 13. If we do not use the null check, ALF does not allow the summation of _intval_ and _sum_ since _intval_ can be null, and multiplicities of the operands will not match in that case. The connector behavior invalidates the value stored in the single-copy buffer by setting it to _null_ after using it (line 16). Finally, it returns the _sum_ variable to the requester. ### The Less Frequent Sender

The less frequent requester connector coordinates a single requester and a single provider. It can be used in cases where the requester makes frequent requests, but the provider expects them less frequently. Listing 4 shows the connector behavior specification in ALF. The connector has a FIFO buffer which can store a limited number of requests. The connector achieves the coordination by collecting requests in the request buffer until the request buffer reaches a predefined size, indicated by the _MaxRequestCount_ property of the OpaqueBehavior representing the connector behavior. When enough requests are collected, the connector behavior merges them as a single request by summing up the request values. Finally, the connector behavior sends the merged request to the provider. The requests are dequeued from the FIFO request buffer until the buffer is empty. Figure 6 presents an illustration in which subsequent requests are stored in the FIFO buffer and merged into a single request. For the requests that do not cause sending an actual request to the provider (i.e., when the number of requests in the buffer has not reached the _MaxRequestCount_ limit), the connector replies to the requester with a default reply. The default reply value is stored in the _DefaultReply_ property of the connector behavior, which is initialized to _IntegerLiteral 0_ by providing its default value in the E1 model.