Docstoc

DISTRIBUTED

Document Sample
DISTRIBUTED Powered By Docstoc
					Java-Based Distributed Models
                             Charles E. Hughes
                              ceh@cs.ucf.edu
                       http://www.cs.ucf.edu/~ceh
                 Professor, School of Computer Science
                      University of Central Florida




 Last Updated 29 Nov. 1999                               1
Common DS Paradigms
• Channels – send / receive

   – Messages to single or collection of recipients

• Distributed Objects – invoke services on remote objects

   – Requires object serialization and un-serialization
• Tuple space – write, read, take

   – A space for reliable communication and coordination




   Last Updated 29 Nov. 1999                                2
IP Network Communication
• Each node has an address (IP address)

• Each node has many mailboxes (ports)

• Messages (packets) are received at and sent through

  ports




  Last Updated 29 Nov. 1999                        3
UDP – Simplest Communication
• Like regular mail

   – I send messages with a return address and mailbox #

         • There’s no guarantee of delivery or order of receipt

   – If all goes well you receive my mail at your mailbox

         • You can respond using my address and mailbox number




  Last Updated 29 Nov. 1999                                       4
Sample UDP Service
• CLIENT (sender)
 socket = new DatagramSocket();
 packet = new DatagramPacket(sendBuf,256,host,5500);
 socket.send(packet);
• SERVER (receiver)
 socket = new DatagramSocket(5500);
 packet = new DatagramPacket(buf, 256);
 socket.receive(packet);
 address = packet.getAddress();
 port = packet.getPort();
 s = new String(packet.getData(),packet.getlength());




  Last Updated 29 Nov. 1999                       5
TCP/IP – Common Protocol
• Like a phone call

   – I place a call your address and ask for you (port)

   – You pick up and automatically have my address and port

   – We have a two-way channel (stream) over which we communicate

   – We need to be sure our messages are arriving reliably and in order




   Last Updated 29 Nov. 1999                                          6
Sample TCP/IP Service
• CLIENT (sender, then just participant)
 connection = new Socket( host, 5000 );
 in = connection.getInputStream();
 out = connection.getOutputStream();


• SERVER (receiver, then just participant)
 server = new ServerSocket( 5000, 2 );
 connection = server.accept();
 in = connection.getInputStream();
 out = connection.getOutputStream();




  Last Updated 29 Nov. 1999                  7
Remote Messages

• Personalized at the object level

• Messages are at a high-level of abstraction

• Interpretation of messages is at receiver end




  Last Updated 29 Nov. 1999                     8
Sketch of Sample RMI Service
• INTERFACE
  public interface Hughes extends Remote {
      ResType service() throws RemoteException;}

• CLIENT
  obj = (Hughes )Naming.lookup(“//host/CharlesServer”);
  result = obj.service();


• SERVER
  obj = new HughesImpl();
  Naming.rebind("//host/CharlesServer", obj);




  Last Updated 29 Nov. 1999                               9
Tuple Space
• Tuples are like entries in a database
   – < “Mexico City”, “Querétaro”, 180 >
      means it takes 180 min. to travel from Mexico City to Querétaro

• We can match this with many templates
   – < “Mexico City”, “Querétaro”, Integer >

   – < String, “Querétaro” , 180 >




   Last Updated 29 Nov. 1999                                            10
Tuple Match
• Template is of a chosen class

• Template fields can have values or null

• Template can match only tuples of class or subclass

• Values are exact matches; nulls are type matches




  Last Updated 29 Nov. 1999                          11
Sketch of JavaSpace Service
• TEMPLATE
  public class Atlas implements Entry {
      public String startCity;
      public String endCity;
      public Integer travelTime; }
• PRODUCER
  JavaSpace space = SpaceAccessor.getSpace();
  Atlas msg = new Atlas(“Mexico City", “Querétaro”, 180);
  space.write(msg, null, Lease.FOREVER);
• CONSUMER
  JavaSpace space = SpaceAccessor.getSpace();
  Atlas template = new Message(); endCity = “Querétaro”;
  Atlas msg = space.take(template, null, Long.MAX_VALUE);




  Last Updated 29 Nov. 1999                             12
Tuple Space Bid for Airline Ticket
 • Customer write bid to proxy’s tuple space

     – p.write<me, home, to, leave, return, bid>
 • Customer takes bids from tuple space
     – p.take<?airline, me, home, to, ?leave, ?return, ?price>
 • Customer accepts some bid
     – p. write<airline,me,home,to,leave,return,price,credit>




    Last Updated 29 Nov. 1999                                    13
Proxy to Airlines
• Proxy takes bid from tuple space

    – p.take<?you, ?home, ?to, ?leave, ?return, ?bid>
• Proxy replicates (writes) bid to each airline (a)
    – a.write<airline, you, home, to, leave, return, bid>
• Proxy awaits and relays prices to you
    – a.read<?airline, you, home, to, leave, return, price>
    – p.write<airline, you, home, to, leave, return, price>




   Last Updated 29 Nov. 1999                                  14
Completing the Purchase
• Proxy passes your acceptance on

• Airline sends confirmation which is relayed to you

• Uses multiple tuple spaces

• Uses class (type) of template as part of match




  Last Updated 29 Nov. 1999                            15
Atomic Operations

• Want to treat group of actions as atomic

• At some point we either

   – Commit and roll all changes into visible state; or

   – Abort and roll back state to condition before group




 Last Updated 29 Nov. 1999                            16
Transactions
• Some client starts a transaction

• Others join the transaction

• Client asks for a vote from participants

• Each responds prepared, nochanges, or abort




  Last Updated 29 Nov. 1999                  17
Leases
• Crashes could be real bad with deserted tuples

• Each tuple leases space

   – You must renew lease or tuple is deleted automatically




  Last Updated 29 Nov. 1999                                   18
Completing Transactions
• All participants keep state at start

• All prepared participants save prepared state

• Client reports roll back if anyone voted abort

• Client reports roll forward if no aborts

   – Nochanges do not participate, but should pause




  Last Updated 29 Nov. 1999                           19
Jini Architecture
• Discovery

   – Find Jini lookup service (acts as broker)

• Join (if providing new service)

• Lookup services (if required)




  Last Updated 29 Nov. 1999                      20
Discovery Parameters
• Protocol version number ( = 1 )

• Response port

• Groups to discover (or empty for all)

• Set of lookup services that already responded

• All packed into at most 512 bytes for single UDP packet




   Last Updated 29 Nov. 1999                                21
Discovery Process

 Multicast request
      client
                              Multicast request
                                   server
Multicast response
      server
                              Multicast response
                                    client
Discovering Entity
                               Lookup Service

  Last Updated 29 Nov. 1999                        22
Discovery Protocol

• Use multicast to request local lookup service

• Use unicast to request specific lookup service




  Last Updated 29 Nov. 1999                   23
Join Parameters
• Service ID – assigned when service is new

• Attributes that describe service

• Groups in which service participates

• Lookup services at which this is (to be) registered




   Last Updated 29 Nov. 1999                            24
Avoiding a Packet Storm
• Wait a random time (up to 15 seconds)

• Then register service at lookup sites

• Random wait is useful after a crash

• If didn’t do this, then all servers would start simultaneously

    – Technique similar to that used after Ethernet collision




   Last Updated 29 Nov. 1999                                       25
Lookup
• Use lookup service to get desired service

   – Can choose by group and attributes

         • Print service that prints in color at 1440 dpi

         • Three-D rendering object that imports VRML


• Service object can be remote or a local proxy




  Last Updated 29 Nov. 1999                                 26

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:11
posted:9/9/2011
language:English
pages:26