APAM/APAM Getting Started Tutorial/APAM Hello World

From Wiki Adele Team
< APAM‎ | APAM Getting Started Tutorial
Revision as of 11:49, 3 December 2012 by Mehdi (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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


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 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.


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" 


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) 
    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" 
     <callback onInit="start" onRemove="stop"/>


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" >

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.


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