Monday, September 28, 2009

First Steps with JAIN SLEE

Hi Everyone!
Due to the limited information about how to start with JAIN SLEE I offer you this simple tutorial.
Also you can download the tutorial with all the screenshots here:
http://docs.google.com/fileview?id=0B3DLDwLo_7WOZTk1OGU4MGEtNjA1Mi00ZDAxLTkxYjAtM2IyOGZlNGZiODMw&hl=en

To follow this tutorial you need:

  • Eclipse 3.3.1.1
  • MAVEN Plugin- http://m2eclipse.sonatype.org/update/
  • SVN Plugin - http://subclipse.tigris.org/update_1.6.x
  • EclipSLEE plugin v.1.2.4 - http://people.redhat.com/vralev/eclipslee/update/
  • log4j.jar library
  • Mobicents JAIN SLEE Server 1.2.1.GA - http://sourceforge.net/projects/mobicents/files/

ATTENTION! The EclipSlee plugin do not run correctly on other Eclipse versions, I strictly recommend the version 3.3.1.1. Also there is a new version of Eclipslee plugin (v 1.2.5) that runs over eclipse 3.4 and 3.5 but still having some bugs.

Let's start!

1 – Creating JAIN SLEE PROJECT

NEW – Project… – JAIN SLEE – JAIN SLEE PROJECT

Put the name of the project and Finish


2 – Creating a Service Building Block (SBB)

Create a package on src, and do New - Other - JAIN SLEE - Service Bulding Block.

Fill the name of the Sbb and the information of the second slide.


3 – Adding an event for the Root SBB

In this part we will add the event (trigger) that runs when we start the service that contains the SBB.

In the Root-Sbb-jar.xml inside the sbb tag we have to include this code:

  • < direction="Receive" event="True">
  • <>ServiceStartedEvent
  • <>
  • <>javax.slee.serviceactivity.ServiceStartedEvent
  • <>javax.slee
  • <>1.0
  • < /event-type-ref>"
  • < variable="ActivityContext">
  • < /event>




Once declared the Starting event we have to implement the event function in the RootSbb.java

This function prints on the JAIN SLEE server console the message of the bold text.

  • private static Logger logger = Logger.getLogger(RootSbb.class);
  • public void onServiceStartedEvent( javax.slee.serviceactivity.ServiceStartedEvent event, ActivityContextInterface aci) {
  • try {
  • Context myEnv = (Context) new InitialContext().lookup("java:comp/env");
  • ServiceActivity sa = ((ServiceActivityFactory) myEnv
  • .lookup("slee/serviceactivity/factory")).getActivity();
  • if (sa.equals(aci.getActivity())) {
  • // it's this service that is starting
  • logger.info("THIS IS A MESSAGE OF HOPE!!");
  • }
  • // don't want to receive further events on this activity
  • aci.detach(this.sbbContext.getSbbLocalObject());
  • } catch (Exception e) {
  • logger.error("Can't handle service started event.", e);
  • }
  • }

This function requires these imports:

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.slee.serviceactivity.ServiceActivity;

import javax.slee.serviceactivity.ServiceActivityFactory;

import org.apache.log4j.Logger;



Also we have to add the log4j library:

To add a new library into JAIN SLEE ant project we have to add it on Referenced Libraries.

Referenced Libraries – Build Path – Configure build path

In the Library label we have to Add External JARs… and search the log4j.jar file

Also we have to copy the jar file and paste it into lib folder.

Finally we have to add the used libraries into Build.xml descriptor file. In the build-Root-Sbb Label we have to add a new path reference, and also create the path reference. The bold code should be added.

includes="org/i2cat/slee/firstSteps/sbb/RootSbb.java" srcdir="src">

Once we have saved all this chances we have to deploy the build.xml file with ant.

build.xml- run as... - ANT BUILD

4 – Creating a service

Once we have build the Sbb we will create a service.

  • First of all, we create a new package.
  • Inside this package we have to create the service.
  • New - Other - JAIN SLEE - Service
  • Fill the information and select the previus Sbb.

5 – Creating JAIN SLEE DEPLOYABLE UNIT

  • Create a new package
  • New - Other - JAIN SLEE - Deployable Unit
  • Fill the information.
  • Select the Sbb
  • ATTENTION DO NOT SELECT THE ZIP FILE!!
  • Select the service.xml

6- Building the DU.

Finally we have to rebuild the project to create de DeployableUnit.jar file

build.xml- run as... - ANT BUILD


8 – Deploying the project into JAIN SLEE Server

  • Start the JAIN SLEE Server (go to the JBOSS folder, and run the bin\run.bat
  • Open the managment console (http://localhost:8080/management-console)
  • Deployable Units -Install - Select the DU.JAR created on workspace/%project's name%/jars/%deployable unit name%.jar
  • Click Install, and a Log message will appear informing the correct installation.

9 – Starting the service

  • In the JAIN SLEE Management console go to Services, and click Activate

When we start the Service, our SBB will be executed and show the message by JAIN SLEE run console.