JavaSpaces - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

JavaSpaces

Description:

Nifty Real-Time Interactive Example. Discussion. 9/25/09 ... int Y = rand(), Tmp=0; if (NodeNumber == 0) out('sum of all Ys',0); in('sum of all Ys', ? Tmp) ... – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 21
Provided by: wwwcsa
Category:
Tags: javaspaces | rand

less

Transcript and Presenter's Notes

Title: JavaSpaces


1
JavaSpaces
  • Johann Ammerlahn

2
Overview
  • Overview
  • Brief Background
  • Suns Java and Jini
  • Linda
  • JavaSpaces
  • Big Picture
  • Applications
  • API
  • Ugly Details
  • Nifty Real-Time Interactive Example
  • Discussion

3
Background Java Jini
  • Jini simple set of network protocols that use
    Javas virtual machine and RMI
  • Services offered
  • Network Discovery and Joining
  • Help an arbitrary device enter the network
  • Service Lookup
  • Creates a repository of available services
  • Object leasing
  • Facilitates a fundamental "transaction" view of
    the network
  • Distributed events
  • Extends the Java event model to work in a
    distributed manner
  • Side note Doesnt seem to have penetrated market
    much

4
Background Java Jini (cont.)
5
Background Linda
  • Distributed workspace research by David
    Gelernter at Yale
  • Combines message passing and shared memory
    paradigms
  • Nodes write arbitrary tuples (heterogeneous-type
    vectors) to shared memory
  • Nodes read matching tuples from shared memory
  • Exact matching is required for extraction
  • Lookup calls always block until matching tuple
    exists
  • (Yuck!)
  • NO guarantees about ordering, delay

6
Background Linda (cont.)
  • Core API
  • out()
  • Writes tuples to shared space
  • Example out("abc", 1.5, 12).
  • Result Insert (abc, 1.5, 12) into space
  • read()
  • Retrieves tuple copy matching arg list (blocking)
  • Example read(abc, ? A, ? B)
  • Result Finds (abc, 1.5, 12) and sets local
    variables A 1.5, B 12. Tuple (abc, 1.5,
    12) is still resident in space.
  • in()
  • Retrieves and deletes matching tuple from space
    (blocking)
  • Example Same as above except (abc, 1.5, 12) is
    deleted
  • Eval()
  • Evaluates a tuple on the server

7
Background Linda (cont.)
  • Example
  • //Run on each processor i with distinct
  • //NodeNumber 0,,i-1
  • int Y rand(), Tmp0
  • if (NodeNumber 0)
  • out("sum of all Ys",0)
  • in("sum of all Ys", ? Tmp)
  • Tmp Y
  • out("sum of all Ys",Tmp)
  • / barrier code would go here /
  • if (NodeNumber 0)
  • in("sum of all Ys", ? Tmp)
  • printf("d\n",Tmp)

8
Background Linda JavaSpaces
  • Linda greatly influenced JavaSpace concepts
  • Definitive book, JavaSpaces Principles,
    Patterns, and Practice
  • 2 of 3 authors got Ph.D.s under Gelernter on
    Linda-related subjects
  • Sun took Linda principles and added features
    necessary to make it work in the real world
  • Transactions, leases, events
  • JavaSpaces dont support Eval method
  • Server-side execution has requirements of
    fairness, security

9
JavaSpaces Visual Overview

10
JavaSpaces Visual Overview (cont.)

11
JavaSpaces Overview (cont.)
  • JavaSpace properties
  • Store Java objects instead of tuples
  • Spaces handle all details of sharing
  • Objects are persistent (serializable) until
    removed or leases expire
  • Object lookups are associative
  • Transactionally secure (atomic)
  • Objects may have executable content (e.g.
    methods)
  • Security via identity servers

12
JavaSpaces Applications
  • So what?
  • Applications
  • Chat Server
  • Participants read, write Message objects
  • Compute Server
  • Tasks are written into JavaSpace, compute nodes
    take tasks whenever they are ready and write
    results when done
  • Broker Systems
  • Items are advertised and bid for entirely within
    auction space
  • Email

13
JavaSpaces Compute Server
14
JavaSpaces API
  • Object Example
  •      import net.jini.core.entry.Entry     publi
    c class Message implements Entry
             public String content         public
    Message()             
  • Requirements
  • Implement Net.jini.core.entry.Entry (marker
    interface)
  • No-argument constructor (for deserialization)
  • No primitive types (Integer class instead of int)
  • Important fields should be public

15
JavaSpaces API (cont.)
  • notify(Entry tmpl, Transaction txn,
    RemoteEventListener listener, long lease,
    MarshalledObject handback)
  • When entries are written that match this template
    notify the given listener with a RemoteEvent that
    includes the handback object.
  •  Entry read(Entry tmpl, Transaction txn,
    long timeout)
  • Read any matching entry from the space, blocking
    until one exists.
  •  Entry readIfExists(Entry tmpl, Transaction txn,
    long timeout)
  • Read any matching entry from the space, returning
    null if there is currently is none.
  •  Entry snapshot(Entry e)
  • Return a snapshot of the given entry.
  •  Entry take(Entry tmpl, Transaction txn,
    long timeout)
  • Take a matching entry from the space, waiting
    until one exists.
  •  Entry takeIfExists(Entry tmpl, Transaction txn,
    long timeout)
  • Take a matching entry from the space, returning
    null if there is currently is none.
  •  Lease write(Entry entry, Transaction txn,
    long lease)
  • Write a new entry into the space.

16
JavaSpaces API (cont.)
  • Notify
  • JavaSpace sends an event when an object matching
    your template is written
  • If used with NotifyDelegator class, the object
    that triggered the event may be obtained
  • Transactions
  • Way to lump operations together into a single
    atomic unit
  • Basic guarantees of atomicity (all or none
    commit)
  • Can deadlock
  • Two-phase commit model
  • Snapshot
  • Returns a particular JavaSpaces serialization of
    an object
  • Useful for multiple reads, takes
  • No guarantees if a snapshot from Space1 is used
    with Space2

17
JavaSpaces API (cont.)
  • More on Transactions
  • Properties
  • Atomicity All or none
  • Consistency Completion leaves system in
    consistent state
  • Isolation Concurrent transactions dont affect
    each other
  • Durability Results as persistent as entity to
    which they are applied
  • Effects on operations
  • Write Entries are not visible outside
    transaction until it commits
  • Read All entries in outside of transaction are
    searched
  • Take Same as read
  • Notify Applies to all writes as well as those
    within the current Transaction

18
JavaSpaces Details
  • Internals
  • Written objects are serialized into JavaSpaces
    server
  • Field matching is exact, based on identical
    serializations in Java Server
  • Null value is wildcard
  • To match an initialization, use a Boolean
    isInitialized
  • Guarantees
  • None (ha ha)
  • Not quite
  • No persistence guarantee (server crash)
  • No ordering guarantee
  • Thread 1 inserts Object O on Tuesday, Thread 2
    cant find it on Wednesday
  • 5 Threads are waiting for an Object O, when it
    appears they are woken randomly
  • 12 copies of Object O are written to server, all
    O reads return the sixth
  • Atomicity under Transaction model

19
JavaSpaces Example
  • public class HelloWorld extends SpaceApplet
        private JavaSpace space    public void
    init()         super.init()        space
    (JavaSpace)space()                try
                Message msg new
    Message()            msg.content "Hello
    World"            space.write(msg, null,
    Lease.FOREVER)            Message template
    new Message()            Message result
    (Message)space.take(template, null,
    Long.MAX_VALUE)             System.out.println(r
    esult.content)         catch (Exception e)
                e.printStackTrace()

20
JavaSpaces Discussion
  • Linda concepts in a distributed environment
  • Vs. MPI?
  • Vs. Shared memory?
  • JavaSpaces (as an implementation of Linda ideas)
  • Limitations?
  • Potential?
  • Where the heck is it? Implemented 98-99
  • Applicability to Sensor Networks?
  • New requirements for OS, applications?
  • Good paradigm for devices that should sleep as
    often as possible?
  • Would a java VM be easy to implement in TinyOS?
Write a Comment
User Comments (0)
About PowerShow.com