Title: Distributed Programming in Java
1Distributed Programming in Java
- Space-Based Computing (1)
2Coordination
- Coordination is the process of building
applications by glueing active pieces - Active pieces are autonomous entities such as
processes, tasks, threads, etc. - Glueing together pieces means to gather them into
an ensemble so that we consider the ensemble
itself as the application - All pieces are working on the same problem
3Parallelism
- Parallelism is a special form of coordination
- Types of parallelism
- Result parallelism units of work based on
decomposition of desired result - Agenda parallelism units of work are tasks that
are assigned to universal workers - Specialist parallelism units of work are
performed by multiple specialists - Hybrid forms
4Recap Blackboard
- Divide application into knowledge sources, which
cooperate in data-driven manner
Specialist parallelism with controller
5Space-Based Computing
- A space is a high-level coordination tool for
glueing agents into an application - Different programming paradigm
- Instead of relying on message-passing,
- applications cooperate through the flow of
objects in and out of spaces - Space-based models (JavaSpaces, TSpaces) based on
tuple space concepts
6Tuple Spaces (Linda)
- Originally designed as a persistent buffer for
communicating among parallel programs - Design goals include
- Anonymous communication
- Universal associative addressing
- Persistent data repository
- Applications post and read unstructured tuples to
a shared tuple space
7Vision Mirror Worlds
- Deep pictures (zoomable)
- Life, real-time pictures
- Agents filtering information on their users
behalf - Experience and history
Google Maps, anyone?
8JavaSpaces
- Adds new ideas to Linda
- Distributed leasing curbs resource consumption
due to failures - Distributed event notification event sources,
listeners, and objects - Distributed transactions ensures operation
ordering (2PC) - Basis of the Jini architecture for service
discovery and invocation
9Home Automation (X10)
Physical Computing Systems
10Tuple Spaces Defined
- More formally, a tuple space is a shared named
collection (bag) of tuples - Associative memory structure
- Contains tagged data records called tuples
- Tag is a name used to distinguish between tuples
for different classes of data - Values are data values integers, floats, etc.
("tag", value-1, ..., value-n)
11Simple Set of Operations
- Basic operations on a tuple space (Linda)
- out adds a tuple to the tuple space
- in reads a matching tuple and deletes it from the
tuple space - in tuple also known as template fields are
expressions, or formal parameters - read is like in, but tuples not deleted
out("tag", expr-1, ..., expr-n)
in("tag", field-1, ..., field-n)
12Tuple Matching
13Tuples
- A tag (eg "camera")
- Typically, a collection of named fields
- A tuple becomes a template, if it contains formal
fields, otherwise it is actual - Templates match another tuple, if
- the tags are the same
- number of fields is the same
- all of the fields match
14Fields
- Each field has
- name (eg make)
- type (a Java class, eg String.class)
- value (eg Leica)
- A field is formal if its value is a null token
(eg null), otherwise a field is actual - A formal field matches a field in another tuple,
if its name and type are the same
15Tuple Space API
public interface TupleSpace extends Remote
public Tuple in(Tuple template) throws
RemoteException public Tuple inNoBlock(Tuple
template) throws RemoteException public void
out(Tuple tuple) throws RemoteException publi
c Tuple read(Tuple template) throws
RemoteException public Tuple readNoBlock(Tuple
template) throws RemoteException
16Marketplace
gt space.sh market in(ltcameragtltprice/gtltmakegtLeicalt/
makegtlt/cameragt) out(ltcameragtltpricegt100lt/pricegtltmak
egtNikonlt/makegtlt/cameragt) out(ltcameragtltpricegt200lt/p
ricegtltmakegtLeicalt/makegtlt/cameragt) gt buyer.sh
Leica Buyer.in ltcameragtltmakegtLeicalt/makegtltprice/gt
lt/cameragt Match ltcameragtltmakegtLeicalt/makegtltpricegt
200lt/pricegtlt/cameragt Camera.price
ltpricegt200lt/pricegt gt seller.sh Nikon
100 Seller.out ltcameragtltmakegtNikonlt/makegtltpricegt1
00lt/pricegtlt/cameragt gt seller.sh Leica
200 Seller.out ltcameragtltmakegtLeicalt/makegtltpricegt2
00lt/pricegtlt/cameragt
17Marketplace
- Commands to run this example (you also need to
run the RMI registry)
space.sh java -Djava.security.policyall.policy
dpj.ts.TupleSpaceServer \ -debug 1
buyer.sh java -Djava.security.policyall.policy
dpj.ts.test.CameraBuyer \ localhost market 1
seller.sh java -Djava.security.policyall.policy
dpj.ts.test.CameraSeller \ localhost market 1 2
18CameraBuyer
public class CameraBuyer public static void
main(String args) try System.setSecurit
yManager(new RMISecurityManager()) TupleSpace
space (TupleSpace) Naming.lookup("rmi//"
args0 "/" args1) String make
args2 Tuple cameraTemplate new
Tuple("camera", new Field("make",
make), new Field("price", Integer.class))
System.out.println("Buyer.in "
cameraTemplate) Tuple camera
space.in(cameraTemplate) System.out.println("M
atch " camera) System.out.println("Camera.p
rice " camera.getField("price"))
catch (Exception e) System.err.println(e)
19CameraSeller
public class CameraSeller public static void
main(String args) try System.setSecurit
yManager(new RMISecurityManager()) TupleSpace
space (TupleSpace) Naming.lookup("rmi//"
args0 "/" args1) String make
args2 int price Integer.parseInt(args3)
Tuple camera new Tuple("camera", new
Field("make", make), new Field("price",
price)) System.out.println("Seller.out "
camera) space.out(camera) catch
(Exception e) System.err.println(e)
20More Readings
- Gelernter, Mirror Worlds, Oxford
- Gelernter/Carierro, How to Write Parallel
Programs, MIT - Freeman/Hupfer/Arnold, JavaSpaces, Jini
Technology Series, Addison-Wesley - IBM, TSpaces project
- www.almaden.ibm.com/cs/TSpaces
- Magee/Kramer, Concurrency State Models and Java
Programs