Projet

Général

Profil

SpeADL Java Reference » Historique » Version 4

Anonyme, 16/10/2014 10:36

1 1 Anonyme
h1. Java for SpeADL  Reference Guide
2
3 2 Anonyme
In the [[SpeADL Reference|SpeADL reference guide]] we saw how one can define ecosystems, species and compose them together.
4
We now present how to implement these in Java.
5
6 3 Anonyme
h2. Terminology
7
8
The reader can refer to the [[MAY Terminology]] document to get an overview of the different terms used in SpeADL.
9
10
h2. SpeADL
11
12
It is needed to understand the content of the [[SpeADL Reference|SpeADL Reference Guide]] before reading the current document.
13
14 1 Anonyme
h2. Ecosystem and Species Implementation
15
16
Implementing an ecosystem is similar to implementing a component.
17
The only difference is with the species: there are methods to implement to provide for an implementation of the species and there are methods that can be used to create instances of species from within the implementation of the ecosystem.
18
19
The idea is that the only way of instantiating a species is from within an ecosystem: if one needs to do it from the exterior of the component, some ports must be defined whose implementation does the actual species instantiation.
20
21
h3. Special Method to Implement
22
23
Each species *S* must be implemented by overriding a method called *S make_S()* where S is also the name of an static inner class of the ecosystem generated abstract class.
24
It means that in order to implement the method *make_S()*, it is necessary to extends the class S in any way desired.
25
The implementation of the species can either directly subclass S in an anonymous way in the *make_S()* method, be defined in its own file, or, as it is often done, defined as an inner class of the ecosystem.
26
This last possibility can be useful to access to some Java class member of the ecosystem class for example.
27
28
h3. Special Methods to Exploit
29
30
Each species *S* can be instantiated as many times as desired by calling the method *S.Component newS()* which will also take arguments for the parameters declared in the species.
31
This method is accessible only from within the ecosystem implementation, it can be done for example in the implementation of one of its provided ports or in its *start()* method.
32
33
From the implementation of the species, the required and provided ports as well as the parts can be accessed through the same methods as normal component class implementations: *requires()*, *provides()* and *parts()*.
34
On top of this, the required and provided ports, and the parts, of the ecosystem containing the species can be accessed respectively with *eco_requires()*, *eco_provides()* and *eco_parts*.
35
36
h3. Example
37
38 4 Anonyme
<pre><code class="java">
39 1 Anonyme
package testpackage;
40
41
import my.interfaces.AJavaInterface;
42
import simple.ecos.MyFirstEco;
43
import simple.stuffs.MyBeautifulComponent;
44
45
public class MyFirstEco1 extends MyFirstEco {
46
47
	@Override
48
	protected S make_S(final String name) {
49
		return new S() {
50
			
51
			@Override
52
			protected AJavaInterface make_p2() {
53
				return new AJavaInterface() {
54
					@Override
55
					public String aMethod(Integer param1) {
56
						return name+"/"+param1;
57
					}
58
				};
59
			}
60
			
61
			@Override
62
			protected MyBeautifulComponent make_c() {
63
				return new MyComponentImpl();
64
			}
65
		};
66
	}
67
}
68 4 Anonyme
</code></pre>
69 1 Anonyme
70
Of course, one can extract the implementation of the species, either as an inner class of the ecosystem implementation, or even put it in another Java file if desired.
71 4 Anonyme
<pre><code class="java">
72 1 Anonyme
public class MyFirstEco1 extends MyFirstEco {
73
74
	@Override
75
	protected S make_S(String name) {
76
		return new SImpl(name);
77
	}
78
	
79
	private final class SImpl extends S {
80
		
81
		private final String name;
82
		
83
		public SImpl(String name) {
84
			this.name = name;
85
		}
86
		
87
		@Override
88
		protected AJavaInterface make_p2() {
89
			return new AJavaInterface() {
90
				@Override
91
				public String aMethod(Integer param1) {
92
					return name+""+param1;
93
				}
94
			};
95
		}
96
97
		@Override
98
		protected MyBeautifulComponent make_c() {
99
			return new MyComponentImpl();
100
		}
101
	}
102
}
103 4 Anonyme
</code></pre>
104 1 Anonyme
105
h2. Lifecycle of Species Initialisation at Instantiation
106
107
For a species *S*, when *newS(params...)* is called from the ecosystem implementation, this is what happens:
108
# The species implementation is instantiated (see below).
109
# The species is instantiated from the implementation (see below).
110
# The instance is started (see below).
111
112
h3. Species Implementation Instantiation
113
114
# The implementation of S is instantiated with the *make_S(params...)* method.
115
# For each part *useX* of *S* in the order of declaration:
116
## The species implementation is instantiated from the ecosystem part following the current procedure.
117
118
h3. Species Instantiation
119
120
# For each part *partX* or use *useX* in the order of declaration
121
** If it is a part:
122
### The implementation is instantiated with the *make_partX()* method.
123
### The component is instantiated from the implementation following the [[SpeADL Minus Reference#Component Instantiation 2|Component Instantiation procedure]].
124
** If it is a use:
125
### The use's species is instantiated from the implementation following the current procedure.
126
# For each provided port *portX* in the order of declaration:
127
## The interface implementation is instantiated with the *make_portX()* method.
128
129
h3. Species Instance Start
130
131
# For each part *partX* or use *useX* in the order of declaration:
132
** If it is a part:
133
### The part is started following the [[SpeADL Minus Reference#Component Instance Start|Component Instantiation procedure]].
134
** If it is a use:
135
### The use is instantiated following the current procedure.
136
# The implementation *start()* method is called.