1 / 42

JavaSpaces

JavaSpaces. SENG 609.09. Shuxin Yuan/Mike Gao April 17, 1999. JavaSpaces Concepts Technology Basis Applications JavaSpaces Operations Entries and Templates. JavaSpaces architecture Functionality Sample implementation Supporting packages Conclusions. JavaSpaces. Table of Contents.

giacomo
Télécharger la présentation

JavaSpaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaSpaces SENG 609.09 Shuxin Yuan/Mike Gao April 17, 1999

  2. JavaSpaces Concepts Technology Basis Applications JavaSpaces Operations Entries and Templates JavaSpaces architecture Functionality Sample implementation Supporting packages Conclusions JavaSpaces Table of Contents

  3. JavaSpaces Concepts (1) • A mechanism for distributed computing • dynamic sharing, communication and coordination of Java Objects • Loosely coupled, cooperative marketplace model • producer store objects in the space • consumer lookup and take objects from the space • 100% pure Java language based

  4. JavaSpaces Concepts (2) • A networked repository for Java Objects • Store Entries (Serialized Java objects) • Both data and behaviors • Lookup entries by using Templates( Entries given the values of fields for matching) • Type matching (same class?) • Value matching: lookup and compare the specific fields

  5. JavaSpaces Concepts (3) • An interface: net.jini.space.JavaSpace • A JavaSpace server implements this interface • Operations are involked on a JavaSpace object • write, read, readIfExists, take, TakeIfExists, notify, snapshot • Not a remote interface • Client communicates with JavaSpaces server remotely • JavaSpaces server communicates with JavaSpaces locally • Each method throws RemoteException

  6. JavaSpaces Concepts (4) • JavaSpaces solves two problems: • Distributed persistence • store and retrieve objects on remote systems • use object serialization technology • Distributed algorithms • RMI • flow of objects

  7. Differences to database • JavaSpaces is not just for data repository • All entries are copies of original objects • No general query language • No way to return sets of objects • Not a transparent persistence mechanism (can not modify data) • Understand entry by type and serialized fields • JavaSpaces is something between file system and database

  8. JavaSpaces Suitability • JVM • All users should link to a JVM • use Java RMI • Transport among JVMs via JNI • Interoperability • interoperable with other language • via RMI/IIOP and CORBA

  9. JavaSpaces Advantages • Simple solution for lightweight distributed application • Make client-side model simple and the downloading of client classes quick • Decouples rigid association between requestor and provider • Relieves responsibilities and complexity • easy to build and maintain • Multiple spaces can co-exist within a network • Unified network environment • Simple yet powerful methods, only four primitive methods: • write, read, take, notify

  10. JavaSpaces Technology basis • Built on core JDK facilities • RMI • Object serialization • Part of Sun’s Jini package • Leasing • Transaction • Distributed events

  11. Applications (Model) Identities read JavaSpaces server Client write Security Check writeEvent Client write notify Event Catcher Transaction proxy take notify write JavaSpaces server notify JavaSpaces server

  12. Live feed applet buyer bid entry read Write JavaSpaces Server graphic applet Write entry seller Notify An application scenario: Stock trading system • Entry fields: • securities, owners price offers, quantities, ... • GUI: • applets • Many sellers and buyers can be involved • concurrent access are handled by the space

  13. Applications • Workflow systems • Customer management systems • Supply chain management • Auction systems • Trading service • Agent systems • Publish and subscribe service • …...

  14. JavaSpaces Operations • write -- put a copy of entry into the space • read, readIfExists -- return a matching entry from the space • take, takeIfExists -- remove the matching entry from the space • notify -- send an event when the matching entry is written • snapshot -- return another entry object that contains the snapshot of the original one

  15. Entries • Entry Implementation • Typed group of objects, java class • Implement Java interface: net.jini.space.Entry public interface Entry extends java.io.serializable { } • Have a public, zero-arg constructor • Defines public fields for matching • Each field is an object, no primitive types • Default implementation of Entry: public abstract class AbstractEntry implements Entry { ...} • implements equals( ) and hashCode( ) properly by comparing field values

  16. Templates • Template • Entry object • Some/all fields set to specific values • Null fields act as wildcards • Type and value matching • Exact match of each field

  17. JavaSpaces architecture • Entry/Template • Serialization • JavaSpace Scenario • JavaSpaces/JavaSpace server • JavaSpace Interface

  18. Entry/Template • Template is an Entry for matching • Type matching • Value matching • Type matching and subtype matching • Only public fields are considered for matching • Fields should refer to serializable objects • Fields must have properties

  19. Serialization • Entries are NOT stored in JavaSpaces • Serialized form of the class and fields • java.rmi.MarshalledObject • MashalledObject.equals() • Field in template has null value as wildcard • set fields/un-set fields • Object graph map reference

  20. Serialization Entry Forms

  21. JaveSpaces Scenario Transaction Distributed Event JavaSpaces Leasing Entry RMI

  22. JavaSpaces/JavaSpace Server • Not a remote interface • invocation of methods of JavaSpace throws RemoteException • JavaSpaces server exports objects implemeting javaspace interface to clients

  23. JavaSpace/JavaSpace Server Client JavaSpace Server Server Interface JavaSpace JavaSpace Client

  24. JavaSpaces interface Import net.jini.transaction.* import net jini.event.*; import net.jini.lease.*; Public interface JavaSpace{ Lease write(Entry e, Transaction t, long lease) throws…; public final long NO_WAIT=-1;// don’t wait at all Entry read(Entry temp1, Transaction t, long timeout) throws...; Entry readIfExists(Entry temp1, Transaction t, long timeout) throws…; Entry take(Entry templ, Transaction t, long timeout) throws...; Entry takeIfExists(Entry templ, Transaction t, long timeout) throws...; EventRegistration notify(Entry templ, Transaction t, RemoteEvenbtListener l, long lease, MarshalledObject handback) throws…; Entry snapshot(Entry e) throws RemoteException; }

  25. Functionality • write • read/readIfExists • take/takeIfExists • snapshot • notify

  26. Write Lease write(Entry e, Transaction t, long lease) throws…; • Write a copy into Space • Field is independent • write returns a Lease object • RemoteException • Other kinds of exceptions

  27. ReadIFExists and Read Public Entry read(Entry temp1, Transaction t, long timeout) throws...; Entry readIfExists(Entry temp1, Transaction t, long timeout) throws • A copy of the matching entry is returned. • Null is returned if no matching is found • read vs. readIfExists: read will wait until a match is found or until transaction settle, up to time out period

  28. takeifExists and take Entry take(Entry templ, Transaction t, long timeout) throws...; Entry takeIfExists(Entry templ, Transaction t, long timeout) throws...; • Object is removed from space • RemoteException: Entry may or may not be removed successfully • Other Exceptions mean failure • Subtype matching: returns may be more than anticipated

  29. snapshot • Entry snapshot(Entry e) throws RemoteException; • Reduce repeated use of the same Entry • Returns a Entry object with a snapshot of the original unmodified object • Modification on the original entry will not affect snapshot • Only work within the same JavaSpaces Server where it is generated

  30. notify EventRegistration notify(Entry templ, Transaction t, RemoteEvenbtListener l, long lease, MarshalledObject handback) throws…; • RemoteEvent • RemoteEventListener • EventRegistraion{ evID fromWhom seqNo } • retry to notify listeners

  31. Sample implementation • Requirements • Entry implementation • Sample invocation

  32. Requirements • JDK1.2 beta 4 or later version • Jini beta version or later version

  33. Entry implementation MyEntry class import net.jini.space.Entry public class MyEntry implements Entry{ public String name; public GIFImage value; public MyEntry(){ } }

  34. Sample invocation import net.jini.impl.outrigger.binders.RefHolder Public HelloWorld class{ public JavaSpace getSpace(){ RefHolder rh = (RefHolder)Naming.lookup(“JavaSpace”); JavaSpace js = (JavaSpace)rh.proxy(); } }

  35. Sample invocation • JavaSpace space = getSpace(); • MyEntry e = new MyEntry(); • e.name =“Duke”; • e.Value= new GIFImage(“dukeWave.gif”); • space.write(e, null, 60*60*1000);// one hour

  36. Supporting packages • Leasing • Transaction • Distributed Event/Listener

  37. Leasing • Used in distributed environments to solve partial failure of resources and services • Resources are leased and freed when the time of the lease expires • Get ride of debris easily • Negotiation among related parties • Lease can be renewed or canceled • Different from garbage collection

  38. Transaction • System task is to coordinate objects over transaction • Two phrase commit model • Based on RMI to perform communication • Dependent on Leasing

  39. Distributed Event • Events in multi-address spaces • Desired delayed • Network failure/Delay • Third-party agents perform notification • Non-Java third-party agents

  40. Third-part agents Obj3 Obj1 Server Server Obj4 Obj2

  41. Conclusion • JavaSpaces concepts and advantages • Model object flow processes • JavaSpaces architecture and operations • Supporting packages • Reference: http://www.javasoft.com/products/javaspaces/index.html

  42. Questions?

More Related