Instructions for completing the Labs using F4e

Transcription

Instructions for completing the Labs using F4e
Instructions for completing the Labs using F4e Environment setup and simple HelloWorld example In this tutorial we will provide a step-­‐by-­‐step guide on how to complete the basic HelloWorld example. After completing the example described in this guide, you shall be able to create your own fractal applications. The tutorial assumes that you already have Java Runtime Environment (jre) and Execution Environment installed on your machine. This tutorial has been developed on a Windows 7 machine with j2SE-­‐1.5 as Java Runtime Environment. Please note that there are compatibility issues with jre8, and the f4e works only with jre1.7 and the 1.5 System Library. Also f4e is a 32-­‐bit application, therefore you need a 32-­‐bit jre. Reminder!!! This guide does not cover the theoretical foundations and rationale behind the fractal component model. It focuses on technical details and it is intended to save you time and effort while managing technical difficulties. To be able to use the Fractal component model properly, it is required that you read the documentation suggested during the lectures. As an addition to the material suggested in the lecture slides, on the following web locations http://fractal.ow2.org/documentation.html and http://fractal.ow2.org/fractal-­‐
distribution/fractal-­‐concepts-­‐doc.html you can find comprehensive documentation for the Fractal component model. Environment setup The instructions cover developing a fractal project using the F4e tool. It is an Eclipse based tool, which can be used for developing and running fractal models. The F4e tool can be downloaded from the following link: http://download.forge.ow2.org/fractal/eclipse-­‐modeling-­‐ganymede-­‐SR2-­‐F4E-­‐
1.2.7-­‐incubation-­‐win32.zip. Once you download it, you can unpack the .zip file and run the eclipse. The whole package has been preset so you are not required to make any changes. Simple HelloWorld example In the reminder of the description, you will learn the basics of how to create Fractal Component Model project and execute it as a Fractal ADL. The tutorial will be given as a step-­‐by-­‐step example of a simple HelloWorld application. Task 0 – Read the Problem Description The description of the scenario can be found on the following link: http://fractal.ow2.org/fractal-­‐distribution/helloworld-­‐julia-­‐fraclet/user-­‐
doc.html. In order to be able to successfully follow the tutorial presented in this document you must read the description of the HelloWorld given above. There, you will find the detailed explanation about the interfaces, instances and other Fractal elements. Please note that the reminder of the tutorial is not to give you a description of Fractal building elements, but instead it should present you the technicalities behind creating and executing Fractal ADL model. Task 1 – Create a New Fractal Project In order to create new project you shall perform the following action: File -­‐> New -­‐> Other -­‐> Fractal -­‐> Fractal project. The window in Eclipse for creating new Fractal project is given in Figure 1. Figure 1Creating new Fractal Project in Eclipse Once you have selected to create new Fractal project, click next, and the following window (see Figure 2) will appear. Fill in the name of the project (HelloWorld) and select the same execution environment as in the figure (j2SE-­‐
1.5). It is very important that you select this execution environment as there might be compatibility issues with other JREs. If you do not have the j2SE-­‐1.5 installed on your machine you can download it from here: http://www.oracle.com/technetwork/java/javase/index-­‐jsp-­‐135232.html Figure 2Fractal Project setup After you fill in all the fields like in Figure 2, a new empty Fractal project will be created for you. Task 2 – Create a New Package Next, you should create a package in the project where all the files will be located. You can create new package in the project as following: right click on the src folder -­‐> new -­‐> Package. When you execute the given sequence of commands, a new window (Figure 3) will appear. Fill in “helloworld” for package name and click Finish. This will create new package in your project structure. Figure 3 Creating new package Task 3 – Create the Components with Their Interfaces Once the project has been created, we will start adding the components into the package. First, we start by creating new interface called Service. To create the interface perform the following action: right click on the package “helloworld” -­‐> new -­‐> Interface. When you execute the given set of commands, the window as in Figure 4. Enter “Service” for the interface name and click Finish. Figure 4 Creating new interface Once the Service interface has been added to your Fractal project, open the Service.java file and adds the following code to it: Figure 5 Service interface code After the interface has been created, continue by adding the two primitive components in the model: Server and Client. First, we create .java classes for each of the primitive components. To create class right click on the package -­‐> new -­‐> “ClientImpl”. When you execute the given sequence of commands, a new window like the one given in Figure 6 will appear. Enter “ClientImpl” for the class name and click finish. Repeat the same procedure for creating the “ServerImpl” class. Figure 6 Creating new class Task 4 – Implementation of the Primitive Components After successfully creating the two classes, we have to provide implementation for them. The implementation of the ClientImpl.java class is given in Figure 7, while the implementation of the ServerImpl.java is given in Figure 8: Figure 7 ClientImpl.java Figure 8 ServerImpl.java Task 5 – Wrap the Components as Fractal Components Once the implementation of the components in java has been done, now we need to create Fractal corresponding components. The ServerImpl and ClientImpl and primitive components wrapped by the ClientServerImpl composite component. First, we start by creating the two primitive components: ClientImpl and ServerImpl. To add Fractal component, right click on the package -­‐> new -­‐> Other -­‐> Fractal Model. When you execute the sequence of commands, new window like in Figure 9 will appear. Figure 9 Create new Fractal model Click Next, and fill in the required fields like in Figure 10. Repeat the same to create Fractal component for the “ServerImpl”. Figure 10 Creating new Fractal model step 2 After the Fractal components have been created, next is to add the properties (children) to each of them. For adding new children to Fractal model, double click on the Fractal model file, then right click on the Definition –> new child and a new window like in Figure 11 will open. Figure 11 Adding children to Fractal model In the rightmost menu you can see the possible options for child type to Fractal component model. For the ClientImpl Fractal component (model) we add the following 3 children: Server interface r, with the properties given in Figure 12. Figure 12 ClientImpl server interface r properties Client interface s, with properties given in Figure 13 Figure 13 ClientImpl client interface s properties Content, which actually represents the implementation of client in java. The property window for the content is given in Figure 14. Figure 14 ClientImpl content child properties For ServerImpl Fractal component (model) we add the following children: Server interface s, with the property window given in Figure 15 ServerImpl server interface s properties Content i.e. the actual implementation of the behavior of the compoenet given in .java class. The property window for the content child of ServerImpl is given in Figure 16 bellow: Figure 16 ServerImpl content property window •
The controller shall be set to “primitive” Task 6 – Create a Composite Fractal Component In the end we have to create the Fractal composite component called “ClientServerImpl” that will incorporate the two primitive components into its structure. The ClientServerImpl Fractal component is created in the same way as the primitive components described above. After the ClientServerImpl.fractal has been created, we add the following children to it: Server interface r, with the property window given in Figure 17 Figure 17ClientServerImpl server interface r Client component ClientImpl with the property window given in Figure 18. Figure 18 ClientServerImpl client compoenent Server component with the property window given in Figure 19. Figure 19 ClientServerImpl server component Client binding with the properties given in Figure 20. Figure 20 ClientServerImpl client interface binding Server binding with the property window given in Figure 21. Figure 21 ClientServerImpl server interface binding Task 7 -­‐ Add the Configuration File Now the HelloWorld Fractal model has been completed. Before we run the model, we have to add the build configuration file called build.xml into the project. Download the file (http://www.idt.mdh.se/kurser/cd5490/2016/labs_files/build.xml) and then right click on the root -­‐> Import -­‐> File System -­‐> “location of your build.xml file”. Now the project is complete and we can run it. Figure 22 Run as of the Fractal model Task 8 – Running the Project To run the project, right click on the ClientServerImpl.fractal -­‐> Run as -­‐> Run Configuration (see Figure 22). After you execute the given sequence of commands a new window like the one in Figure 23 will open. Double click on the Fractal ADL option (the one selected in the Figure 23). This will create the ADL model and the corresponding launcher. Figure 23 Run as configuration window Then you can expland the Fractal ADL option and you will get the window in Figure 24. Select the helloworld.ClientServerImpl (like in the figure) and press Run. Figure 24 Run the launcher After you execute the Fractal ADL model, you shall get the console output like in Figure 25. Figure 25 Fractal model execution output Deliverables You are expected to complete this assignment during the first lab time slot (2016-­‐02-­‐04). In order to get your assignment approved, you must demonstrate the working version of the HelloWorld example to the lab assistant by the end of the lab session. During the demonstration you will be asked questions about the Fractal component model. Important! You are not allowed to start the next lab assignments until you get an approval this assignment by the lab assistant. This assignment does not require any submission from you.