Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Subject-oriented programming through RMI

Create a shared experience with the 'subject' design pattern

How do you make software that allows a number of people to work together on the same group of things? Think of air traffic control, logistics planning, multiuser games, whiteboarding, or even software development itself. In each of these examples, there is both a group of people and a set of the things they're working on, and what we really want to do is create a little universe in which they can all exist and interact with each other in realtime.

This little universe, of course, isn't new -- it's been accomplished in many ways in many different situations. But at some point we must ask ourselves if there is a more overarching way to solve this recurring problem.

This article describes just such a solution -- one I've built using Java's elegant Remote Method Invocation (RMI). The Java code required to build the necessary infrastructure for this kind of software is remarkably minimal, and the result is extremely flexible.

'Subjects' defined

While writing about this software problem or trying to explain it in the classroom or to my clients, I've found that I constantly use the phrase "objects-of-interest" in order to describe the thing -- whatever it might be -- that a given group of people was working on. Then it occurred to me that these things could simply be called subjects instead, though I knew that this might be a bit of a daring wordplay. (Think: server plus object equals: sobject, or subject.)

If we want to build a sensible environment for a group of people to interact with a group of subjects, there are a number of requirements:

  • Participants should be able to "tune in" to a selection of subjects

  • Everyone must receive quick notification when a subject's attribute changes

  • Update notification should be automatic, or listener-based, as it is in AWT and Swing components

  • Network traffic should be minimized using a caching strategy


Rethinking client and server

Remote method invocation provides a way to build wormholes to join the object galaxies contained in different virtual machines. Effectively, RMI creates special reference "wires" that extend from one galaxy to another, and tries to makes sure that the method-call "sparks" along these wires visit the other galaxy and return intact. There are two important differences between local method calls and RMI: RMI sparks happen in slow motion compared to local method-call sparks, and the intergalactic wires can sometimes go down.

Developers often choose to have RMI's remote objects reside exclusively on a machine they call the server, with their counterpart proxies on the client machine. This is fine until you need to allow the server to initiate an event -- for instance, in collaborative software in which one client's updates must be broadcast to all the other clients. In this context, the client must also play the role of server in that it must be ready to receive updates at any time.

Client/server and the collaborative system

It's time to rethink the ideas of client and server. The key difference between server and client objects in a collaborative system is their one-to-many relationship. The relationship can be nicely described as a fanning out of connections between the singular subject and the multiple remote subjects, which are the things that the people see.

1 | 2 | 3 | 4 |  Next >
Resources
  • Download the source code, in zip format, for this article http://www.javaworld.com/jw-08-1998/subjectop/jw-08-subjectop.zip
  • See JavaWorld's Step by Step column on whiteboarding with RMI http://www.javaworld.com/jw-12-1997/jw-12-step.html
  • Java Collections Framework http://www.javasoft.com/products/jdk/1.2/docs/guide/collections/index.html
  • Remote Method Invocation http://www.javasoft.com/products/jdk/1.2/docs/api/package-java.rmi.html