users@grizzly.java.net

Re: grizzly-cometd-bayeux not sending messages to all subscribed clients.

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 15 Jul 2009 21:13:41 -0400

Salut,

apology for the delay.

Abey Tom wrote:
> Hi
>
> I'm working with the sample application
> 'grizzly-cometd-bayeux'(/samples/comet/cometd-javaapiupdate-chat). I use
> 'grizzly-cometd-webserver-1.9.18-SNAPSHOT.jar' to deploy the war.
>
> I subscribed to multiple channels in the file chat.js. But the messages are
> getting published ONLY to the LAST subscribed channel and NOT to the others.
>
> Please find my code changes below.
> _______________________________________________________________________
> chat.js : I modified the function room.join(). Added the 3 lines to
> subscribe.
>
> join: function(name){
> if(name == null || name.length==0 ){
> alert('Please enter a username!');
> }else{
> dojox.cometd.init(new
> String(document.location).replace(/http:\/\/[^\/]*/,'').replace(/\/\/.*$/,'\/cometd')+"/cometd");
> this._username=name;
> dojo.byId('join').className='hidden';
> dojo.byId('joined').className='';
> dojo.byId('phrase').focus();
>
> // Really need to batch to avoid ordering issues
> dojox.cometd.startBatch();
> dojox.cometd.subscribe("/chat/demo", room, "_chat");
>
> //Change start
> dojox.cometd.subscribe("/chat/demo1", room, "_chat");
> dojox.cometd.subscribe("/chat/demo2", room, "_chat");
> dojox.cometd.subscribe("/chat/demo3", room, "_chat");
> //Change End
>
> dojox.cometd.publish("/chat/demo", { user: room._username, join:
> true, chat : room._username+" has joined"});
> dojox.cometd.endBatch();
> }
> }
>
> ____________________________________________
> com.sun.grizzly.bayeux.BayeuxExternalServlet.init() : Publishes to all
> subscribed channels.
>
> timer.scheduleAtFixedRate(new Runnable() {
> public void run() {
> CometEngine engine = CometEngine.getEngine();
> String channels[] = { "/chat/demo", "/chat/demo1", "/chat/demo2",
> "/chat/demo3" };
> for (int i = 0; i < channels.length; i++) {
> String topic = channels[i];
> CometContext context = engine.getCometContext(topic);
> if (context != null) {
> System.out.println("wake up call for " + topic);
> Map<String, Object> map = new HashMap<String, Object>();
> map.put("chat", "Wake up call from the chatroom :-) to "+topic);
> map.put("user", "ChatPigner");
> Data data = new Data();
> data.setMapData(map);
> data.setChannel(topic);
> DeliverResponse deliverResponse = new DeliverResponse();
> deliverResponse.setChannel(topic);
> // deliverResponse.setClientId("");
> deliverResponse.setData(data);
> deliverResponse.setLast(true);
> deliverResponse.setFollow(true);
> deliverResponse.setFinished(true);
> try {
> context.notify(deliverResponse);
> } catch (IOException ex) {
> ex.printStackTrace();
> }
> ;
> }
> }
> }
> }, 10, 3, TimeUnit.SECONDS);
>
>
> when I debugged, the CometContext.handlers() is Empty for all the channels
> except for the /chat/demo3, which is the LAST subscribed one.
> BUT if I send a message from the webpage, its is published properly
> irrespective of the channel.

Hum sound likes a bug, but could it be on the client side? Can you share
a test case I can use to reproduce the issue?

Thanks!

-- Jeanfrancois


>
> Is my approach wrong or is there a bug in the code?
>
> Let me know if anything else is required.
> Screenshot of the app: http://www.nabble.com/file/p24460710/Clipboard01.jpg
> Clipboard01.jpg
>
> Thanks
> Abey Tom
>
>