In a previous article I already mentioned Direct Web Remoting (DWR), the best AJAX-library I encountered up to now. I just had the time to re-discover it, as I sought something to get back to my Java skills. This library really keeps one promise: it really starts making fun to develop web-applications with AJAX. A short summary: DWR provides a very easy means for calling server-side methods which are hosted in a Java Servlet Container like Tomcat or Jetty. It masks the communication effort by providing client-side abstraction to the method calls of exported Java methods, so remote calls look local to the developer.
The new version 2.0 (release-candidate) introduces a new concept, which they call “reverse AJAX“. Reverse AJAX allows the server to asynchronously send data to its clients. It works by either polling, persistent connection or additional information on your next AJAX call. It means, that the server at any time can push data to the client, without the client’s request. In “persistent connection” this works almost “real-time”, while polling takes at least a poll-interval to notice the new information and additionally increases load on the server.
This feature allows highly interactive applications where new information can be published right away, in best case without noticeable delay. Developing a simple chat-application becomes the matter of just a few lines of server-side code.
For an example of what you can easily do now, look at this example (fake) stock ticker, which updates the data on the client without the client being required to poll for changes. Also note the simple, yet cool, inclusion of script.aculo.us effects during the update. (Hint: you need to move the mouse over the table for the application to start.)
The downside is, the feature is still in an early stage of development, it still has some problems. On my Gentoo Linux box, I can reproducibly increase my CPU load to 100% by duplicating a tab with an open persistent connection in Opera. In Firefox, duplicating the tab leads to normal AJAX calls to no longer function with about 50% chance. If Firefox enters this mode, it will queue up
XMLHttpRequest causing a “normal” call to be queued behind the persistent call which will be kept open for around 60 seconds if no data is pushed from the server or even longer, if there is data. This of course makes it almost unusable at the moment, unless you can be sure, users won’t hit your site twice within the same session and/or are not using tab-duplication.
I’m really looking forward to this feature becoming stable, this is so cool and you can do so much awesome stuff with it. Thanks to all developers for their great work!