Projet

Général

Profil

Reference Guides » Historique » Version 8

Anonyme, 03/10/2014 13:30

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 6 Anonyme
A component is made of two elements: a component class definition using SpeADL and an implementation using Java.
15 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.
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 6 Anonyme
	namespace things {
30
	}
31 1 Anonyme
}
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 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.
51 1 Anonyme
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 6 Anonyme
A component is made of a component class definition and an implementation: it can then be instantiated 
57 1 Anonyme
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 6 Anonyme
	component MyBeautifulComponent {
75
		provides portName: AJavaInterface
76
		requires anotherPortName: AnotherJavaInterface
77
	}
78 1 Anonyme
}
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 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).
111 3 Anonyme
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 6 Anonyme
import simple.stuffs.MyBeautifulComponent;
122 3 Anonyme
123 6 Anonyme
public class ComponentImpl extends MyBeautifulComponent {
124 3 Anonyme
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 6 Anonyme
public class ComponentImpl extends MyBeautifulComponent implements AJavaInterface {
140 4 Anonyme
141
	@Override
142 1 Anonyme
	public String aMethod(Integer param1) {
143
		return "" + param1 + " and " + requires().anotherPortName().test();
144 4 Anonyme
	}
145 1 Anonyme
	
146
	@Override
147
	protected AJavaInterface make_portName() {
148
		return this;
149
	}
150
}
151
</pre>
152
153 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.
154 1 Anonyme
155 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).
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 (e.g., *requires().anotherPortName().test()* in the example).
157 1 Anonyme
158 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.
159
160 1 Anonyme
h3. Composites
161 6 Anonyme
162
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.
163
164
A composite, on top of provided and required ports, contains parts. A part is structurally similar to a class member in Java.
165
A part is declared using the *part* keyword and the name of the component class of the part.
166
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*.
167
168
An example follow:
169
<pre>
170
namespace simple.stuffs {
171
	component MySimpleComponent {
172
		provides p1: AnotherJavaInterface
173
	}
174
175
	component MyComplexComponent {
176
		
177 7 Anonyme
		provides p1: AnotherJavaInterface
178
		provides p2: AnotherJavaInterface = s.p1
179
		requires p3: AnotherJavaInterface
180
181
		part b1: MyBeautifulComponent {
182 6 Anonyme
			bind anotherPortName to s.p1 
183 1 Anonyme
		}
184 7 Anonyme
185
		part b2: MyBeautifulComponent {
186
			bind anotherPortName to p1
187
		}
188
189
		part b3: MyBeautifulComponent {
190
			bind anotherPortName to p3
191
		}
192 6 Anonyme
		
193
		part s: MySimpleComponent
194
		
195
	}
196
}
197 1 Anonyme
</pre>
198 7 Anonyme
199
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:
200
* The name of another part, a dot, then a provided port of this part (as for *b1* in the example).
201
* The name of a provided port of the component containing the part (as for *b2* in the example).
202
* The name of a required port of the component containing the part (as for *b3* in the example).
203
204
Furthermore, another type of binding is a delegation of a provided port to another port.
205 8 Anonyme
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.