Summary. The purpose of this tutorial is to show that we can utilize block contracts when composing rather complex building blocks (e.g., have many pins). In particular, we show that we do not need to see the inner details of those blocks. Moreover, we also learn how to fix errors in the specification
Note that there is a similar project called (Level 2) Multiple Emails (finished) containing a complete and correct system specification.
This application block already contains three building blocks, namely:
With these blocks we will build an application that sends multiple emails which are generated at random time intervals by block Emails Generator. Block Send Email can only send one email at a time. Hence, there is a possibility that there are many emails generated while an email is being sent. In order to avoid losing emails, we buffer them by using block Buffer Eager Simple.
Let us now connect the building blocks to make a complete application. Connect the system as shown below:
Some additional details:
Now, let us analyze the application block. Choose Analyze from the context menu of the application block.
Analysis view will pop up showing the result as depicted below.
We see that block Send Multiple Emails has an error, namely Flows harms the contract of block 'Send Email'. Lets now try to understand it & fix the problem.
A detailed description about an issue is given by clicking the issue. For the error shown in the figure above:
Each type of detected issues is explained in our website together with examples and possible fixes. An overview of all issues are shown in this gallery. To go directly to a type of issue you encounter, just click link Read more about this issue… (scroll to find it) in the Analysis view, or click here for our current error.
You may want to Highlight the situation by clicking it in the detailed description of the error:
This action will accentuate block SendEmail and the harming activity step:
Exit the highlighting by pressing the ‘x’ key. Open the contract of block Send Email choosing Show Contract from the block's context menu (right-click the block):
It shows that the block SendEmail is activated via pin send going from its initial state to state active. From state active two transition are possible reporting the two possible outcomes, namely ok or failed, going to state final. There is no transition that includes both pins send and failed.
To further understand that such a step may occur, you can use the action Start animation towards the situation by clicking this action in the detailed description of the error. (It might be helpful to also open the contracts of the inner blocks.) Some parts of the model are highlighted as shown in the following figure.
You can use arrows → and ← to run through the three steps leading to the error condition.
The last activity step harms block Send Email as there is no transition that involves both pins failed and send. The behaviour of application block Send Multiple Emails is not compatible with the contract of block Send Email.
Note that the contract of block Send Email allows transition labelled with /failed to a final state. Moreover, it also allows transitions send/ from an initial state to state active. This means that we try to restart the block Send Email within one activity step which is forbidden by its contract.
As also described here, there are basically two alternatives to fix the error. However, since we can't modify the inner block's contract (as it is taken from a library), we correct the error by splitting the activity step 4 (see above) into two activity steps:
After having fixed the issue:
You can build and run the application if you wish. However, remember to set the username and password variables in the operation init with your gmail or google account and password respectively.