Agile Ajax

GWT and Comet - Using GWT with Jetty Continuations

Let's review: Comet basically means keeping an HTTP connection open between the server and the browser so the former can stream messages to the latter without polling (see the Ajax Patterns page on HTTP Streaming for info on how it's done). This poses a problem for commonly used web infrastructure, like app servers, which usually associate one thread per connection. If you have lots of open connections, let's say 10,000, then you will need that many threads that are doing very little but sitting around waiting for the next message to be sent. Regardless of OS, 10,000 threads puts a pretty heavy load on a system. As a solution, Greg Wilkins proposed an extension of the Servlet standard to allow "continuations." What are they?

A java Filter or Servlet that is handling an AJAX request, may now request a Continuation object that can be used to effectively suspend the request and free the current thread. The request is resumed after a timeout or immediately if the resume method is called on the Continuation object.

Continuations, while not a part of the Servlet standard, are available in Jetty 6.

GWT, or the Google Web Toolkit, is the client-side framework that let's you write and debug your application in Java, then deploy it as Javascript.

Whew! Now that the explanations are out of the way, I can tell you that Greg Wilkins (of Jetty Continuations fame) has been noodling about how to get GWT to do Comet, specifically using Jetty's continuations.

Unfortunately GWT has not made it easy to use continuations within their RPC mechanism. Firstly they catch Throwable, so he Jetty RetryException is caught. Secondly they have made most of the methods on the GWT servlet final, so you cannot fix this by extension.

Luckily GWT is open source under the apache 2.0 license, so it was possible to do a cut/paste/edit job to fix this. The OpenRemoteServiceServlet recently added to Jetty is [a] version of GWTs RemoteServiceServlet without the final methods and a protected method for extending exception handling.

Once the GWT remote service servlet has been opened up, it is trivial to extend it to support Continuations...

There's enough code and pointers in the article to make it an effective, if short, howto. Apparently http://www.gpokr.com/ uses these extensions to GWT in its app, so it's proven in production.

Update: I see that there is an entry entitled "RemoteServiceServlet refactoring to be pluggable" in the GWT 1.4 dev plan. Is this what I think it is?


Technorati : , , , ,

Topics: ,

Leave a comment

Powered by WP Hashcash

About Pathfinder

  • We design and build extraordinary applications for companies looking to make the next great idea a reality.
  • learn more

Topics

WordPress

Comments about this site: info@pathf.com