JavaSpaces Principles, Patterns and Practice
The Book JavaSpaces technology is a high-level coordination tool for gluing processes together into a distributed application. For a technology that has to handle latency, synchronization, and partial failure the API is very simple and easy to use. JavaSpaces is based on the "Linda" coordination language developed at Yale University. Two of the authors, Dr. Freeman and Hupfer have spent a decade in designing and implementing space based applications as part of the Linda research group and the third Ken Arnold was in charge of the JavaSpaces project at Sun Microsystems.
The book teaches the principles, patterns and practice of JavaSpaces technology.
The principles are very simple. The API is very minimal with just seven methods and that is all you need to write distributed applications using JavaSpaces. There is a tutorial introduction to the API and by the end of chapter two, you will be able to write your own distributed applications. The building blocks for space based programming is distributed data structures. The distributed version of arrays, shared variables, and unordered data structures are described in the chapter "Building Blocks". The concepts of leases, distributed events and transactions are covered in detail in separate chapters.
The patterns in distributed programming are those of synchronization, communication and application. One of the main concerns in distributed programming is synchronization. But this task is simplified in JavaSpaces as synchronization is built into the space operations. The synchronization chapter covers implementing semaphores, using multiple semaphores, using various synchronization techniques like round robin and barrier, and finally the readers/writers problem. In the loosely coupled communication style of space based programming the senders and receivers can remain anonymous. The communication patterns are variants of the distributed data structure---channels. The chapter on Application Patterns presents the frameworks for solving compute-intensive problems like ray tracing or generating computer animations and frameworks for producers and consumers of resources.
All these concepts are put together to develop two real world applications to show the practice of JavaSpaces. The first one is a collaborative application---an interactive messenger service and the other is a parallel application for breaking password encryption. These examples cover everything from the basics, to useful distributed data structures to advanced topics like distributed events, transactions and leasing.
The final chapter of the book provides a list of resources for further reading both for JavaSpaces and its foundation the Jini technology. The appendix includes the official specs of JavaSpaces from Sun Microsystems.
What's to consider?
For people new to JavaSpaces this book is a good tutorial introduction. If you write distributed applications in some other language, you will find the patterns section of the book very useful, where you can learn how to implement the common patterns using JavaSpaces. The individual methods of the API are covered in detail and finally the broad picture is presented where the different pieces fit to solve a problem.
Even if you are not in the field of distributed application development, you can read through the book to get an understanding of this new programming paradigm. The narrative is smooth and all the concepts are illustrated with code samples and interesting examples. Each chapter of the book has an associated set of exercises. These exercises prompts the reader to explore his understanding of the topic by enhancing the examples described in the chapter.
Summary
This book serves both a tutorial as well as a reference. If you are new to JavaSpaces or are an experienced distributed application developer, this book will be a valuable resource.
See:
The Nuts and Bolts of Compiling and Running JavaSpacesTM Programs by Susanne Hupfer.
Their instructions worked, but it wasn't always clear what had to be named exactly as in the examples.
They've also posted errata at the book's site.
Regards,
--tangram
Having both worked with Linda variants before and critiqued their designs, I have a couple of comments I'd make before rushing out to learn JavaSpaces.
While some classes of distributed programming problems are trivial to implement in Linda-likes, others are at best no easier and may even be harder. Some examples of things that are easier:
However, both of these are fraught with the usual perils of distributed programming. Deadlocking a Linda-like system is trivial:
- Make processes A and B and slots a and b.
- Proc A uses slot a to send stuff to proc B.
- Proc B uses slot b to send stuff to proc A.
- Proc A reads from slot b (blocking until B puts something there).
- Proc B reads from slot a (blocking similarly).
"So don't make those kinds of loops! Duh!" But cycles are difficult to avoid (unless you're using a pure (and I mean pure) functional language). Consider a real-world system and think about how easy it might be for such a cycle to accidently spring up among a network of a dozen processes, each with their own complex flow control. Consider the following simple mistakes for the work queue and semaphore above:- If tasks depend on results from other tasks, then you lose parallelism.
- Forget to put the value back, or forget to take it in the first place.
And of course, "good programmers will avoid those pitfalls." Uh huh. BTDT. "Good programmers don't need revision control." Heard that, too.Programming in Linda-likes is a lot like programming in Self. If Self slots were queues (and Self is so flexible, you can make them queues if you want), it would be a Linda-like. Self makes some things really easy, but it's the old flexibility problem - get enough rope, hang yourself six ways til Sunday.
-----
Klactovedestene!
Here's a 5 part hands on tutorial on JavaSpaces:
Part 1
Part 2
Part 3
Part 4
Part 5
.peter
Which, as it turns out, is just fine, the same p's can be applied with comparitive ease to IBM's TSpaces.
Setting up Jini/JavaSpaces is pretty involved if you're just looking to take it for at test drive.
In fact, after a detailed (i.e. reading 3-4 books) look at JavaSpaces and Jini as candidates for my current project at work I decided that the overhead was just too much for my small team of 2-3 developers to mess with.
On top of that, I found JavaSpaces querying abilities lacking. It is only capable of comparing objects in serialized form using bitwise comparison.
The consequence? If you're looking for an object with a timestamp within a certain range you're pretty much SOL in JavaSpaces.
Luckily enough though, I discovered TSpaces shortly there after. It's similar to JavaSpaces in that it uses the same general space-based api of read/write/take.
But its advantages are that (1) the server is a single, easy-to-start, java process (2) you can do range queries based upon the actual compare() methods of objects and (3) the guys who are working on it are accessible for questions and feature requests via the tspaces mailing list.
Granted, it doesn't address discovery and some of the nicer features of Jini, but it is incredibly simple to set up in comparison to JavaSpaces and 6 months later I'm still glad I chose it.
So for those of you who want to take the principles, patterns, and practice of space programming for a test drive, go grab the TSpaces jar and you'll have a server up and be coding in 5 minutes.
Jackson Gibbs gibbs@roguewave.com
"A matter of internal security, the age old cry of the oppressor" - Jean Luc Picard
My biggest complaint with the book was its lack of detail about the setup of an actual Java Spaces environment. I understand that even with the (sorta) WORO Java that steup of a Space differs between platforms, but there's enough similarities between installations that some directions would've been helpful -- especially things like property setups.
Furthermore, I understand that the book is more about the API in general than in Sun's first implementation of said API, but what good is making the source for your examples available online if you're not going to provide sufficient information to get a space up.
Maybe I'd be less bitchy if I hadn't spent 10 hours pawing through java spaces mailing list archives to find the arcane properties necessary for setup, but a little help from the author (who udoubtably knew the sad state of Sun's installation instructions) would've been a huge help.
That said I found the notion of space based distributed systems very interesting and have since gone on to look at T-spaces and other predecessors as well.
--
I'm hard pressed to remember the last time there was a book review on slashdot that had a negative opinion of the book reviewed. Is this because of self-selection by reviewers, either to bother writing reviews about only books that matter or to promote books that reviewers prefer? I would find it more useful to have reviews that also say "This book, while it may look like a winner on the shelf, is really a steaming pile of crap and should be avoided."
"If one is really a superior person, the fact is likely to leak out without too much assistance" -- John Andrew Holmes
Chapter 11 is posted on Sun's site.
There is also a basic overview of JavaSpaces here (in PDF)
Finally. the JDC
Being with you, it's just one epiphany after another