Skip to main content

Woke From Dreaming

Posted by editor on March 22, 2007 at 7:18 AM PDT

Giving your clients a kick

Aren't distributed events a fun problem to solve? It was nearly ten years ago that I read and was profoundly inspired by a HotWired (remember them?!) article, Writing Chat Systems with Java 1.1's RMI, which showed how to build a chat system that used RMI to asynchronously send new messages to all the participants (or let two participants exchange messages directly, without touching the server). In fact, a year or two later, I designed a client-server system that put a nice, clean event listener metaphor around RMI communication, so the Swing clients would get asynchronous updates from the server when new media arrived that they'd be interested in. It worked great, so long as you didn't get hosed by RMI's inexplicable and evil reverse-DNS lookup, which is a rant for another time. If I had it to do over, I'd probably use Jini, since it would be more robust and tolerant of failure (and I was already pretty pro-active about dead clients). But suffice to say that asynchronous updating of clients is one of those interesting problems you see over and over again.

To wit, what if instead of a nice thick Swing client on the LAN, your client is a web page somewhere halfway across the internet? And what if the nature of your application still calls for the server to send asynchronous notifications to the client? This is handily addressed by the Direct Web Remoting Ajax framework, and its new "Reverse Ajax" feature. Katherine Martin has details in
our Feature Article,
Developing Applications Using Reverse Ajax.

DWR, hosted on, is a Java open source library that helps developers to write websites that include Ajax technology. When DWR broke onto the Ajax scene with release 1.0, its announced mantra was "Easy Ajax for Java." It aids the developer in many ways, not least by allowing code in the web browser to use Java functions running on the web server as if they were in the browser.

With release 2.0, DWR continues on the same theme, removing from the developers shoulders the pesky problem of "pushing" information. It introduces the term reverse Ajax to describe this asynchronous transfer of messages from server to browser or browsers. While, as mentioned above, techniques for doing this already exist, the beauty of "reverse Ajax" is that it wraps them all up neatly and then automatically selects the best method to use transparently to the user.

In a nice bit of irony, the sample code for Katherine's code, included as part of the DWR 2.0 application, is a chat application... just like the HotWired article from 10 years ago. The more things change, the more they stay the same.

In Java Today,
the just-announced (and still-incubated) GWT4NB project is an effort to develop a NetBeans module to support Google Web Toolkit development. GWT is "is an open source Java software development framework that makes writing AJAX applications (...) easy for developers who don't speak browser quirks as a second language." GWT4NB's features include using GWT with new or existing web projects,
deploying, running, and debugging GWT-enabled Web Apps using and arbitrary application server, and
assistance to deal with some code editing nuances such as creating services efficiently.

The JAXP project, the reference implementation of the Java API for XML Processing, has released Version 1.4.1. This is the first patch since JAXP 1.4 was released in October, and among 36 issues addressed, it fixes a regression in which DOM generated by code from a DocumentBuilder using DOM level 1 methods (createElement, etc) fails validation against an XML schema.

Not clear on the point of portlets, or where the spec stands today? Get a reset from the SDN article Introducing Java Portlet Specifications: JSR 168 and JSR 286. "In February 2006, the JSR 286 Expert Group was formed to start work on Java Portlet Specification 2.0. When that is finalized, backward compatibility will be in place: JSR 168 portlets will be able to run seamlessly in JSR 286 portlet containers. No recompilation will be necessary. This article spotlights JSR 168 and the associated software, Portlet Container 1.0 and the NetBeans Portlet Plug-in. Also described are sample portlets and JSR 286 in its draft state."