dev@grizzly.java.net

Re: [Heads up][Cometd] Example of javaapi for cometd updated.

From: <aalcamo_at_gofurthercorp.com>
Date: Wed, 28 Jan 2009 17:48:25 -0500 (GMT+5)

====================================================================
Here is the first HTTP Request (to connect) sent to the first client
Note: the callback in pos.js, _chat, IS NOT executed
====================================================================

POST /Screen//cometd HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer: http://localhost:8080/Screen/?user=Anthony
x-requested-with: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR
1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR
3.0.04506.648; MS-RTC LM 8; InfoPath.2)
Host: localhost:8080
Content-Length: 166
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=f5e9ae98e55b603a1883763cfcdd;
JSESSIONID=6A0EA5F55F88E2DE740847C8E2809A8D

message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fconnect%22%2C%22connectionType%22%3A%22long-polling%22%2C%22clientId%22%3A%22d00de6376f523579%22%2C%22id%22%3A%225%22%7D%5D

HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0
Server: GlassFish/v3
Content-Type: application/json-comment-filtered;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Wed, 28 Jan 2009 22:32:18 GMT




====================================================================
Here is the second HTTP Request (to connect) sent to the first client
Note: the callback in pos.js, _chat, IS executed, causing the posFrame
to be redirected to another port/page.
====================================================================

GET
/JBossPush/new.jsp?agentID=[agent%20ID]&callType=[call%20type]&callerID=[caller%20ID]&mid=[m%20ID]
HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/xaml+xml, application/vnd.ms-xpsdocument,
application/x-ms-xbap, application/x-ms-application,
application/vnd.ms-excel, application/vnd.ms-powerpoint,
application/msword, application/x-shockwave-flash, */*
Referer: http://localhost:6080/JBossPush/
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR
1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR
3.0.04506.648; MS-RTC LM 8; InfoPath.2)
Host: localhost:6080
Connection: Keep-Alive
Cookie: JSESSIONID=6A0EA5F55F88E2DE740847C8E2809A8D

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Wed, 31 Dec 1969 19:00:00 EST
X-Powered-By: Servlet 2.4; JBoss-4.2.0.GA (build: SVNTag=JBoss_4_2_0_GA
date=200705111440)/Tomcat-5.5
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 1037
Date: Wed, 28 Jan 2009 22:32:48 GMT

POST /Screen//cometd HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer: http://localhost:8080/Screen/?user=Anthony
x-requested-with: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR
1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR
3.0.04506.648; MS-RTC LM 8; InfoPath.2)
Host: localhost:8080
Content-Length: 166
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=f5e9ae98e55b603a1883763cfcdd;
JSESSIONID=6A0EA5F55F88E2DE740847C8E2809A8D

message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fconnect%22%2C%22connectionType%22%3A%22long-polling%22%2C%22clientId%22%3A%22d00de6376f523579%22%2C%22id%22%3A%226%22%7D%5D

HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0
Server: GlassFish/v3
Content-Type: application/json-comment-filtered;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Wed, 28 Jan 2009 22:32:48 GMT



Jeanfrancois and Shing Wai,
As per Alexey's morning call, I am attaching my source code related to
this issue. Note that my CometdServlet.java does not extends
com.sun.grizzly.cometd.servlet.CometdServlet right now, as I brought code
in from that class to try patching. Please help as soon as you can.
Thanks,
Anthony


Jeanfrancois,

We have been testing with this new drop and example code all day. This
seems to work better, but there is still a problem. I'm not sure what is
causing this behavior, but it is consistent each time we test.

Here's what happens:
1. client 1 logs on
2. servlet sends message to client 1 sucessfully
3. client 2 logs on
4. servlet attempts to send message to client 1, but fails
5. servlet sends message to client 1 sucessfully

In other words, each time a new client subscribes, each
previously-subscribed client must be sent one message from the servlet
(which does not get sent) before that client can sucessfully receive any
new messages.

Here's another way to describe it: when a new client logs on, in order for
any of the other clients to receive a new message, it must be sent from
the server to the client twice.

I hope this makes sense. If you know of a work around, please let us
know.

Thanks,
Anthony

-------

Salut,

first, I apologize for the recent regressions observed with cometd, in
both GlassFish v2 (grizzly 1.0.22) and v3 (1.9.x). We wioll improve our
testing and avoid such major regressions.


we recently updated the way cometd/bayeux has been implemented on top of
Grizzly Comet. During that re-factoring we have made some major
performance improvement and modified a little how the JavaAPI can be
used. A simple demo can be downloaded here:

http://download.java.net/maven/2/com/sun/grizzly/samples/grizzly-cometd-bayeux/1.9.5-SNAPSHOT/


Mainly, you can test it using the grizzly-cometd-webserver.jar
downloaded from here (hudson seems broken, so make sure you download the
20090126 war file).

http://download.java.net/maven/2/com/sun/grizzly/grizzly-cometd-webserver/1.9.5-SNAPSHOT/

You can run the demo by doing:

java -jar grizzly-cometd-webserver.jar -p 8080 -a
grizzly-cometd-bayeux.war com.sun.grizzly.bayeux.BayeuxExternalServlet.

In that demo, request which takes the form of:

http://host:port/BayeuxExternalServlet/?message=hello,user=moi

will update the cometd-chat demo bu using the JavaAPI. The demo is
simple and can be read from here:

https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/bayeux/BayeuxExternalServlet.html

The code looks like:

> 133 @Override
> 134 public void doPost(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
> 135 String message = request.getParameter("message");
> 136 String user = request.getParameter("user");
> 137 ServletOutputStream out = response.getOutputStream();
> 138
> 139 CometEngine engine = CometEngine.getEngine();
> 140 CometContext context = engine.getCometContext(channel);
> 141
> 142 if (context != null && message != null) {
> 143 Map<String, Object> map = new HashMap<String, Object>();
> 144 map.put("chat", message);
> 145 map.put("user", user);
> 146 Data data = new Data();
> 147 data.setMapData(map);
> 148 data.setChannel("/chat/demo");
> 149
> 150 DeliverResponse deliverResponse = new DeliverResponse();
> 151 deliverResponse.setChannel("/chat/demo");
> 152 deliverResponse.setClientId("");
> 153 deliverResponse.setData(data);
> 154 deliverResponse.setLast(true);
> 155 deliverResponse.setFollow(true);
> 156 deliverResponse.setFinished(true);
> 157
> 158 context.notify(deliverResponse);
> 159
> 160 out.println("Data is sent.");
> 161 System.out.println("Data is sent.");
> 162 } else {
> 163 out.println("No data is sent.");
> 164 System.out.println("No data is sent.");
> 165 }

The main changes from previous version are:

+ No needs for invoking DeliveryResponse.setFinished(...); This was
added after Shing Wai blog and it seemed to break backward
compatibility. Hence we have listened and removed this new API.

+ Now you can lookup CometContext using the channel instead of the
context-path of the Servlet. This was required to allow more than one
channel update from a single Servlet.

All of those changes has been backported to Grizzly 1.0.23. Please gives
us feedback so we can fix regression as soon as possible.

Thanks

-- Jeanfancois










---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
For additional commands, e-mail: users-help_at_grizzly.dev.java.net





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
For additional commands, e-mail: users-help_at_grizzly.dev.java.net