Projet

Général

Profil

SpeADL Java Reference » Historique » Version 1

Anonyme, 15/10/2014 17:32

1 1 Anonyme
h1. Java for SpeADL  Reference Guide
2
3
h2. Ecosystem and Species Implementation
4
5
Implementing an ecosystem is similar to implementing a component.
6
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.
7
8
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.
9
10
h3. Special Method to Implement
11
12
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.
13
It means that in order to implement the method *make_S()*, it is necessary to extends the class S in any way desired.
14
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.
15
This last possibility can be useful to access to some Java class member of the ecosystem class for example.
16
17
h3. Special Methods to Exploit
18
19
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.
20
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.
21
22
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()*.
23
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*.
24
25
h3. Example
26
27
<pre>
28
package testpackage;
29
30
import my.interfaces.AJavaInterface;
31
import simple.ecos.MyFirstEco;
32
import simple.stuffs.MyBeautifulComponent;
33
34
public class MyFirstEco1 extends MyFirstEco {
35
36
	@Override
37
	protected S make_S(final String name) {
38
		return new S() {
39
			
40
			@Override
41
			protected AJavaInterface make_p2() {
42
				return new AJavaInterface() {
43
					@Override
44
					public String aMethod(Integer param1) {
45
						return name+"/"+param1;
46
					}
47
				};
48
			}
49
			
50
			@Override
51
			protected MyBeautifulComponent make_c() {
52
				return new MyComponentImpl();
53
			}
54
		};
55
	}
56
}
57
</pre>
58
59
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.
60
<pre>
61
public class MyFirstEco1 extends MyFirstEco {
62
63
	@Override
64
	protected S make_S(String name) {
65
		return new SImpl(name);
66
	}
67
	
68
	private final class SImpl extends S {
69
		
70
		private final String name;
71
		
72
		public SImpl(String name) {
73
			this.name = name;
74
		}
75
		
76
		@Override
77
		protected AJavaInterface make_p2() {
78
			return new AJavaInterface() {
79
				@Override
80
				public String aMethod(Integer param1) {
81
					return name+""+param1;
82
				}
83
			};
84
		}
85
86
		@Override
87
		protected MyBeautifulComponent make_c() {
88
			return new MyComponentImpl();
89
		}
90
	}
91
}
92
</pre>
93
94
h2. Lifecycle of Species Initialisation at Instantiation
95
96
For a species *S*, when *newS(params...)* is called from the ecosystem implementation, this is what happens:
97
# The species implementation is instantiated (see below).
98
# The species is instantiated from the implementation (see below).
99
# The instance is started (see below).
100
101
h3. Species Implementation Instantiation
102
103
# The implementation of S is instantiated with the *make_S(params...)* method.
104
# For each part *useX* of *S* in the order of declaration:
105
## The species implementation is instantiated from the ecosystem part following the current procedure.
106
107
h3. Species Instantiation
108
109
# For each part *partX* or use *useX* in the order of declaration
110
** If it is a part:
111
### The implementation is instantiated with the *make_partX()* method.
112
### The component is instantiated from the implementation following the [[SpeADL Minus Reference#Component Instantiation 2|Component Instantiation procedure]].
113
** If it is a use:
114
### The use's species is instantiated from the implementation following the current procedure.
115
# For each provided port *portX* in the order of declaration:
116
## The interface implementation is instantiated with the *make_portX()* method.
117
118
h3. Species Instance Start
119
120
# For each part *partX* or use *useX* in the order of declaration:
121
** If it is a part:
122
### The part is started following the [[SpeADL Minus Reference#Component Instance Start|Component Instantiation procedure]].
123
** If it is a use:
124
### The use is instantiated following the current procedure.
125
# The implementation *start()* method is called.