Difference between revisions of "APAM/APAM Getting Started Tutorial/APAM Hello World"

From Wiki Adele Team
Jump to: navigation, search
(Use Hello World Service)
 
(35 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Hello World Sample =
+
[[Category:APAM]]
 +
''' In this lesson, you will manipulate basic apam components. We will create a simple Hello World Service with ApAM components, then we will use it  '''
  
In this lesson, you will manipulate basic apam components. We will create a simple Hello World Service with ApAM components.
 
  
 
__TOC__
 
__TOC__
Line 18: Line 18:
 
=== Specification ===
 
=== Specification ===
 
The specification is the description the service. it contains the description of resources to be provided, like interfaces. the java interface corresponding to the Hello World service is as follow :
 
The specification is the description the service. it contains the description of resources to be provided, like interfaces. the java interface corresponding to the Hello World service is as follow :
<source lang="java">
+
<source lang="java5">
 
package fr.imag.adele.apam.hello.world.spec;
 
package fr.imag.adele.apam.hello.world.spec;
  
Line 39: Line 39:
 
The implementation component is in charge to provide an the code implementation of the service. The Java class implementation corresponding to this implementation is as follows:
 
The implementation component is in charge to provide an the code implementation of the service. The Java class implementation corresponding to this implementation is as follows:
  
<source lang="java">
+
<source lang="java5">
 
package fr.imag.adele.apam.hello.world.impl;
 
package fr.imag.adele.apam.hello.world.impl;
  
Line 50: Line 50:
 
     public void sayHello(String texte) {
 
     public void sayHello(String texte) {
 
         System.out.println("Hello, " + texte);
 
         System.out.println("Hello, " + texte);
 +
    }
 +
 +
    //Called by APAM when an instance of this implementation is created
 +
    public void start(){
 +
        System.out.println("HelloService Start");
 +
    }
 +
   
 +
    // Called by APAM when an instance of this implementation is removed
 +
    public void stop(){
 +
        System.out.println("HelloService Stop");
 
     }
 
     }
 
}
 
}
Line 58: Line 68:
 
<source lang="xml">
 
<source lang="xml">
 
   <implementation name="Hello-Impl"  
 
   <implementation name="Hello-Impl"  
    classname="fr.imag.adele.apam.hello.world.impl.HelloImplementation"
+
        specification="Hello-Spec"     
     specification="Hello-Spec">
+
        classname="fr.imag.adele.apam.hello.world.impl.HelloImplementation">
 +
      
 +
    <callback onInit="start" onRemove="stop"/>
 +
 
 
   </implementation>
 
   </implementation>
 
</source>
 
</source>
 +
 +
In the description we can set callback methods to be called on instance creation and/or destruction. In our example, the method "start()" will be call at instance creation and the method "stop()" at the instance destruction
  
 
=== Instance Description ===
 
=== Instance Description ===
Line 74: Line 89:
 
For build process we use Maven as presented in the [[APAM/APAM_Getting_Started_Tutorial/APAM_Project_Creation | prevoius lesson]] . To launch the build of this project the command “mvn clean install” must be executed in an OS console or using a maven eclipse plugin.
 
For build process we use Maven as presented in the [[APAM/APAM_Getting_Started_Tutorial/APAM_Project_Creation | prevoius lesson]] . To launch the build of this project the command “mvn clean install” must be executed in an OS console or using a maven eclipse plugin.
  
If the build process ends successfully the bundle "HelloWorld-1.0.0-SNAPSHOT.jar" must be in the target directory of the project.
+
If the build process ends successfully the bundle "HelloWorld-AllInOneBundle-1.0.0.jar" must be in the target directory of the project.
 +
 
 +
== Use Hello World Service ==
 +
We create a client "TextGui" which depend on [[APAM/APAM_Getting_Started_Tutorial/APAM_Hello_World | Hello World service]]. This client show a Gui to write a texte, then TextGui called the "Hello World service" with the entered text.
 +
 
 +
=== TextGui ===
 +
We will not explain the code of TextGui but if you want a snapshot of the code you can have look [here]
  
 +
=== Run using the compiled bundle  ===
  
== Use Hello World Service ==
+
* First Download [https://github.com/downloads/AdeleResearchGroup/ApAM/Apam-Runtime.zip APAM-Runtime]
Now we will create a client "TextGui" which depend on [[APAM/APAM_Getting_Started_Tutorial/APAM_Hello_World | Hello World service]]. This client show a Gui to write a texte, then TextGui called the "Hello World service" with the entered text.
 
  
 +
* Install Hello-Service : copy the following command to the ApamRuntime
  
Figure//
+
<source lang="bash">
 +
start https://repository-apam.forge.cloudbees.com/release/tutorials/fr/imag/adele/apam/tutorials/HelloWorld-AllInOneBundle/0.0.1/HelloWorld-AllInOneBundle-0.0.1.jar
 +
</source>
  
 +
* Install TextGui : copy the following command to the ApamRuntime
  
=== TextGui Implementation ===
+
<source lang="bash">
 +
start https://repository-apam.forge.cloudbees.com/release/tutorials/fr/imag/adele/apam/tutorials/TextGui/1.0.0/TextGui-1.0.0.jar
 +
</source>
  
 +
=== Run using your compiled project  ===
 +
* if you have already download source code of the example, you can compile it using Maven then, Download [https://github.com/downloads/AdeleResearchGroup/ApAM/Apam-Runtime.zip APAM-Runtime].
  
=== TextGui Instance ===
+
* tape the command :
 +
 
 +
<source lang="bash">
 +
put TextGui-Impl
 +
</source>
  
 
== Example Resources ==
 
== Example Resources ==
Line 93: Line 126:
 
=== Source code in the Git repository ===
 
=== Source code in the Git repository ===
  
[http://github.com/AdeleResearchGroup/ApAM/tree/master/Tutorials/Projects/HelloWorld-OneBundle Browse the Git code]
+
[ Browse the Git code]
  
 
=== Snapshot of source code ===
 
=== Snapshot of source code ===
  
Get a snapshot of the Git project [https://github.com/downloads/AdeleResearchGroup/ApAM/APAM-HelloWorld.zip here].
+
Get a snapshot of the Git project [comming soon here].
  
 
=== List of compiled artefacts ===
 
=== List of compiled artefacts ===
  
* [http://github.com/AdeleResearchGroup/ApAM/blob/master/Tutorials/Bundles/HelloWorld-1.0.0-SNAPSHOT.jar Hello World (one bundle)]
+
* [https://repository-apam.forge.cloudbees.com/release/tutorials/fr/imag/adele/apam/tutorials/HelloWorld-AllInOneBundle/0.0.1/HelloWorld-AllInOneBundle-0.0.1.jar Hello World All in one Bundle]
 +
 
 +
* [https://repository-apam.forge.cloudbees.com/release/tutorials/fr/imag/adele/apam/tutorials/TextGui/1.0.0/TextGui-1.0.0.jar Text Gui Bundle]

Latest revision as of 10:49, 3 December 2012

In this lesson, you will manipulate basic apam components. We will create a simple Hello World Service with ApAM components, then we will use it


Overview

The goal of this section is to create basic components (without composite) which provide the "Hello World" service. This service receives an input string and displays "Hello, ..." message into the standard output console.


Hello-apam.png

Hello World Service

A service in ApAM is realized through a three level component model : specification, implementation and instance (for more details see the ApAM overview. In this section, we will implements the Hello World service using our three level component model.

Specification

The specification is the description the service. it contains the description of resources to be provided, like interfaces. the java interface corresponding to the Hello World service is as follow :

package fr.imag.adele.apam.hello.world.spec;

public interface HelloService {
    /**
     * Method printing text into the output console with "Hello, " prefix
     * @param texte the string received, 
     */
    public void sayHello(String texte);
}

Each Specification ApAM must be described using the ApAM DSL language. This description provide information about the resources provided and required, the specification component can be customized using definitions and properties.

  <specification name="Hello-Spec" 
     interfaces="fr.imag.adele.apam.hello.world.spec.HelloService">
  </specification>

Implementation

The implementation component is in charge to provide an the code implementation of the service. The Java class implementation corresponding to this implementation is as follows:

package fr.imag.adele.apam.hello.world.impl;

public class HelloImplementation implements HelloService{

    /**
     * @see HelloService#sayHello(String) 
     */
    @Override
    public void sayHello(String texte) {
        System.out.println("Hello, " + texte);
    }

    //Called by APAM when an instance of this implementation is created
    public void start(){
        System.out.println("HelloService Start");
    }
    
    // Called by APAM when an instance of this implementation is removed
    public void stop(){
        System.out.println("HelloService Stop");
    }
}

As Specification component, each implementation in ApAM must be described using the ApAM DSL language. This description provide information about the class implementing this component, the service provided or required.

This description is realized as follows:

  <implementation name="Hello-Impl" 
        specification="Hello-Spec"      
        classname="fr.imag.adele.apam.hello.world.impl.HelloImplementation">
    
     <callback onInit="start" onRemove="stop"/>

  </implementation>

In the description we can set callback methods to be called on instance creation and/or destruction. In our example, the method "start()" will be call at instance creation and the method "stop()" at the instance destruction

Instance Description

ApAM allow the creation of instances using a description. in our example, to create the instance of Hello-Impl the description is realized as follow :

<instance name="Hello-Inst" 
   implementation="Hello-Impl" >
</instance>

Build (Compilation and Packaging)

For build process we use Maven as presented in the prevoius lesson . To launch the build of this project the command “mvn clean install” must be executed in an OS console or using a maven eclipse plugin.

If the build process ends successfully the bundle "HelloWorld-AllInOneBundle-1.0.0.jar" must be in the target directory of the project.

Use Hello World Service

We create a client "TextGui" which depend on Hello World service. This client show a Gui to write a texte, then TextGui called the "Hello World service" with the entered text.

TextGui

We will not explain the code of TextGui but if you want a snapshot of the code you can have look [here]

Run using the compiled bundle

  • Install Hello-Service : copy the following command to the ApamRuntime
start https://repository-apam.forge.cloudbees.com/release/tutorials/fr/imag/adele/apam/tutorials/HelloWorld-AllInOneBundle/0.0.1/HelloWorld-AllInOneBundle-0.0.1.jar
  • Install TextGui : copy the following command to the ApamRuntime
start https://repository-apam.forge.cloudbees.com/release/tutorials/fr/imag/adele/apam/tutorials/TextGui/1.0.0/TextGui-1.0.0.jar

Run using your compiled project

  • if you have already download source code of the example, you can compile it using Maven then, Download APAM-Runtime.
  • tape the command :
put TextGui-Impl

Example Resources

Source code in the Git repository

[ Browse the Git code]

Snapshot of source code

Get a snapshot of the Git project [comming soon here].

List of compiled artefacts