Projet

Général

Profil

SpeADL Minus Reference » Historique » Version 33

Anonyme, 13/10/2014 09:57

1 1 Anonyme
h1. SpeADL Minus Reference
2
3 2 Anonyme
{{>toc}}
4
5 1 Anonyme
In SpeADL, a set of abstractions are provided to define traditional component-oriented architectures.
6 33 Anonyme
With it, it is possible to define software components and compositions of components, called composites, implemented in Java, while keeping a strong link between definition and implementation by relying on an Eclipse plugin and automatic code generation.
7 1 Anonyme
8 4 Anonyme
A component is made of two elements: a class definition using SpeADL and an implementation using Java.
9 33 Anonyme
Optionally, the SpeADL definition can contain a bit of implementation in the form of a composition of components connected together.
10 31 Anonyme
From the SpeADL definition, an abstract Java class (which exactly reflects the definition) is automatically generated and then relied upon through the Java extension mechanism to implement what is left in the component in a safe manner.
11 1 Anonyme
12
h2. Namespaces
13
14 5 Anonyme
A namespace plays the exact same role as a package in Java.
15
16 4 Anonyme
h3. Keyword
17
18 31 Anonyme
Namespaces are declared using the keyword *namespace*.
19 1 Anonyme
20 4 Anonyme
h3. Details
21
22 1 Anonyme
In a SpeADL file, there can be many as namespace (as well as nested ones) as wanted.
23 31 Anonyme
Hence a namespace does not have to follow the name of the directory it is located (as it is the case in Java).
24 1 Anonyme
25 4 Anonyme
Each namespace declaration can contain any component as desired as we are going to see.
26
27
h3. Example
28
29 1 Anonyme
<pre>
30
namespace simple {
31
32
	namespace things {
33 19 Anonyme
34 1 Anonyme
	}
35
}
36
37 19 Anonyme
namespace simple.things {
38
39
}
40
41 1 Anonyme
namespace simple.stuffs {
42 19 Anonyme
43 1 Anonyme
}
44
</pre>
45
46
h2. Imports
47
48 20 Anonyme
As in Java, it is possible to import existing names to avoid referring to them with their fully qualified name (i.e., including their package or namespace).
49 1 Anonyme
50 5 Anonyme
h3. Keyword and Role
51
52
As in Java, this is done with the keyword *import*.
53
54
h3. Details
55
56
The namespace of components are also considered to import component class definitions.
57
58 33 Anonyme
The imports can be automatically handled and reorganised in Eclipse using the *Ctrl-Shift-O* shortcut as with the Java editor.
59 5 Anonyme
60 33 Anonyme
They are always situated at the top of a SpeADL file.
61 5 Anonyme
62
h3. Example
63
64 1 Anonyme
The syntax is similar to Java:
65
<pre>
66
import java.util.Collection
67
import java.util.*
68
import simple.stuffs.*
69
</pre>
70
71 33 Anonyme
h2. Component Definition
72 1 Anonyme
73 33 Anonyme
A software component is made of a definition and an implementation: an instance can then be created from the implementation.
74
A component definition has provided and required ports, as well as parts which are themselves components.
75 1 Anonyme
A part is structurally similar to a class member in Java.
76 5 Anonyme
For each required port of a part, there must be a binding declaring what is providing the required port.
77 1 Anonyme
78
h3. Keywords
79
80 33 Anonyme
A component definition is declared with the keyword *component* followed by a name starting with a capital letter.
81
It must be unique in its namespace.
82 1 Anonyme
83 33 Anonyme
The keywords *provides* and *requires* are used to declare, respectively, provided and required ports, they are followed by a name (unique in the component and without capital letter) and an interface name separated by the character *: *.
84 1 Anonyme
It takes the form _provides name: Interface_ or _requires name: Interface_, where _Interface_ is a Java type.
85
86 31 Anonyme
The keyword *part* is used to declare a part in a component.
87 33 Anonyme
It is followed by a name for the part (unique in the component and without capital letter) and a component class definition name separated by the character *: *.
88 31 Anonyme
It takes the form _part name: ComponentName_.
89 5 Anonyme
90 33 Anonyme
For each part, bindings are used to declare for each of its required port what is fulfilling the requirement.
91
It is done using the keywords *bind* and *to* in the form _bind ...1 to ...2_ where _...1_ is the name of the required port of the part and _...2_ is a reference to a port available in the component containing the part.
92 5 Anonyme
Such a reference can either be:
93 31 Anonyme
* To another part's provided port, taking the form _bind req to name.port_.
94
* A provided or a required port of the current containing component, taking the form _bind req to port_.
95 5 Anonyme
96 31 Anonyme
A delegation is used to declare for the provided port of a component what other port will provides its implementation.
97 33 Anonyme
It is done using the keyword * =  * followed by a reference to a port available in the current containing component (as with bindings).
98 31 Anonyme
It takes the form _provides name: Interface = name.port_ or _provides name: Interface = port_.
99 5 Anonyme
100
h3. Details
101
102 31 Anonyme
An interface is understood as a Java interface, i.e., a collection of methods, and must be visible in the classpath of the Java project.
103 5 Anonyme
104 33 Anonyme
All the required of a part must be bound for the component definition to be valid.
105 1 Anonyme
106 5 Anonyme
h3. Example
107
108 6 Anonyme
Component class definitions:
109 1 Anonyme
<pre>
110
import my.interfaces.*
111
112
namespace simple.stuffs {
113
114
	component MySimpleComponent {
115
		provides p1: AnotherJavaInterface
116
	}
117
118
	component MyBeautifulComponent {
119
		provides portName: AJavaInterface
120
		requires anotherPortName: AnotherJavaInterface
121
	}
122
123 5 Anonyme
	component MyComplexComponent {
124
		
125
		provides p1: AnotherJavaInterface
126
		provides p2: AnotherJavaInterface = s.p1
127
		requires p3: AnotherJavaInterface
128 1 Anonyme
129 5 Anonyme
		part b1: MyBeautifulComponent {
130
			bind anotherPortName to s.p1 
131
		}
132 1 Anonyme
133 5 Anonyme
		part b2: MyBeautifulComponent {
134
			bind anotherPortName to p1
135
		}
136
137
		part b3: MyBeautifulComponent {
138
			bind anotherPortName to p3
139
		}
140
		
141
		part s: MySimpleComponent
142
		
143
	}
144
}
145
</pre>
146
147
Interface definition in Java:
148 1 Anonyme
<pre>
149
package my.interfaces;
150
151
public interface AJavaInterface {
152
  public String aMethod(Integer param1);
153
}
154
</pre>
155
156
<pre>
157
package my.interfaces;
158
159
public interface AnotherJavaInterface {
160
	public Integer test();
161
}
162
</pre>
163
164 33 Anonyme
h2. Component Implementation
165 6 Anonyme
166 1 Anonyme
To implement a component, one has to extend the abstract class generated automatically by the Eclipse plugin.
167 33 Anonyme
For example, for the previous example _simple.stuffs.MyBeautifulComponent_ defined in SpeADL, a Java class _simple.stuffs.MyBeautifulComponent_ is generated (in the *speadl-gen* folder, different than the *src* folder).
168 31 Anonyme
169 33 Anonyme
It is not needed to look at the generated code to use it: when extending the class, some abstract methods will have to be implemented.
170 1 Anonyme
171
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.
172 12 Anonyme
This is one thing that makes a component fundamentally different from an object.
173 31 Anonyme
174 12 Anonyme
h3. Special Methods to Implement
175 7 Anonyme
176 33 Anonyme
Each provided port *p* of interface *I* must be implemented by overriding a method called *I make_p()* which returns an instance of the implementation for the port.
177
This instance is used for 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.
178 6 Anonyme
179
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*.
180 7 Anonyme
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.
181 6 Anonyme
182 8 Anonyme
Furthermore, optionally, a method *void start()* can be override as explained [[SpeADL_Minus_Reference#Component-Initialisation|below]].
183
184 7 Anonyme
h3. Special Methods to Exploit
185 6 Anonyme
186 31 Anonyme
The *requires()* method (inherited from the extended generated class) gives access to each of the required ports (e.g., _requires().port()_).
187
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().port().method()_).
188 6 Anonyme
189 32 Anonyme
The *provided()* method  (inherited from the extended generated class) gives access to each of the provided ports in the same manner.
190
191 31 Anonyme
It is possible to access to the provided ports of the part from within the implementation of a composite by using the method *parts()* (e.g., _parts().partName().portName().method()_).
192 6 Anonyme
193
h3. Examples
194
195
Implementing a component with a provided port:
196 1 Anonyme
<pre>
197
package testpackage;
198
199
import my.interfaces.AnotherJavaInterface;
200
import simple.stuffs.MySimpleComponent;
201
202
public class MySimpleComponentImpl extends MySimpleComponent {
203
204
	@Override
205
	protected AnotherJavaInterface make_p1() {
206
		return new AnotherJavaInterface() {
207
			@Override
208
			public Integer test() {
209
				return 10;
210
			}
211
		};
212
	}
213
214
}
215
</pre>
216
217 6 Anonyme
The same result can be obtained by implementing the port directly by the component implementation as follow:
218 1 Anonyme
<pre>
219 6 Anonyme
public class MySimpleComponentImpl extends MySimpleComponent implements AnotherJavaInterface {
220
221
	@Override
222
	public Integer test() {
223
		return 10;
224
	}
225
	
226
	@Override
227
	protected AnotherJavaInterface make_p1() {
228
		return this;
229
	}
230
}
231
</pre>
232
233
Exploiting a required port:
234
<pre>
235 1 Anonyme
package testpackage;
236
237
import my.interfaces.AJavaInterface;
238
import simple.stuffs.MyBeautifulComponent;
239
240
public class MyComponentImpl extends MyBeautifulComponent {
241
242
	@Override
243
	protected AJavaInterface make_portName() {
244
		return new AJavaInterface() {
245
			@Override
246
			public String aMethod(Integer param1) {
247
				return "" + param1 + " and " + requires().anotherPortName().test();
248
			}
249
		};
250
	}
251
}
252
</pre>
253
254 6 Anonyme
Implementing a component with parts, calling a part's provided port:
255 1 Anonyme
<pre>
256
public class ComplexCompImpl extends MyComplexComponent {
257
258
	@Override
259
	protected MySimpleComponent make_s() {
260
		return new MySimpleComponentImpl();
261
	}
262
263
	@Override
264
	protected AnotherJavaInterface make_p1() {
265
		return new AnotherJavaInterface() {
266
			@Override
267
			public Integer test() {
268
				return parts().s().p1().test();
269
			}
270
		};
271
	}
272
273
	@Override
274
	protected MyBeautifulComponent make_b1() {
275
		return new MyComponentImpl();
276
	}
277
278
	@Override
279
	protected MyBeautifulComponent make_b2() {
280
		return new MyComponentImpl();
281
	}
282
283
	@Override
284
	protected MyBeautifulComponent make_b3() {
285
		return new MyComponentImpl();
286
	}
287
288
}
289
</pre>
290
291 16 Anonyme
h2. Specialisation
292
293
In SpeADL, a basic mechanism exists for specialisation of components.
294
295
h3. Keyword
296
297
When declaring a component class definition, after the name, the keyword *specializes*, followed by a reference to another component name, can be used.
298 1 Anonyme
299 16 Anonyme
h3. Details
300
301 33 Anonyme
302
An implementation of a specialising component can be used in place of the implementation of the specialised component.
303
Only the specialising component needs to be implemented: its implementation will contain all the provided ports of the specialisation hierarchy as well as the parts of the specialising component.
304
305
The specialisation rules are as follow:
306 1 Anonyme
* A component can specialise only a component without parts (i.e., only a pure definition with provided and required ports).
307 31 Anonyme
* A component can override provided ports (while respecting the interface or specialising it) to define delegation.
308 28 Anonyme
* A component can add provided ports.
309 33 Anonyme
* A component CAN'T add required ports (for obvious reason: the specialising component wouldn't be usable in a configuration where the specialised component is used because some of its ports won't be bound).
310 30 Anonyme
311 16 Anonyme
h3. Examples
312
313
<pre>
314
namespace simple.stuffs {
315 26 Anonyme
	component S specializes MySimpleComponent {
316
		provides p2: AnotherJavaInterface
317 16 Anonyme
	}
318
}
319
</pre>
320
321 15 Anonyme
h2. Type Parameters
322
323 33 Anonyme
As in Java, it is possible to exploit type parameters (also called generics) when declaring and referencing components, as well as in the interfaces of the ports.
324 1 Anonyme
325
h3. Keywords
326
327 33 Anonyme
Type parameters are enclosed between *[ * and * ]* (contrary to Java where *< * and * >* are used).
328 1 Anonyme
329
A type parameter can be declared only in a component definition, just after the name declaration.
330 33 Anonyme
It has a unique name, a capital first letter, and can be constrained using the keyword *extends* and the name of a Java class it must be a subclass of.
331 1 Anonyme
332 33 Anonyme
A type parameter can be used as an argument when referencing a component by its name, in a part or in a specialisation declaration.
333 1 Anonyme
It must respect the type parameters declared in the referenced component.
334
335 33 Anonyme
A type parameter can also be used as an argument when referencing an interface by its name in a port declaration.
336 1 Anonyme
Again it must respect the type parameters declared in the interface.
337
338
h3. Details
339
340
The possibilities of expressiveness are equivalent to what can be done in Java.
341
342
The implementation can either keep the type parameters abstract as in the definition, or can concretise them as long as it respects the type parameter declaration.
343
344
Of course interface and component definition references can be parametrised with existing concrete classes.
345
346
h3. Example
347
348
<pre>
349
namespace simple.stuffs {
350
	component ParameterisedComponent1[T extends Number] {
351
		
352
		provides p1: java.util.concurrent.Callable[T]
353
		provides p2: java.util.concurrent.Callable[String]
354
	}
355
	
356
	component ParameterisedComponent2[T1,T2 extends Number] {
357
		
358
		part p1: ParameterisedComponent1[T2] {
359
			
360
		}
361
		
362
		part p2: ParameterisedComponent1[Integer] {
363
			
364
		}
365
		
366
	}
367
}
368
</pre>
369 27 Anonyme
370 33 Anonyme
h2. Instantiation
371
372
In order to instantiate a component from Java, one need an instance of an implementation of the component and to call the *newComponent()* method (present in the generated class) to get an instance of the component.
373
374
h3. Details
375
376
Only component without required port can be manually instantiated from Java: if a component has required ports, it must be composed with other components in a composite component.
377
378
Once we have an instance of a component, we can call the methods of its provided ports.
379
380
The same applies for composite components, the instantiation of the part of a composite is done automatically by the generated code.
381
382
h3. Example
383
384
<pre>
385
MySimpleComponent.Component c = new MySimpleComponentImpl().newComponent();
386
System.out.println(c.p1().test());
387
</pre>
388
389 27 Anonyme
h2. Component Initialisation
390
391
When the implementation of a component is instantiated (before calling *newComponent()*), its constructor is of course called but the component itself is not yet initialised: in particular its provided required ports and parts can't be called at that time.
392
393
h3. Details
394
395
In order to do some initialisation at the instantiation of a component (during the call to *newComponent()*), one can override the *void start()* method of the extended abstract class.
396
397
h3. Example
398
399
<pre>
400
public class MySimpleComponentImpl extends MySimpleComponent {
401
402
	@Override
403
	protected AnotherJavaInterface make_p1() {
404
		return new AnotherJavaInterface() {
405
			@Override
406
			public Integer test() {
407
				return 10;
408
			}
409
		};
410
	}
411
	
412
	@Override
413
	protected void start() {
414
		// do some initialisation using the requires() or the parts(), create a GUI, etc...
415
	}
416
}
417
</pre>
418
419
420
h2. Lifecycle of Component Initialisation at Instantiation
421 22 Anonyme
422
When *newComponent()* is called on a component, this is what happens:
423
# For each part *partX* in the order of declaration
424 23 Anonyme
## The implementation is instantiated with the *make_partX()* method.
425
## A component is created from it with a process equivalent to *newComponent()* but without *start()* being called.
426 25 Anonyme
# For each provided port *portX* in the order of declaration (starting with the super-component in case of specialisation)
427 23 Anonyme
## The interface implementation is instantiated with the *make_portX()* method.
428 22 Anonyme
# The component is started (see below).
429
430
When a component is started, this is what happens:
431
# For each part *partX* in the order of declaration
432 23 Anonyme
## The part is started (as currently defined).
433 22 Anonyme
# The implementation *start()* method is called.