Tuesday, October 20, 2009

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.