Skip to main content

[v3] Comet/Bayeux available in GlassFish v3

5 replies [Last post]
Anonymous

Hi,

You can now use Comet or the Bayeux Protocol (cometd) in GlassFish v3
[1]. I didn't yet enabled it by default because it reduce performance a
little when you stress the server, so if you want to try it, just add
(this is temporary):

-Dv3.grizzly.cometSupport=true

or add the cometSupport element domain.xml like it is described in [1].

Thanks

-- Jeanfrancois

[1]
http://weblogs.java.net/blog/jfarcand/archive/2008/02/comet_support_i.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sendtopms
Offline
Joined: 2004-11-23

I am currently proposing Architecture based on Comet on Glassfish for an enterprise application. One of the nice feature in GF is Comet. I looked at few comet samples like chat, echo etc on GF. My question how can I expose changes in other enterprise components, for example, ejb3.0 to be pushed to the client which uses Dojo cometd?
I did not find any extension point in com.sun.grizzly.cometd.servlet.CometdServlet! Is there any other way which I missed? I read through most of your blogs but not able to find an answer for the above question. Basically I am looking for integration point using which I can hook messages from other entity componets which detect the data to be pushed to the client.

Please guide me on this. Expecting reply. I am using GF 2 UR1.

Thanks in Advance,
Senthilkumar.

Message was edited by: sendtopms

Jeanfrancois Arcand

Salut,

we have a new users list for Comet and Web related technologies. I'm
cc-ing them :-)...and a soon a project called atmosphere.dev.java.net :-)

glassfish@javadesktop.org wrote:
> I am currently proposing Architecture based on Comet on Glassfish for an enterprise application.

Cool.

One of the nice feature in GF is Comet. I looked at few comet samples
like chat, echo etc on GF. My question how can I expose changes in other
enterprise components, for example, ejb3.0 to be pushed to the client
which uses Dojo cometd?

From a non web component, there is two ways to interact with a
CometContext:

(1) Pushing data from your external component (like an ejb).

From you external component, get a reference to the CometContext you
are interested for. For example, you can have that code snippet inside
your ejb:

CometContext ctx = CometEngine.getEngine().getCometContext("foo");
ctx.notify(...some data from you ejb...);

By calling notify(), all CometHandler registered to the CometContext
will receive the data. Hence, all web client will be updated from/by
your ejb.

(2) Register a CometHandler to be notified when push operations happens.
As an example, from your ejb you can do:

CometContext ctx = CometEngine.getEngine().getCometContext("foo");
ctx.addCometHandler(this); //assuming your ejb implements CometHandler

Now every time data is pushed, you ejb will be notified.


I will give a demo of a database that updates web clients (and clients
that update the db using comet) at CommunityOne if you can come:

http://www28.cplancom/cc197/session_details.jsp?isid=297346&ilocation_id...

It does (1) and (2) :-)

> I did not find any extension point in com.sun.grizzly.cometd.servlet.CometdServlet! Is there any other way which I missed? I read through most of your blogs but not able to find an answer for the above question. Basically I am looking for integration point using which I can hook messages from other entity componets which detect the data to be pushed to the client.

Something Jetty have and we don't right now is a way to send json/bayeux
messages from an external component like that:

http://cometdaily.com/2008/04/17/svnsearch-adds-real-time-updates/

We are working on it, but right now if you are planning to use
cometd/bayeux, just register your CometHandler to:

CometContext ctx = CometEngine.getEngine().getCometContext("/cometd");
ctx.addCometHandler(this);

This company:

http://web.mac.com/altmobile/altmobile_blog/ALT_Mobile_Blog/Entries/2008...

is using this approch for it product and it seems to work fine :-)

Hopefully the above will help :-)

Thanks!

-- Jeanfrancois

>
> Please guide me on this. Expecting reply.
>
> Thanks in Advance,
> Senthilkumar.
> [Message sent by forum member 'sendtopms' (sendtopms)]
>
> http://forums.java.net/jive/thread.jspa?messageID=271139
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

sendtopms
Offline
Joined: 2004-11-23

Hi JFA,
Thanks for the prompt response. I was trying to do the same thing which you have explained before posting my initial query in this forum. But not able to get the notification sent over to client.
I did following for the experiment,
1. I took your chat application with Dojo
2. Added one more servlet called ChangePusher
3. I added following code in the doGet and doPost methods
CometEngine cometEngine = CometEngine.getEngine();
CometContext cometContext = cometEngine.getCometContext(contextPath);
cometContext.notify("Got Message from ChangePusher" + info);
here, contextPath="pmschat" I modified in the CometdServlet's init parameter.

Pls look at the attached files for web.xml and my new servlet whcih try to push data to the cometcontext.
I believed that when i invoke ChangePusher servlet, it will notify the cometcontext and hence all the client should be able to see the message. But it is not happening. Please let me know, if i miss something.

* Can you add some logging into comet framework? It will help me trace the flow.
Thanks in advance

Message was edited by: sendtopms

Jeanfrancois Arcand

glassfish@javadesktop.org wrote:
> Hi JFA,
> Thanks for the prompt response. I was trying to do the same thing which you have explained before posting my initial query in this forum. But not able to get the notification sent over to client.
> I did following for the experiment,
> 1. I took your chat application with Dojo
> 2. Added one more servlet called ChangePusher
> 3. I added following code in the doGet and doPost methods
> CometEngine cometEngine = CometEngine.getEngine();
> CometContext cometContext = cometEngine.getCometContext(contextPath);
> cometContext.notify("Got Message from ChangePusher" + info);
> here, contextPath="pmschat" I modified in the CometdServlet's init parameter.
>
> Pls look at the attached files for web.xml and my new servlet whcih try to push data to the cometcontext.
> I believed that when i invoke ChangePusher servlet, it will notify the cometcontext and hence all the client should be able to see the message. But it is not happening. Please let me know, if i miss something.
> Thanks in advance

The attachment haven't made it. Can you send it to me directly: jfarcand
at apache.org

Thanks!

-- Jeanfrancois

> [Message sent by forum member 'sendtopms' (sendtopms)]
>
> http://forums.java.net/jive/thread.jspa?messageID=271615
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

sendtopms
Offline
Joined: 2004-11-23

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 = "<>";
String user = "<>";

HashMap map = new HashMap();
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":"<>","user":"<>"},"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.