Projet

Général

Profil

Reference Guides » Historique » Version 11

Anonyme, 03/10/2014 14:36

1 1 Anonyme
{{>toc}}
2 11 Anonyme
3
h1. SpeADL Reference
4 10 Anonyme
5 1 Anonyme
SpeADL is a language to describe component-oriented architectures and implement them in Java.
6
7
This page is decomposed in two parts:
8 2 Anonyme
# SpeADL⁻ : it concerns the traditional component-oriented abstractions such as components, interfaces, composites, specialisation, provided and required ports, bindings, etc
9 1 Anonyme
# SpeADL: it concerns the specific abstractions introduced by SpeADL to help the development of MAS with ecosystems and species.
10
11 2 Anonyme
h2. SpeADL⁻
12 1 Anonyme
13
In SpeADL, a set of abstractions are provided to define traditional component-oriented architectures.
14
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.
15
16 6 Anonyme
A component is made of two elements: a component class definition using SpeADL and an implementation using Java.
17 1 Anonyme
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.
18
19
h3. Namespaces
20
21
Components and composites are defined inside namespace using the keyword *namespace*.
22
A namespace plays the exact same role as a package in Java.
23
24
In a SpeADL file, there can be many as namespace (as well as nested ones) as wanted.
25
Hence a namespace does not have to follow the name of the directory it is located in as in Java.
26
27
Here is an example of namespace declarations:
28
<pre>
29
namespace simple {
30
31 6 Anonyme
	namespace things {
32
	}
33 1 Anonyme
}
34
35
namespace simple.stuffs {
36
}
37
</pre>
38
39
Each namespace declaration can contain any component as desired as we are going to see.
40
41
h3. Imports
42
43
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*.
44
45
The syntax is similar to Java:
46
<pre>
47
import java.util.Collection
48
import java.util.*
49
import simple.stuffs.*
50
</pre>
51
52 6 Anonyme
Notice that namespace of components are also considered to import component class definitions, and that there is no semi-colon ";" at the end of the line.
53 1 Anonyme
54
The imports can be automatically handled and reorganised in Eclipse using the *Ctrl-Shift-O* shortcut as in the Java editor.
55
56
h3. Components and Ports
57
58 6 Anonyme
A component is made of a component class definition and an implementation: it can then be instantiated 
59 1 Anonyme
The definition gives it a name and a list of ports that are either provided or required by the component.
60
Each port has a name and an interface.
61
An interface is understood as a Java interface, i.e., a collection of methods.
62
63
A component that provides a port must thus provide an implementation for its interface.
64
Inversely, a component that requires a port can use in its implementation the methods of the interface of the required port.
65
66
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.
67
68
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.
69
This is what makes a component fundamentally different from an object.
70
71
A component is defined using the following syntax:
72
<pre>
73
import my.interfaces.*
74
75
namespace simple.stuffs {
76 6 Anonyme
	component MyBeautifulComponent {
77
		provides portName: AJavaInterface
78
		requires anotherPortName: AnotherJavaInterface
79
	}
80 1 Anonyme
}
81
</pre>
82
83
A component is defined using the keyword *component*, has a name and can contains as many port declaration as wanted.
84
85
A port has a name and an interface.
86
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.
87
88
Obviously, having an interface means that there must exist already an interface defined with the same name.
89 3 Anonyme
Such a definition is done in Java as one would normally do, for example, as follow, in Java files:
90 1 Anonyme
<pre>
91
package my.interfaces;
92
93 3 Anonyme
public interface AJavaInterface {
94 1 Anonyme
  public String aMethod(Integer param1);
95
}
96
</pre>
97
98 3 Anonyme
<pre>
99
package my.interfaces;
100
101
public interface AnotherJavaInterface {
102
	public Integer test();
103
}
104
</pre>
105
106 1 Anonyme
In SpeADL, one can use completion to complete interface names.
107
Also, the shortcut to organize imports will take interfaces into account.
108 3 Anonyme
109
h3. Implementations
110
111
To implement a component, one has to extend the abstract class generated automatically by the Eclipse plugin.
112 6 Anonyme
For example, for the previous example of component, a Java class *simple.stuffs.MyBeautifulComponent* was generated (in the speadl-gen folder, separated from the src folder).
113 3 Anonyme
114
It is not needed to look at the generated code to use it: when extending the class, some abstract methods must be implemented.
115
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.
116
117 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).
118 3 Anonyme
Usually, one returns in this method an anonymous instance of the interface as the following Java file shows:
119
<pre>
120
package testpackage;
121
122
import my.interfaces.AJavaInterface;
123 6 Anonyme
import simple.stuffs.MyBeautifulComponent;
124 3 Anonyme
125 9 Anonyme
public class MyComponentImpl extends MyBeautifulComponent {
126 3 Anonyme
127
	@Override
128
	protected AJavaInterface make_portName() {
129
		return new AJavaInterface() {
130
			@Override
131
			public String aMethod(Integer param1) {
132
				return "" + param1 + " and " + requires().anotherPortName().test();
133
			}
134 1 Anonyme
		};
135 4 Anonyme
	}
136
}
137
</pre>
138
139
But the same result can be obtained by implementing the port directly by the component implementation as follow:
140
<pre>
141 9 Anonyme
public class MyComponentImpl extends MyBeautifulComponent implements AJavaInterface {
142 4 Anonyme
143
	@Override
144 1 Anonyme
	public String aMethod(Integer param1) {
145
		return "" + param1 + " and " + requires().anotherPortName().test();
146 4 Anonyme
	}
147 1 Anonyme
	
148
	@Override
149
	protected AJavaInterface make_portName() {
150
		return this;
151
	}
152
}
153
</pre>
154
155 6 Anonyme
We can see that the class extends simple.stuffs.MyBeautifulComponent and that it overrides a method named *make_portName()* after the name of the provided port.
156 1 Anonyme
157 6 Anonyme
Finally, the *requires()* method (inherited from the extended generated class, *MyBeautifulComponent* in the example) gives access to each of the required ports (e.g.,*requires().anotherPortName()* in the example).
158
A port being an implementation of an interface (and not of an operation), it is then necessary to call the desired method on it (e.g., *requires().anotherPortName().test()* in the example).
159 1 Anonyme
160 6 Anonyme
Of course, nothing else is required than calling it to use it: as we are going to see now, the implementation of a required port is provided by another component composed with the requiring component.
161
162 1 Anonyme
h3. Composites
163 6 Anonyme
164
While defining a component class with a name and ports in SpeADL is only a definition of its external interfaces, a composite of many components connected together is already a partial implementation of this definition.
165
166
A composite, on top of provided and required ports, contains parts. A part is structurally similar to a class member in Java.
167
A part is declared using the *part* keyword and the name of the component class of the part.
168
Furthermore, if the component class of the part has required ports, then a part will also contain bindings for these required ports using the keyword *bind*.
169
170
An example follow:
171
<pre>
172
namespace simple.stuffs {
173
	component MySimpleComponent {
174
		provides p1: AnotherJavaInterface
175
	}
176
177
	component MyComplexComponent {
178
		
179 7 Anonyme
		provides p1: AnotherJavaInterface
180
		provides p2: AnotherJavaInterface = s.p1
181
		requires p3: AnotherJavaInterface
182
183
		part b1: MyBeautifulComponent {
184 6 Anonyme
			bind anotherPortName to s.p1 
185 1 Anonyme
		}
186 7 Anonyme
187
		part b2: MyBeautifulComponent {
188
			bind anotherPortName to p1
189
		}
190
191
		part b3: MyBeautifulComponent {
192
			bind anotherPortName to p3
193
		}
194 6 Anonyme
		
195
		part s: MySimpleComponent
196
		
197
	}
198
}
199 1 Anonyme
</pre>
200 7 Anonyme
201
The keyword *bind* is followed by the name of the required port that is to be bound (completion can be used), then by the keyword *to* then either by:
202
* The name of another part, a dot, then a provided port of this part (as for *b1* in the example).
203
* The name of a provided port of the component containing the part (as for *b2* in the example).
204
* The name of a required port of the component containing the part (as for *b3* in the example).
205
206 1 Anonyme
Furthermore, another type of binding is a delegation of a provided port to another port.
207
It is declared using the = sign after the provided port declaration (as in *p2* in the example) and can be followed either by a reference to the port of a part, a provided or a required port of the component, as with the normal bindings.
208 9 Anonyme
209
h3. Implementation of Composites
210
211
As with the implementation of non-composite component classes, a Java class is generated from the description and it must be extended in order to specify the implementation of the provided ports and of the parts.
212
213
Each part *p* of component class *C* has a corresponding abstract method *C make_p()* to override and which must return an instance of an implementation of *C*.
214
215
For example:
216
<pre>
217
public class ComplexCompImpl extends MyComplexComponent {
218
219
	@Override
220
	protected MySimpleComponent make_s() {
221
		return new MySimpleComponentImpl();
222
	}
223
224
	@Override
225
	protected AnotherJavaInterface make_p1() {
226
		return new AnotherJavaInterface() {
227
			@Override
228
			public Integer test() {
229
				return 5;
230
			}
231
		};
232
	}
233
234
	@Override
235
	protected MyBeautifulComponent make_b1() {
236
		return new MyComponentImpl();
237
	}
238
239
	@Override
240
	protected MyBeautifulComponent make_b2() {
241
		return new MyComponentImpl();
242
	}
243
244
	@Override
245
	protected MyBeautifulComponent make_b3() {
246
		return new MyComponentImpl();
247
	}
248
249
}
250
</pre>
251
252
As we can see, the bindings and other connections inside the components are totally taken care of by the generated code and the implementation only needs what is Java-specific.
253
It becomes very easy to define new compositions without extra boilerplate code.