Thursday Jun 17, 2010

SailFin-CAFE GreetingService Demo

SailFin-CAFE provides functionality to create conversation between User and MediaGroup. For instance, a simple snippet for playing an announcement to a user would look like:

   Player p = session.createParticipant(Player.class, "myPlayer");
   Conversation conv = session.createConversation(p);
   conv.addParticipant("alice@example.com");

CommunicationBeans can be used to listen media events, DTMF signals and many other events, based on which application logic can be decided.

Listener for media event when a player(announcement) is finished would be:

    @CommunicationEvent(type = CommunicationEvent.Type.MEDIAENDED)
    public void mediaEnded() {
        ----- application logic ------
    }

DTMF Signal is intercepted through CommunicationEvent type MessageArrived:

    @CommunicationEvent(type=CommunicationEvent.Type.MESSAGEARRIVED)
    void handleMessage() {
        DtmfSignal ds = (DtmfSignal) ctx.getMessage();
        String signal = ds.getSignal();
    }

At the same time Communication API makes it very handy to replace participants in a conversation. eg. Replacing a user with media group or vice-versa.

All this makes it quite simple to write applications like GreetingService. The basic idea of a GreetingService is to allow users to record messages to be played to their friends at a particular date and time.

Following image illustrates the above:

Greeting Service Example

In the above scenario Alice wants to wish Bob, so she logs in and schedules a greeting for Bob. GreetingService calls Alice for recording the message, CommunicationBean is used to play initial announcement and receive DTMF signals to start/stop recording the message. 

Once the recording is finished, an agent(GreetingAgent) is invoked to schedule the Greeting. GreetingAgent calls recepient at scheduled time and plays announcement informing about the Greeting.

Based on the DTMF response of the recepient, greeting is either played or rejected. Sender is informed about the status of the Greeting through an InstantMessage.


  • The sample can be checked out at : http://svn-mirror.glassfish.org/sailfin-cafe/trunk/cafe-samples/GreetingService/
  • Useful Links : http://weblogs.java.net/blog/binod/archive/2009/12/31/sailfin-cafe-fundamentals-communicationbeans-and-agents
  • http://weblogs.java.net/blog/binod/archive/2010/05/14/sailfin-cafe-using-presence-and-conversation-together

Monday Jan 04, 2010

REST based hybrid(OSGI + JavaEE) - OSGI Framework Controller

GlassFish V3 comes with an OSGI Web Container, which provides the support for development of hybrid applications.

A hybrid application is a combination of Java EE and OSGI. More information about developing a simple hybrid application can be found here.

This blog entry describes about a REST based Web Application Bundle to control OSGI Framework.

Steps for the setup:

1. Download and install latest nightly build of glassfish-v3 from here.
2. Start the server using : asadmin start-domain
3. Download the OSGI Web Container bundle form here.
       Install it by copying the downloaded jar file to glassfishv3/glassfish/domains/domain1/autodeploy-bundles directory.
4. Get the ready to install REST based OSGI Framework controller OR

The complete netbeans project is available here. The project built with netbeans generates a plain war file, to make it an OSGI bundle, we need to update the MANIFEST.MF entry. Update the generated war by using the following command:
       jar -uvfm REST_WAB.war MANIFEST.MF

5. Install the application by copying it to glassfishv3/glassfish/domains/domain1/autodeploy-bundles directory. Server log will indicate the success of installation.
6. Use your browser to access the URL : http://localhost:8080/REST_WAB
       Click on View Bundles to get the status of modules in GlassFish v3. The framework controller allows for the install/uninstall, start/stop of the OSGI bundles.

rest framework controller
OSGI Framework Controller

Getting the OSGI Framework Bundle Context in a REST Application:

-- get the servlet context as:
        @Context ServletContext ctx;

-- getting the org.osgi.framework.BundleContext:
         BundleContext bundleContext = (BundleContext) ctx.getAttribute("osgi-bundlecontext");

The bundleContext can be used for running the OSGI Framework related commands.

About

Mohit Gupta

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today