SpeADL Minus Reference » Historique » Révision 45
« Précédent |
Révision 45/69
(diff)
| Suivant »
Anonyme, 15/10/2014 16:10
SpeADL⁻ Reference¶
- Contenu
- SpeADL⁻ Reference
In SpeADL, a subset of abstractions are provided to define traditional component-oriented architectures.
This subset of SpeADL is sometimes called SpeADL⁻ (pronounced SpeADL Minus).
With it, it is possible to define software components and compositions of components, called composites, implemented in Java.
A strong link between definition and implementation is kept by relying on an Eclipse plugin and automatic code generation.
A component is made of two elements: a class definition using SpeADL and an implementation using Java.
The SpeADL definition acts a type declaration but can also describe a composition of components connected together.
From the SpeADL definition, an abstract Java class (which reflects the definition) is automatically generated.
This abstract Java class can be then extended to implement what is left in the component in a type-safe manner.
Terminology¶
The reader can refer to the MAY Terminology document to get an overview of the different terms used in SpeADL.
Namespaces¶
A namespace plays the exact same role as a package in Java.
Keyword¶
Namespaces are declared using the keyword namespace.
Details¶
In a SpeADL file, there can be many as namespace (as well as nested ones) as wanted.
Hence a namespace does not have to follow the name of the directory it is located (as it is the case in Java).
Each namespace declaration can contain any component as desired as we are going to see.
Example¶
namespace simple {
namespace things {
}
}
namespace simple.things {
}
namespace simple.stuffs {
}
Imports¶
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).
Keyword and Role¶
As in Java, this is done with the keyword import.
Details¶
The namespace of components are also considered to import component class definitions.
The imports can be automatically handled and reorganised in Eclipse using the Ctrl-Shift-O shortcut as with the Java editor.
They are always situated at the top of a SpeADL file.
Example¶
The syntax is similar to Java:
import java.util.Collection import java.util.* import simple.stuffs.*
Component Definition¶
A software component is made of a definition and an implementation: an instance can then be created from the implementation.
A component definition has provided and required ports, as well as parts which are themselves components.
A part is structurally similar to a class member in Java.
For each required port of a part, there must be a binding declaring what is providing the required port.
Keywords¶
A component definition is declared with the keyword component followed by a name starting with a capital letter.
It must be unique in its namespace.
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 : .
It takes the form provides name: Interface or requires name: Interface, where Interface is a Java type.
The keyword part is used to declare a part in a component.
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 *: *.
It takes the form part name: ComponentName.
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.
Such a reference can either be:
- To another part's provided port, taking the form bind req to name.port.
- A provided or a required port of the current containing component, taking the form bind req to port.
A delegation is used to declare for the provided port of a component what other port will provides its implementation.
It is done using the keyword = followed by a reference to a port available in the current containing component (as with bindings).
It takes the form provides name: Interface = name.port or provides name: Interface = port.
Details¶
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.
All the required of a part must be bound for the component definition to be valid.
Example¶
Component class definitions:
import my.interfaces.*
namespace simple.stuffs {
component MySimpleComponent {
provides p1: AnotherJavaInterface
}
component MyBeautifulComponent {
provides portName: AJavaInterface
requires anotherPortName: AnotherJavaInterface
}
component MyComplexComponent {
provides p1: AnotherJavaInterface
provides p2: AnotherJavaInterface = s.p1
requires p3: AnotherJavaInterface
part b1: MyBeautifulComponent {
bind anotherPortName to s.p1
}
part b2: MyBeautifulComponent {
bind anotherPortName to p1
}
part b3: MyBeautifulComponent {
bind anotherPortName to p3
}
part s: MySimpleComponent
}
}
Interface definition in Java:
package my.interfaces;
public interface AJavaInterface {
public String aMethod(Integer param1);
}
package my.interfaces;
public interface AnotherJavaInterface {
public Integer test();
}
Component Implementation¶
To implement a component, one has to extend the abstract class generated automatically by the Eclipse plugin.
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).
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.
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.
This is one thing that makes a component fundamentally different from an object.
Special Methods to Implement¶
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.
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.
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.
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.
Furthermore, optionally, a method void start() can be override as explained below.
Special Methods to Exploit¶
The requires() method (inherited from the extended generated class) gives access to each of the required ports (e.g., requires().port()).
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()).
The provided() method (inherited from the extended generated class) gives access to each of the provided ports in the same manner.
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()).
Examples¶
Implementing a component with a provided port:
package testpackage;
import my.interfaces.AnotherJavaInterface;
import simple.stuffs.MySimpleComponent;
public class MySimpleComponentImpl extends MySimpleComponent {
@Override
protected AnotherJavaInterface make_p1() {
return new AnotherJavaInterface() {
@Override
public Integer test() {
return 10;
}
};
}
}
The same result can be obtained by implementing the port directly by the component implementation as follow:
public class MySimpleComponentImpl extends MySimpleComponent implements AnotherJavaInterface {
@Override
public Integer test() {
return 10;
}
@Override
protected AnotherJavaInterface make_p1() {
return this;
}
}
Exploiting a required port:
package testpackage;
import my.interfaces.AJavaInterface;
import simple.stuffs.MyBeautifulComponent;
public class MyComponentImpl extends MyBeautifulComponent {
@Override
protected AJavaInterface make_portName() {
return new AJavaInterface() {
@Override
public String aMethod(Integer param1) {
return "" + param1 + " and " + requires().anotherPortName().test();
}
};
}
}
Implementing a component with parts, calling a part's provided port:
public class ComplexCompImpl extends MyComplexComponent {
@Override
protected MySimpleComponent make_s() {
return new MySimpleComponentImpl();
}
@Override
protected AnotherJavaInterface make_p1() {
return new AnotherJavaInterface() {
@Override
public Integer test() {
return parts().s().p1().test();
}
};
}
@Override
protected MyBeautifulComponent make_b1() {
return new MyComponentImpl();
}
@Override
protected MyBeautifulComponent make_b2() {
return new MyComponentImpl();
}
@Override
protected MyBeautifulComponent make_b3() {
return new MyComponentImpl();
}
}
Component Specialisation¶
In SpeADL, a basic mechanism exists for specialisation of components.
Keyword¶
When declaring a component class definition, after the name, the keyword specializes, followed by a reference to another component name, can be used.
Details¶
An implementation of a specialising component can be used in place of the implementation of the specialised component.
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.
- A component can specialise only a component without parts (i.e., only a pure definition with provided and required ports).
- A component can override provided ports (while respecting the interface or specialising it) to define delegation.
- A component can add provided ports.
- 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).
Examples¶
namespace simple.stuffs {
component S specializes MySimpleComponent {
provides p2: AnotherJavaInterface
}
}
Type Parameters¶
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.
Keywords¶
Type parameters are enclosed between [ and ] (contrary to Java where < and > are used).
A type parameter can be declared only in a component definition, just after the name declaration.
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.
A type parameter can be used as an argument when referencing a component by its name, in a part or in a specialisation declaration.
It must respect the type parameters declared in the referenced component.
A type parameter can also be used as an argument when referencing an interface by its name in a port declaration.
Again it must respect the type parameters declared in the interface.
Details¶
The possibilities of expressiveness are equivalent to what can be done in Java.
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.
Of course interface and component definition references can be parametrised with existing concrete classes.
Example¶
namespace simple.stuffs {
component ParameterisedComponent1[T extends Number] {
provides p1: java.util.concurrent.Callable[T]
provides p2: java.util.concurrent.Callable[String]
}
component ParameterisedComponent2[T1,T2 extends Number] {
part p1: ParameterisedComponent1[T2] {
}
part p2: ParameterisedComponent1[Integer] {
}
}
}
Component Instantiation¶
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.
Details¶
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.
Once we have an instance of a component, we can call the methods of its provided ports.
The same applies for composite components, the instantiation of the part of a composite is done automatically by the generated code.
Example¶
MySimpleComponent.Component c = new MySimpleComponentImpl().newComponent(); System.out.println(c.p1().test());
Component Initialisation¶
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.
Details¶
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.
Example¶
public class MySimpleComponentImpl extends MySimpleComponent {
@Override
protected AnotherJavaInterface make_p1() {
return new AnotherJavaInterface() {
@Override
public Integer test() {
return 10;
}
};
}
@Override
protected void start() {
// do some initialisation using the requires() or the parts(), create a GUI, etc...
}
}
Lifecycle of Component Initialisation at Instantiation¶
When newComponent() is called on a component implementation, this is what happens:- The component is instantiated (see below).
- The instance is started (see below).
Component Instantiation¶
- For each part partX in the order of declaration
- The implementation is instantiated with the make_partX() method.
- A component is instantiated from the implementation following the current procedure.
- For each provided port portX in the order of declaration (starting with the super-component in case of specialisation)
- The interface implementation is instantiated with the make_portX() method.
Component Instance Start¶
- For each part partX in the order of declaration
- The part is started following the current procedure.
- The implementation start() method is called.
Mis à jour par Anonyme il y a plus de 11 ans · 69 révisions