Download presentation
Presentation is loading. Please wait.
Published byFrank Newman Modified over 8 years ago
1
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved.
2
JavaSpaces™: A Service for Collaborative Distributed Applications Ken Arnold Senior Staff Engineer Sun Microsystems, Inc.
3
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. What Is a JavaSpace? A simple service for cooperative computing An object repository that has –Persistence –Template Matching lookup –Transactions (multi-space) Stores entries –Distributed (RMI-based) –Concurrent
4
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. What A JavaSpace is not A relational database An object-oriented database
5
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. JavaSpaces in Jini JavaSpaces are the first Jini service JavaSpaces entries are Lookup service entries JavaSpaces use the Jini programming models: –Transactions –Leases –Events
6
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. The Model Four simple operations: –write: put an entry into the space –read: return a matching entry from the space –take: remove a matching entry from the space –notify: send event if matching entry is written Build cooperative protocols Protocols are loosely coupled –writer doesn’t know who will read or take
7
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. JavaSpaces simplicity Why only four operations? It’s all you need Simplicity lets us help you –Transactions –Scalability –Replication Multiple implementations to choose
8
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. A Simple Example Animator needs to render movie frames –Writes “request for rendering” entries –Takes rendered results written back Server processes tasks –Takes generic “do a task” entries –Executes each task, writing back results
9
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. What is an Entry? An object that implements Entry –All fields must be public –Fields may be of any kind of object –Must have a public, no-arg constructor Added to a space using write
10
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Entry Matching Matching requires a template entry Each field in a template is either –a value to be matched exactly –a wildcard: “I don’t care” The space is searched for any entry that –Is at least the template’s type –Has all values matching
11
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. The JavaSpace Interface public interface JavaSpace { Lease write(Entry entry, Transaction txn, long lease) throws TransactionException, RemoteException; Entry read(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException; Entry readIfExists(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException; Entry take(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException; Entry takeIfExists(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException; EventRegistration notify(Entry tmpl, Transaction txn, RemoteEventListener ln, long lease, MarshalledObject handback) throws TransactionException, RemoteException; Entry snapshot(Entry e) throws RemoteException; }
12
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. A simple example expounded The animator’s program –Writes RenderTask entries –Reads RenderResult entries A server process –Takes Task entries –Writes resulting entries
13
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. A Task Entry public class TaskEntry implements Entry { /** * Execute whatever task the entry requires. If an entry is * returned, it is written back into the space. */ public Entry execute() { throw new RuntimeException("execute() not implemented"); } public long leaseTime() { return 10 * 60 * 1000; // ten minutes } //... server code... TaskEntry tmpl = new TaskEntry(); for (;;) { TaskEntry task = space.take(tmpl, null, Long.MAX_VALUE); Entry result = task.execute(); if (result != null) // write any results back space.write(result, null, task.leaseTime()); }
14
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. A RenderTask Entry /** * Render a frame in a movie. */ public class RenderTask extends TaskEntry { public Long renderID; // which rendering is this? public FrameDesc frame; // the frame to render public Entry execute() { RenderResult result = new RenderResult(); result.image = frame.render(); // do the real work result.renderID = renderID; // the rendering ID return result; }
15
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Let’s walk this through Client writes RenderTask Client blocks taking RenderResult Server takes Task, finds RenderTask –RenderTask not known? RMI downloads it Server invokes execute, renders frame Server writes resulting entry Repeat ad infinitum Client takes RenderResult Repeat until done
16
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Scale it up Add more servers Add more animators
17
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. …And up Add lots more servers Add new kinds of clients with new types of tasks
18
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Why use JavaSpaces? To build an RPC-based system: –Design the actors, protocols, and interfaces –Implement the clients and servers To build a JavaSpaces-based system: –Design the actors, protocols, and entries –Implement the clients –(the server is done for you) Loosely-coupled systems scale well What’s wrong with simple?
19
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Possible uses Work flow –You write an expense report –Your manager, looking for unsigned expense reports, takes it out, signs it, writes it back –Accounting, looking for signed expense reports, takes it out approves it, writes it back –Check writer, looking for approved expense reports, takes it out, cuts the check, marks it “paid”, writes it back
20
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Possible Uses (continued) Groupware/Version control –Each version of a JavaBean is an entry –A token for each bean contains its version number –To edit a bean, take its token, take the bean, write back new bean and new token with new version number Trading systems –Commodities, bids, prices, are entries in a space
21
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Possible uses (expanded) If you can model your protocol as an exchange of objects, you can leverage the simplicity of JavaSpaces
22
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved. Availability Evaluation copy available –JSTK: JavaSpaces Technology Kit –http://developer.java.sun.com/developer/produ cts/jini/ –Runs as a Jini service
23
January 26, 1999--Ken Arnold Copyright 1999 Sun Microsystems, Inc., all rights reserved.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.