users@glassfish.java.net

Re: Grizzly Comet in clustered enviroment

From: Jung-Shuo Pai <pikapai_at_gmail.com>
Date: Fri, 4 Jul 2008 15:42:00 +0800

Hi! Jeanfrancois & Shreedhar

Thank you for the quick response. I'll try the proposed solution!

Maybe, in the future release, the notification mechanism in Grizzly Comet
can be applied to clustered environment in a more transparent way.

For now, I'll just use the messaging solution to propagate the notification
across the clustered machines.

Thank you for all the hard work.



On Fri, Jul 4, 2008 at 12:11 AM, Shreedhar Ganapathy <
Shreedhar.Ganapathy_at_sun.com> wrote:

> Hi JFA
> You could consider using Shoal for this purpose. Benefit over JMS is that
> no separate broker process is required. It is also a portable solution.
>
> Shoal provides cluster event reporting and intra cluster messaging. It
> would have the positive side effect of helping us improve performance as
> well.
>
> Here's a simple example :
> https://shoal.dev.java.net/SimpleShoalGMSSample.java
> May need some simple alterations to fit the example snippet you have
> provided in the previous email.
>
> Let me know if you have any further questions on this.
>
> Thanks
> Shreedhar
>
>
> Jeanfrancois Arcand wrote:
>
>> Salut,
>>
>> (cross posting to users_at_grizzly as similar question has been asked
>> recently)
>>
>> Jung-Shuo Pai wrote:
>>
>>> Hi there:
>>> Currently, I am trying to upgrading our previous website running on
>>> TOMCAT 5.5 to a clustered environment run by Glassfish.
>>> In our application, we use the Grizzly Comet API to do the following
>>> thing:
>>>
>>> A Flash client requests a URL, say /Send , and we'll keep a
>>> connection for this client, but add a handler for the client until
>>> someone notify it.
>>> A software will call another URL, say /Return, and the handler
>>> for
>>> the Flash client will be notified.
>>>
>>> The Flash client will then receive & display a message from
>>> the server before the connection is closed.
>>>
>>> However, this application only works in single-server scenario.
>>> In clustered environment, if the Flash client request URL on server A,
>>> but the software request URL on server B, then the Flash client will never
>>> return.
>>> The typical example of Grizzly Comet API is the Chatroom application.
>>> But even in this application, the issue I mentioned still exists.
>>>
>>
>> Right. In a clustered environment, requests that are suspended on serverA
>> cannot be notified by an event in server B. The proposed solution is to use
>> JMS in between server A and server B, and hook the JMS listener/published
>> using the Grizzly's NotificationHandler[1][2]. As an example, a
>> JMSNotificationHandler could be implemented as (warning: last time I looked
>> at JMS was in ...2002 so the code might be bogus :-))
>>
>>
>> When you create your CometContext, just do:
>>
>> cometContext.setNotificationHandler(new JMSNotificationHandler());
>>
>> [ ** Pushing Data between Server A and B ** ]
>>
>> The JMS enabled NotificationHandler looks like
>>
>> public class JMSNotificationHandler extends DefaultNotificationHandler{
>>
>> public void notify(CometEvent cometEvent<String>, Iterator<CometHandler>
>> iteratorHandlers){
>>
>> //(1) Notify our local CometHandler
>> super.notify(cometEvent,iteratorHandlers);
>>
>> //(2) Notify our remote instance
>> // Assuming we are using JMS Topic
>> TopicPublisher publisher = .....;
>> TextMessage jmsTextMessage = ....;
>>
>> // The attachment contains the message we want to push)
>> jmsTextMessage.setText(cometEvent.attachment());
>> publisher.publish(jmsTextMessage);
>> }
>>
>>
>> [ ** Receiving Data from Server A or B **]
>>
>> public class MyJMSCometLister implements MessageListener{
>>
>> public void onMessage(Message message){
>> TextMessage textMessage = (TextMessage) message;
>> CometContext myCometContext = CometEngine.getCometContext(<<your
>> context>>);
>> myCometContext.notify(message.getText()); }
>> }
>>
>> Technically, every time a Server event (a PUSH) will occurs, all
>> CometHandler.onEvent() will be called independently of their location
>> (server A or B).
>>
>> Is there any possible wayI can resolve the issue happening in the
>>> clustered environment?
>>> Thank you for taking a look at my question.
>>> Best Regards,
>>>
>>
>> Hope that help.
>>
>> A+
>>
>> -- Jeanfrancois
>>
>>
>> [1] https://grizzly.dev.java.net/nonav/apidocs/index.html
>> [2]
>> http://weblogs.java.net/blog/jfarcand/archive/2007/03/new_adventures_1.html
>>
>>> John
>>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>


-- 
Best regards,
Pai, Jung-Shuo
===================================
Master's degree:
Graduate Institute of Information Management
National Sun Yat-sen University
Bachelor's degree:
Department of Management of Information Systems
National Chengchi University
Sun Certified JAVA Programmer 1.4
Mobile phone: 886+ 953404037
E-mail: pikapai_at_gmail.com