Cilia/Hello World

From Wiki Adele Team
Jump to: navigation, search

Overview

The goal of this section it to create a simple mediation chain with only one mediator i.e. the “Hello World” mediator. The mediator receives an input string from a GUI and displays and “Hello, …” message into the standard output console.

Hellomediator1.png

Mediator Implementation

A mediator is composed of three elements: processor, scheduler and dispatcher (for an explanation of each element see the User Guide). In this subsection, for the Hello World mediator we will present its elements, then the mediator description and finally the mediation build process.

Processor

The processor of the Hello Mediator takes the data received by the mediator, next it extracts the content of this data (a string in this case), then it adds the text “hello, ” to this string, and finally it sends the data to the next mediator. The Java class corresponding to this processor is as follows:

package fr.liglab.adele.cilia.components.mediators;

import fr.liglab.adele.cilia.Data;

/**
 * The Hello World Processor Class
 * 
 */
public class HelloProcessor {

   /**
    * Method modifying the received data
    * 
    * @param data The processor received data
    * @return The data with "Hello, " prefix
    */
   public Data sayHello(Data data) {
      if (data != null) {
         data.setContent("Hello, " + data.getContent().toString());
      }
      return data;
   }
}

Each processor must be described in the Cilia DSL language. In this description is provided information about the class implementing the processor, the method used to treat the data, and the data type used to transport information (by default is fr.liglab.adele.cilia.Data).

This description is realized as follows:

   <processor name="HelloProcessor"
      classname="fr.liglab.adele.cilia.components.mediators.HelloProcessor">
      <cilia:method name="sayHello" data.type="fr.liglab.adele.cilia.Data" />
   </processor>

Scheduler and Dispatcher

A set of prebuilt Schedulers and Dispatchers are available into the Cilia compendium distribution. For this mediator we will use the Immediate Scheduler (the data is passed to the processor when they are received by the scheduler) and the Multicast Dispatcher (the data is passed to the all next mediators).

Mediator Description

The mediator is described into the Cilia DSL language. The description indicates each element forming the mediator (scheduler, processor and dispatcher). The description file is a follows:

   <mediator-component name="HelloMediator" category="samples">
      <cilia:processor name="HelloProcessor" />
      <cilia:scheduler name="immediate-scheduler" />
      <cilia:dispatcher name="multicast-dispatcher" />
   </mediator-component>

Build (Compilation and Packaging)

For build process we use Maven (project management software). Maven compiles the Java code, adds the appropriated metadata to the mediator and creates an OSGi standard bundle (jar file). To launch the build of this project the command “mvn clean install” must be executed in an OS console. The work directory must be the project directory.

Mediator Deployment

Mediator deployment is simple, it consists only in copying the file produced by maven (hello-mediator-1.0.0-SNAPSHOT.jar) into the cilia directory of the installed platform. Indeed, mediator bundles are compliant OSGi bundle, it can be installed using provided capabilities by the installed platform. In our case, we have installed a Felix platform with the FileInstall extension, it allows the automatic deployment of bundles putting files into a specific directory.