jSpace
jSpace implements
tuple
spaces, a blackboard memory paradigm for
parallel and distributed computing, made famous by the
Linda
language by David Gelernter and Nicholas Carriero.
jSpace is the Java version of
pSpaces, which also has
implementations for Go, .NET, Swift, and JavaScript.
jSpace is far from being the first Java implementation of the
blackboard model, with perhaps the best known being
JavaSpaces, which rests atop
Jini, Sun Microsystems'
distributed services framework. Sadly, JavaSpaces never became popular
(although it is apparently still used in hush-hush financial
domains). Its main problem, in my humble opinion,
was the complexity of setting
up the JavaSpaces/Jini system, which required a level of networking skill
that the tuple space concept was invented to hide.
Happily, jSpace (and its siblings) is quite straightforward to
compile and install (it's just a few JAR files).
The pSpace site hosts good
documentation
and a
tutorial,
which focuses mostly on the Java implementation.
To make things even easier, you can download a file containing
all the necessary JAR files from
here
(see the bottom of the page). I've
also generated the jSpaces
API documentation.
My examples are based on those in the
tutorial,
code from the course
Introduction to Coordination in Distributed Applications,
and I've also lifted examples from several books, including:
- JavaSpaces Principles, Patterns, and Practice,
Eric Freeman, Susanne Hupfer, and Ken Arnold, Addison Wesley 1999
- JavaSpaces in Practice, Philip Bishop, Nigel Warren
Addison Wesley, 2002
- How
to Write Parallel Programs: A First Course,
Nicholas Carriero and David Gelernter, MIT Press,
MIT Press, 3rd ed., 1992
Visualization
The most significant change I've made is to write three classes
to aid with the visualization of the execution of tuple space
programs. VisSpace.java is a version of
jSpace's SequentialSpace class which displays a window showing
tuples and queries and how they match. The example
on the right depicts a moment during the execution of
DiningPhilosophers.java.
I've also coded PrintAreas.java, which
creates a window of text areas that can be assigned as
output windows to
threads. These are much easier to read than a mixed-up jumble of
prints to stdout. The example below shows the output
from the five threads involved in the dining philosopher's problem.
Neither VisSpace nor PrintAreas are "industrial
strength" tools. VisSpace can only display a maximum of
ten queries and ten tuples, while PrintAreas maxs out at
twelve text panes, but they're quite useful for the beginner/intermediate
problems included here.
Examples
- Good old HelloWorld.java,
accompanied by concurrent and distributed versions:
ConcurrentHelloWorld.java and
RemoteHelloWorld.java;
- Short examples of the tuple operations
put, queryp, getp, and queryAll:
Fridge.java and
ConcurrentFridge.java;
- A producer-consumer example:
ProducerConsumer.java, using
ProducerAgent.java and
ConsumerAgent.java, and a
distributed version:
RemoteProducerConsumer.java;
- A bare-bones Remote Procedure Call (RPC) server
RPCServer.java and client
RPCClient.java;
- Two-way communication set up by
PingPong.java between
PingAgent.java and
PongAgent.java;
distributed versions using jSpaces' keep protocol
PingPongKeep.java and
conn protocol
PingPongConn.java;
- A chat server ChatServer.java, client
ChatClient.java, and a (simplistic) way
to display chat messages
RoomReader.java; this example illustrates
one of the weaknesses of the basic blackboard model, which is how
to efficiently (and atomically) retrieve multiple tuples
matching some criteria.
- The eponymous Dining
philosophers' problem: DiningPhilosophers.java and
Philosopher.java, along with
a distributed version
RemoteDiningPhilosophers.java.
In addition, a second version that uses 'tickets' to prevent the
philosophers from deadlocking:
DiningPhilTickets.java and
PhilTicket.java;
- Another classic concurrency problem – the
cigarette
smokers problem:
CigSmokers.java, using
Smoker.java,
Agent.java, and
Supplies.java;
- Yet another classic concurrency problem – the
sleeping
barber problem:
BarberShop.java, using
WaitingRoom.java,
Barber.java, and
Customer.java;
- A concurrent version of
mergesort:
SpaceSorter.java, employing
Splitter.java and
Merger.java;
- Sequential code for calculating π:
CalcPiSeq.java, compared to
a concurrent version
CalcPiSpace.java with workers
PiWorker.java;
- Two concurrent version of matrix multiplication:
MatrixMultRow.java with
n2
MultWorkerRow.java workers, and
MatrixMultCell.java with n
MultWorkerCell.java workers;
- Sequential code for drawing the beloved Mandelbrot image
SeqMandelbrot.java, versus a
concurrent version
MandelSpace.java with workers
MandelWorker.java;
- Visualizing tuple space using
VisSpace.java and
SpaceViewer.java; these classes
are utilized by most of my examples;
- PrintAreas.java: a window
of text panes that can be used as output windows by threads;
- Utilities: SpaceUtils.java and
Pair.java.
Other Downloads and Links
Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to the third-party libraries page