- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
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?
Leave a comment
About Pathfinder
Recent
- IE8 Beta 2 Released
- Faster JavaScript for Firefox 3.1 Thru JIT
- Implementing linked multiselects with jQuery, LiveQuery, and Low Pro: Part 2: First pass at the actual code
- I’m Cranky Because I’m Not Getting Enough REST
- Flex Gauge Component Example with source
- Plugging Some Cool Tools
- Implementing linked multiselects with jQuery, LiveQuery, and Low Pro: Part 1: Requirements and interaction design
- Many Varied Components, or… Multi Variable Complexity, or… Mainly Vanilla Coding
- Custom Flex 3 Lightweight Preloader with source code
- Mass Assigning Inheritance Column Values for ActiveRecord STI with Rails
Archives
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006

