users@glassfish.java.net

Re: [v3] Comet/Bayeux available in GlassFish v3

From: <glassfish_at_javadesktop.org>
Date: Wed, 30 Apr 2008 09:20:22 PDT

I tested below code on Glassfish v2UR2 (I hope it will work with UR1 too).
There are 3 ways on which components (Servlet/Ejb/Pojo etc) can participate in Bayeux/Comet message/data exchange.
1. Just Post or Push the message to particular Channel in the Context, so whoever register to listen to the channel get the message Posted/Pushed,
      Here is how I used Servlet to post a message to particular channel in the Context.
      
              String message = "<<Your message>>";
              String user = "<<who am I>>";

              HashMap<String, Object> map = new HashMap<String, Object>();
              map.put("chat", message);
              map.put("user", user);
              Data data = new Data();
              data.setMapData(map);
              data.setChannel("/chat/demo");
              data.setClientId("ejb6312");
              
              CometEngine cometEngine = CometEngine.getEngine().getCometContext(contextPath).notify(data);
              
              Note: HashMap and Data is a wrapper to create a bayeux message of the following form
             /*[{"successful":true,"channel":"/chat/demo","timestamp":"Wed, 30 Apr 2008 15:43:34 GMT","id":"5"},{"id":"5","timestamp":"Wed, 30 Apr 2008 15:43:34 GMT","data":{"chat":"<<Your message>>","user":"<<who am I>>"},"channel":"/chat/demo"}]*/. For more information please look at bayeux spec and JFA's dojo chat application.
         

2. Just Listen to particular Channel in the Context - whatever components which implements handler can listen to and obtain messages. It can be useful for implementing clients for broadcasting kind of situations or react to certain events of its interest (Dashboard, progress monitoring etc).

3. Listen and Post/push the message over the Channel on the context - will be useful for Chat/Collaboration kind of application
     I used JFA's dojo based chat application. It can be tested with opening JFA'a chat application using 2 different browser, so message send from one browser is shown in the other browser. Here message is visible both the side. It is like JMS topic subscribed consumer - bayeux server will publish message to all the listening client.
     
     Special thanks to JFA who helped me to resolve the issue. ..

     Thanks,
     Senthilkumar PM.
[Message sent by forum member 'sendtopms' (sendtopms)]

http://forums.java.net/jive/thread.jspa?messageID=272256