420 likes | 613 Views
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.
E N D
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
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
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
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
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
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
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
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
JavaSpaces Technology basis • Built on core JDK facilities • RMI • Object serialization • Part of Sun’s Jini package • Leasing • Transaction • Distributed events
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
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
Applications • Workflow systems • Customer management systems • Supply chain management • Auction systems • Trading service • Agent systems • Publish and subscribe service • …...
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
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
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
JavaSpaces architecture • Entry/Template • Serialization • JavaSpace Scenario • JavaSpaces/JavaSpace server • JavaSpace Interface
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
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
Serialization Entry Forms
JaveSpaces Scenario Transaction Distributed Event JavaSpaces Leasing Entry RMI
JavaSpaces/JavaSpace Server • Not a remote interface • invocation of methods of JavaSpace throws RemoteException • JavaSpaces server exports objects implemeting javaspace interface to clients
JavaSpace/JavaSpace Server Client JavaSpace Server Server Interface JavaSpace JavaSpace Client
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; }
Functionality • write • read/readIfExists • take/takeIfExists • snapshot • notify
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
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
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
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
notify EventRegistration notify(Entry templ, Transaction t, RemoteEvenbtListener l, long lease, MarshalledObject handback) throws…; • RemoteEvent • RemoteEventListener • EventRegistraion{ evID fromWhom seqNo } • retry to notify listeners
Sample implementation • Requirements • Entry implementation • Sample invocation
Requirements • JDK1.2 beta 4 or later version • Jini beta version or later version
Entry implementation MyEntry class import net.jini.space.Entry public class MyEntry implements Entry{ public String name; public GIFImage value; public MyEntry(){ } }
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(); } }
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
Supporting packages • Leasing • Transaction • Distributed Event/Listener
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
Transaction • System task is to coordinate objects over transaction • Two phrase commit model • Based on RMI to perform communication • Dependent on Leasing
Distributed Event • Events in multi-address spaces • Desired delayed • Network failure/Delay • Third-party agents perform notification • Non-Java third-party agents
Third-part agents Obj3 Obj1 Server Server Obj4 Obj2
Conclusion • JavaSpaces concepts and advantages • Model object flow processes • JavaSpaces architecture and operations • Supporting packages • Reference: http://www.javasoft.com/products/javaspaces/index.html