Make room for JavaSpaces, Part 3
Coordinate your Jini applications with JavaSpaces
By Susanne Hupfer, JavaWorld.com, 03/01/00
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
The first article in this JavaSpaces thread presented an overview of the JavaSpaces programming model and its simple API.
You'll recall that the model is based on spaces -- shared, network-accessible object storage and exchange areas -- through
which processes communicate and synchronize their activities. Indeed, coordination is a crucial component of distributed programs,
just as it is in any distributed activity.
TEXTBOX: TEXTBOX_HEAD: Make room for JavaSpaces: Read the whole series!
:END_TEXTBOX
Consider cars speeding through an intersection, workers assembling a car, or athletes playing a basketball game: each of those
real-world distributed systems requires coordination to function smoothly. So with distributed applications, the processes
need to synchronize with one another to succeed at a common task. For example, distributed applications often need to mediate
access to a limited set of shared resources, guarantee fair access to those resources, or prevent processes from terminating
as they wait for resources that may never become available.
This month I'll show you how to use JavaSpaces to coordinate processes in a networked environment. At the same time, I'll
start tying JavaSpaces and Jini closer together. If you've experimented with JavaSpaces, you already know that it is implemented
on top of Jini. In fact, a new article, "The Nuts and Bolts of Compiling and Running JavaSpaces Programs" (see Resources), can help you get your JavaSpaces programs up and running, which can be a frustrating task, given all the Jini machinery
needed underneath. What may not be as clear is that JavaSpaces is a powerful tool for communication and coordination between
a Jini federation's entities. In particular, space-based communication and coordination works well in the Jini networked environment,
where entities may rapidly appear and disappear at will (or against their will, in the case of machine, software, or network
failures).
In this article, I'll investigate how you can achieve some simple forms of distributed synchronization by using a space. To
illustrate, I'll build a distributed multiplayer game, provided as a Jini service, that permits access by a limited number
of players at a time. You'll see how to mediate players' access to the game through a space. Before diving into the game service,
let's start by taking a quick look at an important concept that you'll use to build synchronization into your distributed
programs: how the JavaSpaces API provides basic synchronization on entries for free.
Space operations and synchronization
Coordinating distributed processes can be hard work. In an application that runs on a single machine, the operating system,
acting as a centralized manager, can synchronize multiple threads. But in a networked environment, a single point of control
doesn't necessarily exist. Processes run on different machines and at their own pace. Unless you want to build a centralized
controller to manage those processes, which would introduce an unwelcome bottleneck to the environment, you must build a distributed
means of managing their interactions, which can be significantly trickier.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- The complete source code for the game service example can be downloaded from
http://www.javaworld.com/jw-03-2000/jini/code.zip
- "Make Room for JavaSpaces, Part 1," Eric Freeman and Susanne Hupfer (JavaWorld, November 1999) provides a brief introduction to JavaSpaces
http://www.javaworld.com/javaworld/jw-11-1999/jw-11-jiniology.html
- For an exploration of space-based programming concepts and code examples, as well as an in-depth look at the JavaSpaces technology
APIs, refer to Sun's official Jini Technology Series book on the topicJavaSpaces Principles, Patterns, and Practice, Eric Freeman, Susanne Hupfer, and Ken Arnold (Addison-Wesley, 1999)
http://www.amazon.com/exec/obidos/ASIN/0201309556
- You may wish to experiment with the code from JavaSpaces Principles, Patterns, and Practice, which can be downloaded from the book's Website
http://java.sun.com/docs/books/jini
- The Jini specifications from Sun Microsystems are the definitive references on the JavaSpaces API (starting with the Jini
entry specification and the JavaSpaces specification)
http://www.sun.com/jini/specs
- The Jini specifications are also provided in The Jini Specification -- another Jini Technology Series book -- by Ken Arnold, Bryan O'Sullivan, Robert W. Scheifler, Jim Waldo, and Ann Wollrath
(Addison-Wesley, 1999)
http://www.amazon.com/exec/obidos/ASIN/0201616343
- Core Jini, by W. Keith Edwards (Prentice-Hall, 1999), provides in-depth treatment of Jini, including information about lookup and discovery
http://www.amazon.com/exec/obidos/ASIN/013014469X/
- Whether you wish to share information with other developers (including the Sun engineers that developed the Jini and JavaSpaces
technologies) or seek troubleshooting advice, the official JavaSpaces users mailing list is the place to go
http://archives.java.sun.com/archives/javaspaces-users.html
- The Jini-users mailing list also has a considerable amount of JavaSpaces-related discussion
http://archives.java.sun.com/archives/jini-users.html
- For pointers to the JavaSpaces FAQ and other documentation, refer to the Sun Microsystems JavaSpaces page
http://java.sun.com/products/javaspaces/
- ITworld.com sends out a weekly Jini Advisor newsletter, written by Eric Freeman, that covers many of the nuances of Jini and JavaSpaces technology (past topics have
included codebase, leasing, and transactions)
http://www.itworld.com/cgi-bin/w3-msql/newsletters/subcontent12.html
- If you encounter problems as you try to get your JavaSpaces programs up and running, refer to the article "Nuts and Bolts
of Compiling and Running JavaSpaces Programs," Susanne Hupfer (Java Developer Connection, January 2000)
http://developer.java.sun.com/developer/technicalArticles/Programming/javaspaces/
- For further information on RMI, Sun's official specification is the definitive reference
http://java.sun.com/products/jdk/1.2/docs/guide/rmi/spec/rmiTOC.doc.html