• Aucun résultat trouvé

Fractal Tutorial: HelloWorld with Fractal ADL http://fractal.ow2.org/fractal-distribution/helloworld-julia-adl/user-doc.html

N/A
N/A
Protected

Academic year: 2022

Partager "Fractal Tutorial: HelloWorld with Fractal ADL http://fractal.ow2.org/fractal-distribution/helloworld-julia-adl/user-doc.html"

Copied!
1
0
0

Texte intégral

(1)

Fractal Tutorial: HelloWorld with Fractal ADL

http://fractal.ow2.org/fractal-distribution/helloworld-julia-adl/user-doc.html

Table of Contents 1. Introduction

1.1. Steps

1.2. Composite component 1.3. Primitive components 1.4. Java content

1.4.1. Client component 1.4.2. Server component 2. Run the application

List of Examples

1.1. Fractal ADL definition of the client primitive component 1.2. Fractal ADL definition of the server primitive component 1.3. ClientImpl.java

1.4. ServiceAttributes.java 1.5. ServerImpl.java

Chapter 1. Introduction

Table of Contents 1.1. Steps

1.2. Composite component 1.3. Primitive components 1.4. Java content

1.4.1. Client component 1.4.2. Server component

In this tutorial, we will work on the same helloworld application than the previous tutorial but without the Fraclet tool.

The main differences are that we have to write extra Java code and ADL definitions that are normally created by Fraclet.

In the previous tutorial we've had a bottom-up approach, we've started by the .java code of the primitive

components to end with the ADL definition of the composite component. In this tutorial we will show how we can have a top-down approach. We will start from the composite ADL definition to the Java implementation code.

1.1. Steps

 Create the description of the composite component with Fractal ADL

 Create primitif components. To do this :

o

create the description of the primitive components with Fractal ADL.

o

create Java interfaces that will be associated with our Fractal interfaces.

o

create a Java class which contains the business code of the component and implements needed Fractal control interfaces.

 call the FractalADL factory which will instanciate the description of our architecture from Java.

1.2. Composite component

The ADL of the client-server composite is the same that in the previous tutorial.

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN"

"classpath://org/objectweb/fractal/adl/xml/basic.dtd">

<definition name="helloworld.ClientServerImpl">

<interface name="r" role="server" signature="helloworld.Main"/>

(2)

<component name="client" definition="helloworld.ClientImpl" />

<component name="server" definition="helloworld.ServerImpl" />

<binding client="this.r" server="client.r" />

<binding client="client.s" server="server.s" />

</definition>

Note: Be careful with the order of the Fractal ADL xml elements. For composite components: first list the interface elements, then the list of sub-components, finally the bindings between sub-components.

1.3. Primitive components

As we don't use Fraclet we have to describe the architecture of our primitive components. It is a little tedious, but easy.

Example 1.1. Fractal ADL definition of the client primitive component

package helloworld;

import org.objectweb.fractal.api.NoSuchInterfaceException;

import org.objectweb.fractal.api.control.BindingController;

public class ClientImpl implements java.lang.Runnable, BindingController { private Service service;

public ClientImpl () {

System.err.println("CLIENT created");

}

public void run () {

service.print("Hello world !");

}

public String[] listFc () {

return new String[] { "s" };

}

public Object lookupFc (final String cItf) { if (cItf.equals("s")) {

return service;

}

return null;

}

public void bindFc (final String cItf, final Object sItf) { if (cItf.equals("s")) {

service = (Service)sItf;

} }

public void unbindFc (final String cItf) { if (cItf.equals("s")) {

service = null;

} }

}

(3)

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN"

"classpath://org/objectweb/fractal/adl/xml/basic.dtd">

<definition name="helloworld.ServerImpl">

<interface name="s" role="server" signature="helloworld.Service"/>

<content class="helloworld.ServerImpl"/>

<attributes signature="helloworld.ServiceAttributes">

<attribute name="header" value="->"/>

</attributes>

<controller desc="primitive"/>

</definition>

To describe the Fractal attributes of a primitive component, we need to indicate the Java interface used by the attribute controller, and describe the initialization of the attributes.

We indicate the Java interface that will be used by the attribute controller.

<attributes signature="helloworld.ServiceAttributes">

We can initialize the value of the attribute:

<attribute name="header" value="->"/>

Note: Be careful with the order of Fractal ADL xml elements. For primitive component: first list interfaces, after content, then attributes, finally the controller. Note also, that you can't define binding in a primitive component definition. They are defined only in composite components, because bindings between two components can only occur in a common super-component.

1.4. Java content

1.4.1. Client component

Example 1.3. ClientImpl.java

package helloworld;

import org.objectweb.fractal.api.NoSuchInterfaceException;

import org.objectweb.fractal.api.control.BindingController;

public class ClientImpl implements java.lang.Runnable, BindingController { private Service service;

public ClientImpl () {

System.err.println("CLIENT created");

}

public void run () {

service.print("Hello world !");

}

public String[] listFc () {

return new String[] { "s" };

}

(4)

public Object lookupFc (final String cItf) { if (cItf.equals("s")) {

return service;

}

return null;

}

public void bindFc (final String cItf, final Object sItf) { if (cItf.equals("s")) {

service = (Service)sItf;

} }

public void unbindFc (final String cItf) { if (cItf.equals("s")) {

service = null;

} }

}

Java fields with interface types are used to store Fractal required interfaces. We need to inform Fractal about the private field to use for each required Fractal interface. To do this we have to implement the BindingController control interface.

Note. With the Fraclet tool you don't need to implement this interface because Fraclet automatically injects this code from the the information that you've provided with the annotations.

1.4.2. Server component

The server component also needs extra manual code without Fraclet. Our server component has a 'header' attribute. So here too we have to explicit the mapping between the Java attributes and Fractal attributes. To do so we need to add a ServiceAttributes control interface.

The ServiceAttributes interface just contains accessors to manipulate the Java attributes that you want to map to Fractal attributes.

Example 1.4. ServiceAttributes.java

package helloworld;

import org.objectweb.fractal.api.control.AttributeController;

public interface ServiceAttributes extends AttributeController { String getHeader ();

void setHeader (String header);

}

The name of the accessor must have the same name that your Fractal attribute, in our case our Java attribute is named header so the accessors are named

getHeader

and

setHeader

.

As our interface will be a control interface to manipulate attributes, we need to extend the standard Fractal AttributeController interface.

Let's note that you can map more that one attribute in the same interface. If you have a other attribute name 'foo' you can add a

getFoo

and a

setFoo

in the same interface than the one used for the header attribute.

(5)

package helloworld;

public class ServerImpl implements Service, ServiceAttributes { private String header;

public ServerImpl () {

System.err.println("SERVER created");

}

public void print (final String msg) { System.out.println(header + msg);

}

public String getHeader () { return header;

}

public void setHeader (final String header) { this.header = header;

} }

Chapter 2. Run the application

To launch the application we have to instanciate our helloworld.ClientServerImpl Fractal ADL file.

With ant, we first need to package the helloworld application in a jar :

ant dist

We can call the Fractal ADL factory on our Fractal ADL file Linux :

bash $FRACTAL_HOME/bin/fractal.sh -cp dist/helloworld.jar -adl helloworld.ClientServerImpl

Windows :

%FRACTAL_HOME%\bin\fractal.bat -cp dist/helloworld.jar -adl helloworld.ClientServerImpl

With Maven, just type :

mvn -Prun

Références

Documents relatifs

The Sierpinsky Gasket is a fractal object built by effacing one triangle in the middle of each existing triangle.. a) Find the fractal dimension D f of the

The surface consists of an infinite number of facets (the larger the Miller index, the smaller the facet) and of two types of Cantor sets.. It is useful to deal

On pourrait croire naïvement qu’une sorte de graphe séparateur jouerait le rôle de la médiatrice (comme dans le cas précédent) : ce graphe séparerait le plan en trois régions,

Under the assumption of dominated splitting of index-1, we calculate the Hausdorff dimension of the level sets of the pointwise H¨ older expo- nent for a subinterval of the

La chirurgie constitue un temps très important dans la prise en charge du cancer thyroïdien, la thyroïdectomie totale est le geste chirurgical de référence,

The difference in the last network with D = I-S is easily understood when one thinks that its function is to transport people from or to the center of urban ensemble, the town of

backbone of critical percolation clusters, by analyzing four different sets of data for the hypocenter distributions and calculating the dynamical properties of the

Following the first observation of a fractal structure over a restricted range of length in base catalyzed silica aerogels, it was suggested that fractality in