Wednesday, November 18, 2009

MAVEN Deployable Unit PLUGIN





Hi all,
This is another tutorial to develope JAIN SLEE Projects using the Maven-du-plugin.


TOOLS:
Mobicents JAIN SLEE Server 1.2.6-GA - http://sourceforge.net/projects/mobicents/files/

ATTENTION! Some JAIN SLEE programmers recommend using MAVEN DU PLUGIN version 1.0.0.BETA2
RESUME: This tutorial shows how to create a JAIN SLEE project with maven (using maven commands over Windows console). Also we can introduce a Ant code to deploy the resultant Deployable Unit of the project over Mobicents JAIN SLEE Server.
Maven installation:
1. Download Maven binary resource and unzip it.
2. Create a System Variable M2_HOME to the unzipped folder.
3. Modify the PATH system variable adding “;%M2_HOME%\bin”.
JAIN SLEE Server installation
1. Download the JAIN SLEE Server 1.2.6-GA binary resource and unzip it.
2. Create a System variable JBOSS_HOME to the jboss-4.2.3.GA folder.
3. Start the server executing jboss-4.2.3.GA\bin\run.bat
Maven DU Plugin
We use a folder as workspace, in our case we have created a the “C:\MAVEN WORKSPACE” folder, and we have created a folder for the project called “My project”
Create the next folder tree into the project folder:



Required files:
· POM.xml on Project Root folder (“My Project”)
· POM.xml on Project Root folder \du
· POM.xml on Project Root folder\sbb
· Service.xml on Project Root folder\du\src\main\resources\services
· Sbb-jar.xml on Project Root folder\sbb\src\main\resources\META-INF
· Sbb.java on Project Root folder\sbb\src\main\java\“package”
The Root POM.XML describes the name, vendor, and version of the project you want to build with maven. Also it contains a reference of the folders that compose the project and the repositories that are required.
The DU POM.XML creates the DU.jar file and requires the information of:
· The main project that is referenced
· The SBB that contain your project
· The Maven-du-plugin you want to use
· The ant code for autodeploy the DU resultant
The SBB POM.XML requires the information of the main project that composes, and has a description of itself and the dependences that requires de SBBs.
The sbb-jar.xml has the reference of the SBB POM.XML and also contains the path to the sbb.java and the events that implements.
Finally the service.xml has the description of the service (name, vendor and version) and has the reference to the artifact sbb (the same as sbb POM.XML and sbb-jar.xml).





1. Root folder POM.xml












Maven Project
Description of the Maven project
The description of folders that compose the project.
The repository ofthe JAIN SLEE projects.
The repository of the Maven-Du-plugin.





2.DU folder POM.xml




All POM.xml must implement
This is the description of the Base project.
This is the result Deployable Unit file
This is the list of sbb that we want to include on the project
The first plugin defines the MAVEN DU PLUGIN with the version you want to use
The second plugin defines the autodeploy (copy the resultant DU to the deploy folder of jboss). Make sure the path exists and the JBOSS_HOME system variable is configured in your system.
ATTENTION! The sbb dependency must has the same version as described on sbb-jar.xml (change $(pom.version) for 1.0 in this case, because our pom version is 1.0.0 and there is not any sbb vith 1.0.0 version.)


3. SBB folder POM.xml






All POM.xml must implement
This is the description of the Base project.
This is the Sbb description
There are the dependences that our Sbb.java needs




4. Service.xml on Project Root folder\du\src\main\resources\services











Service.xml Structure

This is the description of the JAIN SLEE Service.
This is the list of SBB includes on the JAIN SLEE Service
Priority




5. Sbb-jar.xml on Project Root folder\sbb\src\main\resources\META-INF












SBB-jar Structure
Description of the SBB
The events implemented on the SBB




6. Sbb.java on Project Root folder\sbb\src\main\java\“package”




package org.i2cat.slee.firstSteps.sbb;


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.slee.*;
import javax.slee.serviceactivity.ServiceActivity;
import javax.slee.serviceactivity.ServiceActivityFactory;
import org.apache.log4j.Logger;

public abstract class FirstSbb implements javax.slee.Sbb {

private static Logger logger = Logger.getLogger(FirstSbb.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())) {
logger.info("THIS IS A MESSAGE OF HOPE!!!");
}
aci.detach(this.sbbContext.getSbbLocalObject());
} catch (Exception e) {
logger.error("Can't handle service started event.", e);
}
}
public void setSbbContext(SbbContext context) { this.sbbContext = context; }
public void unsetSbbContext() { this.sbbContext = null; }
public void sbbCreate() throws javax.slee.CreateException {}
public void sbbPostCreate() throws javax.slee.CreateException {}
public void sbbActivate() {}
public void sbbPassivate() {}
public void sbbRemove() {}
public void sbbLoad() {}
public void sbbStore() {}
public void sbbExceptionThrown(Exception exception, Object event, ActivityContextInterface activity) {}
public void sbbRolledBack(RolledBackContext context) {}
protected SbbContext getSbbContext() {return sbbContext;}
private SbbContext sbbContext;
}



This code depends on the name of your SBB
This code affects to the folder tree.



In this example we use the same SBB code as the First Steps Tutorial. This SBB is packed into org.i2cat.slee.firstSteps.sbb and then we have to create the next folder tree into the Sbb\src\main\java. Also we have to rename the RootSbb.java to FirstSbb.java as we have described in the SBB-jar.xml in the sbb-classes tag.



7.Installation
Once we have the files and folder tree, we have to start the JAIN SLEE Server. The next step is open a command console, access to MyProject folder, and run: “mvn install”. Now maven will start downloading the dependences (it could take several minutes). When it finish, a Successful message must appear, and JAIN SLEE Server Console must show the Message of hope.
If there is any error in the xmls code, the JAIN SLEE Server console will show a message saying waiting to resolve dependences. You can consult the problem at:

http://localhost:8080/ JMX Console /service=JSLEEDeployer / java.lang.String showStatus()

For more information and help: http://groups.google.com/group/mobicents-public?hl=en


Tuesday, October 20, 2009

JAIN SLEE Example, How to implement a Resource Adaptor

Hello!
I am proud of share this new tutorial about how to implement Resource Adaptors into our JAIN SLEE projects. This tutorial explains how to implement the SIP-RA. This is the last starter tutorial, and I hope it will be helpful. I will continue editing new tutorial about more complex thematics soon.


Also you can see the complete tutorial in slides at:


http://docs.google.com/fileview?id=0B3DLDwLo_7WOOTliODkxNDEtMDQzNy00ZWIwLThlZmUtOTNiNGMzYjhhM2Y4&hl=en


To follow this tutorial you need:


ECLIPSE: Version: 3.3.1.1 Build id: M20071023-1652


EclipSLEE plugin v.1.2.4 - http://people.redhat.com/vralev/eclipslee/update/
Mobicents JAIN SLEE Server 1.2.5-GA - http://sourceforge.net/projects/mobicents/files/
Mobicents JAIN SLEE Resources SIP-RA-1.2.5
SIP Stack I have used the Ericsson Service Development Studio (SDS) that has a SIP client with a SIP stack that I knew.


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 (1.2.5) that runs over
eclipse 3.4 and 3.5 but still having some bugs.


NOTES:
Use the same RA that is included in the resources folder of JAIN SLEE Server zip file. If you use
JAIN SLEE 1.2.5 use the SIP-RA-1.2.5.jar


Let's start!



1 – Creating JAIN SLEE PROJECT
NEW – Project… – JAIN SLEE – JAIN SLEE PROJECT
Put the name of the project and Finish


2-Adding Resource Adaptor into JAIN SLEE Project
On the project Name in eclipse do right mouse button, properties, JAIN SLEE, ADD DU, and select the SIP-RA-1.2.5-GA.jar and Accept.





3 – Creating a Service Building Block (SBB)
Create a package on src, and do New - Other - JAIN SLEE - Service Bulding Block.
In the event selection you will find a list of events defined by the SIP-RA. In this case we choose a SIP INVITE and we modify the event selecting Event direction: Receive, choosing it as initial event and Initial event selector: Activity context.

Finally we select the JAIN SIP Type Binding.

Once we have created the SBB we find an onInvite funciton in the SBB.java where we implement our code that will be executed when the Server receive a SIP INVITE.
Our code is:
System.out.println("A SIP INVITE HAS BEEN RECEIVED!!!!!");


4 - Configuring the RA binding.
Before the creation of the Deployable Unit we have to create the RA bindings.
Over the Sbb.java right button, Modify Service Building Block, Resource Adaptor Bindings...
Put the factory name: slee/resources/jainsip/1.2/acifactory
Click on Edit binding, and click ADD
Object name: slee/resources/jainsip/1.2/provider
Entity Link: SipRA

Once we have created the entity we have to create the service and Deployable unit of the project.


5 - Preparing the Server
First of all, start the JAIN SLEE Server. Then, we have to deploy the Resource Adaptor (SIP-RA).
Once the RA is deployed you have to go to RESOURCES - click on JAINSIPRESOURCE ADAPTOR.
Create entity: SipRA and make click on Create
Then will appear the SipRA entity INACTIVE, click on SipRA name.

Edit properties and change the 127.0.0.1 ip by the private ip address, for example 192.168.x.x



Finally, bind a entity link: SipRA
Come back to Resources, and Activate the SipRA entity.


Now you can deploy the project DU, and activate the service




JAIN SLEE example. How to Create Sbb Child Relations

Hi again!
Here we have a new tutorial about how to create Sbb child relations.
Also you can download the full tutorial with all the sreenshots at:
http://docs.google.com/fileview?id=0B3DLDwLo_7WOOTQyNWY3ZWItYTc2ZC00NDQ1LWI4ZDAtMmY4N2ExYWJlODA2&hl=en

To follow this tutorial you need:

ECLIPSE: Version: 3.3.1.1 Build id: M20071023-1652
EclipSLEE plugin v.1.2.4 - http://people.redhat.com/vralev/eclipslee/update/
Mobicents JAIN SLEE Server 1.2.5-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 (1.2.5) that runs over
eclipse 3.4 and 3.5 but still having some bugs.

NOTES:
This example is based on OpenCloud tutorial. You can find it on the next Url.
https://developer.opencloud.com/devportal/display/OCDEV/Child+Relation+Echo+Service

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

To use this sbb as child of other sbb in a sbb tree you have to create the custom SBB local object interface. In this interface we must define the function that will implement this SBB child.



In this example we create a function with returns a Boolean that results by the comparison of a

String (message) with a String with value “bye”.

Code:

On localobjectSbb class:

public boolean isMessageAGoodBye(String message);

On sbb class:

private static final String BYE = "bye";

public boolean isMessageAGoodBye(String message){

return message.equals(BYE);}

3 – Creating a Root Service Building Block (SBB)

Now you have to create another SBB and when you use the wizard you find the option to add the previous sbb as child.

In the RootSbb.java is declared the child

public abstract ChildRelation getChildSbb();

In this example getChildSbb() is the child sbb.

On this sbb we will use the same system event as the First Steps Tutorial, and the code to execute will be the follow:

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("Response must be True -> Response: " +((ChildSbbLocalObject)getChildSbb().create()).isMessageAGoodBye("bye"));

}

// 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);

}

}

The important sentence on this code is:
((ChildSbbLocalObject)getChildSbb().create()).isMessageAGoodBye("bye")
that is the invokation to the child sbb, usign the child function and sending "bye" as parameter.

4 – Finishing the program

Finally you have to create the Service and the Deployable Unit as the previous tutorial explains (FirstSteps Tutorial).

5 – Executing the service.

After deploy the DU.jar, when you start the service, a message in the JAIN SLEE console must appear returning a True in the call to the SBB child. If you change the parameter "bye" in the code by other String, then, you must see in the JAIN SLEE Server console, a false.

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.