Title: JavaSpaces
1JavaSpaces
- Prabhaker Mateti
- Wright State University
2Ack
- Ken Arnold
- Jan Newmarch
- Susanne Hupfer
- And many other sources on the Web
-
3(No Transcript)
4public interface JavaSpace
- public interface JavaSpace Lease write(Entry
entry, Transaction txn, long lease) Entry
read(Entry tmpl, Transaction txn, long
timeout)Entry readIfExists(Entry tmpl,
Transaction txn, long timeout)Entry
take(Entry tmpl, Transaction txn, long
timeout)Entry takeIfExists(Entry tmpl,
Transaction txn, long timeout)EventRegistratio
n notify(Entry tmpl, Transaction txn,
RemoteEventListener ln, long lease,
MarshalledObject handback)Entry
snapshot(Entry e) -
- // throws clauses not shown
5(No Transcript)
6MP3Request implements Entry
- public class MP3Request implements Entry
- public String channelName // recipient of the
request public Integer position // position of
request in channel - public String inputName // file path
- public byte data // content of the file
- public String from // who sent the request
public MP3Request() - public MP3Request(String channelName)
- this.channelName channelName
-
- public MP3Request (String channelName, Integer
position) - this.channelName channelName this.position
position -
- public MP3Request(String channelName, Integer
position, - String inputName, byte data, String from)
- this.channelName channelName this.position
position - this.inputName inputName
- this.data data
- this.from from
-
-
7From Jini
- import net.jini.transaction.
- import net jini.event.
- import net.jini.lease.
8JavaSpaces Technology basis
- Built on core JDK facilities
- RMI
- Object serialization
- Part of Suns Jini package
- Leasing
- Transaction
- Distributed events
9Jini
JavaSpace
Other
services
Lookup Service
Discovery/Join
Java RMI
10JavaSpace v. Linda
- write put an entry in the space (out)
- read return a matching entry from the space (rd)
- take remove a matching entry from the space (in)
- notify send event when a matching entry is
written (?) - JavaSpace has No Linda eval()
11JavaSpaces architecture
- Entry/Template
- Serialization
- JavaSpace Scenario
- JavaSpaces/JavaSpace server
- JavaSpace Interface
12JavaSpace Service
- A simple service for distributed computing
- A shared object repository
- Persistent
- Template-matching lookup
- Transactions (multi-space)
- Stores entries (tuples of objects)
- Distributed (RMI-based)
- Concurrent
- What a JavaSpace service isn't
- A relational database
- An object oriented database
13Why Use a JavaSpace?
- Cooperative, loosely-coupled systems scale well
14JavaSpaces Suitability
- JVM
- All users should link to a JVM
- use Java RMI
- Transport among JVMs via JINI
- Interoperability
- interoperable with other language
- via RMI/IIOP and CORBA
15JavaSapces Concepts 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
16JavaSapces Concepts A networked repository for
Java Objects
- Store Entries (Serialized Java objects)
- Both data and behaviors
- Lookup entries by using Templates
- Type matching (same class?)
- Value matching lookup and compare the specific
fields
17Service Provider
- Implements the objects that provide a service
- Finds the lookup services
- Registers the service object with lookup services
- Service object gets downloaded to clients
- A typical service object is a proxy
18A Service Provider Example
public class AServer implements DiscoveryListener
protected LeaseRenewalManager lm new
LeaseRenewalManager() public static void
main(String argv) new AServer()
Thread.currentThread().sleep(Lease.FOREVER)
public AServer() LookupDiscovery di new
LookupDiscovery(LookupDiscovery.ALL_GROUPS)
di.addDiscoveryListener(this) public void
discovered(DiscoveryEvent evt)
ServiceRegistrar rg evt.getRegistrars()0
ServiceItem item new ServiceItem(null, new
AServerImpl(), null) ServiceRegistration sr
rg.register(item, Lease.FOREVER)
lm.renewUntil(sr.getLease(), Lease.FOREVER,
this)
19Lookup Services
- Listening on port 4160
- Unicast TCP Multicast UDP
- Sends a registrar object to requestor
- Registering storing a copy of the service
object in the lookup service - 4160 0xCAFE 0xBABE
20Entry Class
- Implements interface
- public interface Entry extends java.io.serializabl
e - All fields must be public
- Fields must be objects, not builtins (no int,
etc.) - Must have a public null-arg constructor
21An Example Entry
- class User implements Entry
- public String login
- public String homeHost
- public String fullName
- public Long lastLogin
- // ...
-
22Entry Methods
- 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
23Lease write (Entry e, Transaction t, long lease)
- Write a copy of e into Space
- returns a Lease object
- limited persistence with time-outs
- exceptions
24Entry snapshot (Entry e)
- Returns an Entry object with a copy of the
original unmodified object - Modification on the original entry will not
affect snapshot - Works only within the same JavaSpaces Server
where it is generated
25Template
- Entry object
- Some/all fields set to specific values
- Null fields act as wildcards
- Exact value match of each non-null field
26Template
- Type matching and subtype matching
- Only public fields are considered for matching
- Fields should refer to serializable objects
- Fields must have properties
27Entry Matching
- Matching requires a template
- The service is searched for one entry that...
Is at least the template's type Has all
values matching
28Templates match entries iff
- each field in template is
- either null or
- match the entry field via MarshalledObject.equals.
- That is, the serialized forms of the objects
match exactly.
29public Entry read (Entry e, Transaction t,long
timeout)
- A copy of the matching entry is returned.
- read vs. readIfExists read will wait until a
match is found or until transaction settles, up
to time out period - Null returned, if nothing matches
30Entry take(Entry tmpl, Transaction t, long
timeout)
- Matching 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
31Serialization
- 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
32notify
- EventRegistration notify(Entry tmplt, Transaction
t, RemoteEventListener l, long lease,
MarshalledObject handback) RemoteEvent - RemoteEventListener
- EventRegistraion
- evID
- fromWhom
- seqNo
-
- retry to notify listeners
33JaveSpaces Scenario
Transaction
Distributed Event
JavaSpaces
Leasing
Entry
RMI
34Leasing
- 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 rid off debris easily
- Negotiation among related parties
- Lease can be renewed or canceled
35Lease
- a time period during which the grantor of the
lease insures that the holder of the lease will
have access to its resources. - Typical Grantor lookup service
- Typical Grantee component
36package net.jini.core
- public interface Lease void cancel()
- throws UnknownLeaseException,java.rmi.RemoteExce
ption - long getExpiration()
- void renew(long duration) throws
LeaseDeniedException, UnknownLeaseException,
java.rmi.RemoteException -
37ACID properties of transactions
- Atomicity
- All the operations of a transaction must take
place, or none of them do - Consistency
- The completion of a transaction must leave the
participants in a consistent'' state. - Isolation
- The activities of one transaction must not affect
any other transactions - Durability
- The results of a transaction must be persistent
38Two-phase commit protocol
- Participants tentatively carry out the
operations. - All participants then vote.
- If all agree, the transaction commits.
- If any disagree, transaction aborts in all.
39Jini Transaction
- Two phase commit model
- Transaction ID supplied by the manager
- Based on RMI for communication
- Dependent on Leasing
- Mahalo transaction manager is part of Jini
40Distributed Event
- Events in multi-address spaces
- Desired delay
- Network failure/Delay
- Third-party agents perform notification
- Non-Java third-party agents
41Multiple JavaSpaces
- Multiple JavaSpaces cooperate, and transactions
span multiple spaces. - Partitions provide minimal protection.
42Scale It Up
43JavaSpaces is not a database
- 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
44Applications (Model)
Identities
read
JavaSpaces server
Client
write
Security Check
writeEvent
Client
write
notify
Event Catcher
Transaction
proxy
take
notify
JavaSpaces server
write
notify
JavaSpaces server
45An application scenario Stock trading system
- Entry fields
- securities, owners price offers, quantities,
... - GUI
- applets
- Many sellers and buyers can be
- involved
- concurrent accesses are handled
- by the space
46Applications
- Workflow systems
- Customer management systems
- Supply chain management
- Auction systems
- Trading service
- Agent systems
- Publish and subscribe service
- ...
47JavaSpaces Server
- Not a remote interface
- invocations of methods of JavaSpace throw
RemoteException - JavaSpaces server exports objects implementing
javaspace interface to clients
48JavaSpace Server
JavaSpace Server
Client
Server Interface
JavaSpace
JavaSpace
Client
49Entry implementation Example
- import net.jini.space.Entry
- public class MyEntry implements Entry
- public String name
- public GIFImage value
- public MyEntry()
-
50Sample implementation
- Requirements
- Entry implementation
- Sample invocation
51Sample invocation
- import net.jini.impl.outrigger.binders.RefHolder
- public class HelloWorld
- public JavaSpace getSpace()
- RefHolder rh (RefHolder)
Naming.lookup(JavaSpace) - JavaSpace js (JavaSpace) rh.proxy()
-
-
52Sample invocation
- JavaSpace space getSpace()
- MyEntry e new MyEntry()
- e.name Duke
- e.value new GIFImage (dukeWave.gif)
- space.write(e, null, 60601000)
53Supporting packages
- Leasing
- Transaction
- Distributed Event/Listener
54Third-party agents
Obj3
Obj1
Server
Server
Obj4
Obj2
55Jini lookup service reggie
- Reggie is an activatable process
- It just registers itself with rmid
- Rmid activates it as necessary
56(No Transcript)