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.