Reference Guides » Historique » Version 5
Anonyme, 03/10/2014 09:40
| 1 | 1 | Anonyme | h1. SpeADL Reference |
|---|---|---|---|
| 2 | |||
| 3 | SpeADL is a language to describe component-oriented architectures and implement them in Java. |
||
| 4 | |||
| 5 | This page is decomposed in two parts: |
||
| 6 | 2 | Anonyme | # SpeADL⁻ : it concerns the traditional component-oriented abstractions such as components, interfaces, composites, specialisation, provided and required ports, bindings, etc |
| 7 | 1 | Anonyme | # SpeADL: it concerns the specific abstractions introduced by SpeADL to help the development of MAS with ecosystems and species. |
| 8 | |||
| 9 | 2 | Anonyme | h2. SpeADL⁻ |
| 10 | 1 | Anonyme | |
| 11 | In SpeADL, a set of abstractions are provided to define traditional component-oriented architectures. |
||
| 12 | With it, it is possible to define components and compositions of components, called composites, and to implement them in Java while keeping a strong link between definition and implementation by relying on an Eclipse plugin. |
||
| 13 | |||
| 14 | A component (and thus a composite components) is made of two elements: a definition using SpeADL and an implementation using Java. |
||
| 15 | From the SpeADL definition, an abstract Java class is automatically generated and then relied upon through the Java extension mechanism to implement it in a safe manner. |
||
| 16 | |||
| 17 | h3. Namespaces |
||
| 18 | |||
| 19 | Components and composites are defined inside namespace using the keyword *namespace*. |
||
| 20 | A namespace plays the exact same role as a package in Java. |
||
| 21 | |||
| 22 | In a SpeADL file, there can be many as namespace (as well as nested ones) as wanted. |
||
| 23 | Hence a namespace does not have to follow the name of the directory it is located in as in Java. |
||
| 24 | |||
| 25 | Here is an example of namespace declarations: |
||
| 26 | <pre> |
||
| 27 | namespace simple { |
||
| 28 | |||
| 29 | namespace things { |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | namespace simple.stuffs { |
||
| 34 | } |
||
| 35 | </pre> |
||
| 36 | |||
| 37 | Each namespace declaration can contain any component as desired as we are going to see. |
||
| 38 | |||
| 39 | h3. Imports |
||
| 40 | |||
| 41 | As in Java, it is possible to import existing types into a file to avoid referring to them with their fully qualified name (i.e., including their package or namespace) using the keyword *import*. |
||
| 42 | |||
| 43 | The syntax is similar to Java: |
||
| 44 | <pre> |
||
| 45 | import java.util.Collection |
||
| 46 | import java.util.* |
||
| 47 | import simple.stuffs.* |
||
| 48 | </pre> |
||
| 49 | |||
| 50 | Notice that namespace of components are also considered, and that there is no semi-colon ";" at the end of the line. |
||
| 51 | |||
| 52 | The imports can be automatically handled and reorganised in Eclipse using the *Ctrl-Shift-O* shortcut as in the Java editor. |
||
| 53 | |||
| 54 | h3. Components and Ports |
||
| 55 | |||
| 56 | A component is made of a definition and an implementation. |
||
| 57 | The definition gives it a name and a list of ports that are either provided or required by the component. |
||
| 58 | Each port has a name and an interface. |
||
| 59 | An interface is understood as a Java interface, i.e., a collection of methods. |
||
| 60 | |||
| 61 | A component that provides a port must thus provide an implementation for its interface. |
||
| 62 | Inversely, a component that requires a port can use in its implementation the methods of the interface of the required port. |
||
| 63 | |||
| 64 | A component with required ports must be composed with other components so that there exist an actual implementation of the interface of the required port: this is covered in the next section. |
||
| 65 | |||
| 66 | When implementing a component, one only has to take care of implementing the provided port, and can exploit the required ports without assuming anything about their implementation and who provides it. |
||
| 67 | This is what makes a component fundamentally different from an object. |
||
| 68 | |||
| 69 | A component is defined using the following syntax: |
||
| 70 | <pre> |
||
| 71 | import my.interfaces.* |
||
| 72 | |||
| 73 | namespace simple.stuffs { |
||
| 74 | component ComponentName { |
||
| 75 | provides portName: AJavaInterface |
||
| 76 | requires anotherPortName: AnotherJavaInterface |
||
| 77 | } |
||
| 78 | } |
||
| 79 | </pre> |
||
| 80 | |||
| 81 | A component is defined using the keyword *component*, has a name and can contains as many port declaration as wanted. |
||
| 82 | |||
| 83 | A port has a name and an interface. |
||
| 84 | The keywords *provides* and *requires* respectfully represents ports that are provided and required by the component and are a mandatory keyword when defining a port inside a component. |
||
| 85 | |||
| 86 | Obviously, having an interface means that there must exist already an interface defined with the same name. |
||
| 87 | 3 | Anonyme | Such a definition is done in Java as one would normally do, for example, as follow, in Java files: |
| 88 | 1 | Anonyme | <pre> |
| 89 | package my.interfaces; |
||
| 90 | |||
| 91 | 3 | Anonyme | public interface AJavaInterface { |
| 92 | 1 | Anonyme | public String aMethod(Integer param1); |
| 93 | } |
||
| 94 | </pre> |
||
| 95 | |||
| 96 | 3 | Anonyme | <pre> |
| 97 | package my.interfaces; |
||
| 98 | |||
| 99 | public interface AnotherJavaInterface { |
||
| 100 | public Integer test(); |
||
| 101 | } |
||
| 102 | </pre> |
||
| 103 | |||
| 104 | 1 | Anonyme | In SpeADL, one can use completion to complete interface names. |
| 105 | Also, the shortcut to organize imports will take interfaces into account. |
||
| 106 | 3 | Anonyme | |
| 107 | h3. Implementations |
||
| 108 | |||
| 109 | To implement a component, one has to extend the abstract class generated automatically by the Eclipse plugin. |
||
| 110 | For example, for the previous example of component, a Java class *simple.stuffs.ComponentName* was generated (in the speadl-gen folder, separated from the src folder). |
||
| 111 | |||
| 112 | It is not needed to look at the generated code to use it: when extending the class, some abstract methods must be implemented. |
||
| 113 | It is a good idea to use the errors shown by the Eclipse Java editor and their quick-fixes to quickly generate the skeleton of the implementation itself. |
||
| 114 | |||
| 115 | 4 | Anonyme | Each provided port *p* of interface *I* must be implemented by overriding a method called *I make_p()* which returns an implementation for the port used during the whole life of the component (i.e., the *make_p()* method is called only once to construct the port when the component is instantiated). |
| 116 | 3 | Anonyme | Usually, one returns in this method an anonymous instance of the interface as the following Java file shows: |
| 117 | <pre> |
||
| 118 | package testpackage; |
||
| 119 | |||
| 120 | import my.interfaces.AJavaInterface; |
||
| 121 | import simple.stuffs.ComponentName; |
||
| 122 | |||
| 123 | public class ComponentImpl extends ComponentName { |
||
| 124 | |||
| 125 | @Override |
||
| 126 | protected AJavaInterface make_portName() { |
||
| 127 | return new AJavaInterface() { |
||
| 128 | @Override |
||
| 129 | public String aMethod(Integer param1) { |
||
| 130 | return "" + param1 + " and " + requires().anotherPortName().test(); |
||
| 131 | } |
||
| 132 | 1 | Anonyme | }; |
| 133 | 4 | Anonyme | } |
| 134 | } |
||
| 135 | </pre> |
||
| 136 | |||
| 137 | But the same result can be obtained by implementing the port directly by the component implementation as follow: |
||
| 138 | <pre> |
||
| 139 | public class ComponentImpl extends ComponentName implements AJavaInterface { |
||
| 140 | |||
| 141 | @Override |
||
| 142 | public String aMethod(Integer param1) { |
||
| 143 | return "" + param1 + " and " + requires().anotherPortName().test(); |
||
| 144 | } |
||
| 145 | |||
| 146 | @Override |
||
| 147 | protected AJavaInterface make_portName() { |
||
| 148 | return this; |
||
| 149 | 3 | Anonyme | } |
| 150 | } |
||
| 151 | </pre> |
||
| 152 | |||
| 153 | 5 | Anonyme | We can see that the class extends simple.stuffs.ComponentName and that it overrides a method named *make_portName()* after the name of the provided port. |
| 154 | |||
| 155 | Finally, the requires are accessible through the *requires()* method which gives access to each of the required ports (for example *requires().anotherPortName()* here). |
||
| 156 | A port being an implementation of an interface (and not of an operation), it is then necessary to call the desired method on it (for example *requires().anotherPortName().test()* here). |
||
| 157 | 3 | Anonyme | |
| 158 | h3. Composites |