P. 1
DIS Comp

DIS Comp

|Views: 1|Likes:
Published by Navneet Kumar
DIS Comp
DIS Comp

More info:

Published by: Navneet Kumar on Oct 09, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/09/2013

pdf

text

original

Distributed Computing

• Computing on many systems to solve one problem • Why?
- Combination of cheap processors often more cost-effective than one expensive fast system - Flexibility to add according to needs - Potential increase of reliability - Sharing of resources

• Why not?
- Security - Physical distribution may not match logical distribution of program - Programming effort & overhead

Distributed Object Systems 27/01/98 Java RMI 1

© Atze Dijkstra Dept. of Comp.Science, UU

Distributed system
• Supports distributed computing • What should a distributed system provide?
- Illusion of one system while running on multiple systems - Transparancy of resources

• Issues
- Communication, failure handling, synchronization - Protection, security - Resource management (allocation of process, devices, memory, re-allocation) - Naming (of resources, locating) - Data management (files, sharing) - Deadlock

Distributed Object Systems 27/01/98 Java RMI 2

© Atze Dijkstra Dept. of Comp.Science, UU

Client/server • Embedded in language Java .Science.Adds naming compared with RPC .Restricted to Java environments Distributed Object Systems 27/01/98 Java RMI 3 © Atze Dijkstra Dept.Implementing some application for user .Using support of distributed services .Layers of support .Java RMI • Communicating entities Process Process Interprocess communication service Communication Communication software software Communication hardware .Object variant of remote procedure call . of Comp. UU .

Example • Hello world (or: a difficult way of saying. message = obj.println("HelloApplet: an exception occurred:"). } } Distributed Object Systems 27/01/98 Java RMI 4 © Atze Dijkstra Dept. of Comp.sayHello(). 50).) • Application (applet) code. UU .getHost() + "/HelloServer").Applet { String message = "".. client public class HelloApplet extends java. public void init() { try { Hello obj = (Hello) Naming.Science.lookup("//" + getCodeBase().. } catch (Exception e) { System.printStackTrace(). e.applet. 25. } } public void paint(Graphics g) { g.drawString(message.out.

println("HelloImpl created and bound in the registry to the name HelloServer"). UU .out. public HelloImpl(String s) throws java.printStackTrace().rmi.RemoteException { super(). name = s.main: an exception occurred:").Science.println("HelloImpl. of Comp. } } } Distributed Object Systems 27/01/98 Java RMI 5 © Atze Dijkstra Dept. e. } public String sayHello() throws RemoteException { return "Hello World!". try { HelloImpl obj = new HelloImpl("HelloServer"). } catch (Exception e) { System. Naming.rebind("HelloServer". obj).Example (cont'd) • Server code public class HelloImpl extends UnicastRemoteObject implements Hello { private String name.setSecurityManager(new RMISecurityManager()). System.out. } public static void main(String args[]) { // Create and install the security manager System.

implements Hello interface) .Invokes methods on object Distributed Object Systems 27/01/98 Java RMI 6 © Atze Dijkstra Dept. of Comp.Creates an object which does what it should do (i. UU . invoking sayHello • Client side .Stops .Example (cont'd) • Server side .Science.e.Asks registry for object corresponding to name on some machine .Tells the registry to register the object under some name (registry should be running) .Runtime environment directs requests to object.

Science. not actual implementation .RMI features • Distributed object model . normal objects by copying .Remote references can be distributed freely .Environment takes care of remote invocation • Differences normal and remote objects . of Comp.Remote object can be used as normal object .Remote object exists on other host .Behavior described by interface .Passing remote objects by reference.Failure handling more complicated since invocation itself can also fail Distributed Object Systems 27/01/98 Java RMI 7 © Atze Dijkstra Dept.Clients only know/use interface.Objects: normal and remote • Idea . UU .

g. invokes stub method (proxy pattern) • Stub uses administration of remote reference to locate server (e.Science. of Comp.g. env 2) • Invocation packaged & passed via transport & network to server • Handled by skeleton which invokes locally appropriate method Distributed Object Systems 27/01/98 Java RMI 8 © Atze Dijkstra Dept.Implementation architecture Java Environment 1 Application or Applet Stub Skeleton Java Environment 2 Application or Applet Stub Skeleton Remote Reference Transport Security Dist GC Loader Remote Reference Transport Security Dist GC Loader • Client interacts with stub (e. UU . in env 1).

Science. UU . of Comp.Interfaces and classes • For client and server Client side Remote Server side RemoteObject RemoteServer UnicastRemoteServer .Server implements interface Remote via extending RemoteObject Distributed Object Systems 27/01/98 Java RMI 9 © Atze Dijkstra Dept.Client uses interface Remote .

Remote .Science. of Comp. UU .Server implements Hello public class HelloImpl extends UnicastRemoteServer implements Hello Distributed Object Systems 27/01/98 Java RMI 10 © Atze Dijkstra Dept.Hello is a Remote public interface Hello extends java.Interfaces and classes • Hello example Client side Remote Hello Server side RemoteObject RemoteServer UnicastRemoteServer HelloImpl .rmi.

.Separate compiler (rmic) makes stub and skeleton .Interfaces and classes • Hello invocation Remote Hello RemoteObject RemoteServer UnicastRemoteServer HelloImpl HelloStub HelloSkeleton .getHost() + "/HelloServer"). UU .Science.rebind("HelloServer".lookup ("//" + getCodeBase().sayHello().Server HelloImpl makes itself known to naming service HelloImpl obj = new HelloImpl("HelloServer"). .Client asks Naming service for the stub Naming.Client invokes stub for Hello message = obj. Distributed Object Systems 27/01/98 Java RMI 11 © Atze Dijkstra Dept. Naming. obj). of Comp.

g.Connection may break . too busy) .Exceptions • Extra things may go wrong .Science.Server may refuse (e.etc. of Comp. Distributed Object Systems 27/01/98 Java RMI 12 © Atze Dijkstra Dept. UU .Server does not trust data from client (security problem) .Server may be down (or go down halfway invocation) .

UU ..Failure must ultimately be handled by client Distributed Object Systems 27/01/98 Java RMI 13 © Atze Dijkstra Dept. of Comp. } public class HelloImpl extends UnicastRemoteObject implements Hello { private String name. .Science.RemoteException.May be thrown by all remote methods public interface Hello extends java.Remote { String sayHello() throws java..rmi. public String sayHello() throws RemoteException { ..rmi. ..Exceptions • Extra category of exceptions: RemoteException .

Stub of remote object is passed as non-remote object .Stub contains information on location of server object Distributed Object Systems 27/01/98 Java RMI 14 © Atze Dijkstra Dept.Parameter passing • Non-remote objects .Graph of related objects is packaged (marshalled) at client side .Passed by copy .Packaged data is unmarshalled at server side and reconstructed into local object graph • Remote objects .Science. UU . of Comp.

echo ) .sun.Science.Locating remote objects • How to get a remote reference .Naming service itself may also be server .rmi. .Naming service is bootstrap service. of Comp. java.com/echo" .rmi. EchoImpl echo = new EchoImpl() .As a result value of another (remote) method invocation • Via a naming service .Naming.Naming( url ) .Given an URL (Uniform Resource Locator) and server made known to naming service String url = "rmi://java. .bind( url. UU .Looked up by client echo = (Echo)java. so needs fixed way of finding it Distributed Object Systems 27/01/98 Java RMI 15 © Atze Dijkstra Dept.

Naming • Registry maps names to objects • Default registry of objects uses URL's as names rmi://java. UU . of Comp.Science.com:2001/root • Registry maintains flat name space • Binding name to object void bind( String url. Remote obj ) • Unbinding void unbind( String url ) • Listing String[] list( String url ) Distributed Object Systems 27/01/98 Java RMI 16 © Atze Dijkstra Dept.sun.

class (client code) rmic (rmi stub compiler) HelloImpl_Skel.java (server source) HelloAppl.Science. of Comp.From source to client and server • From source to code: Java compiler Hello. UU .java (client source) javac (java compiler) Hello.class (client stub code) • From code to stubs: RMI compiler • From name to object (at runtime): rmiregistry as separate name server on wellknown location (tcp/ip port) • Server and client are started as separate programs Distributed Object Systems 27/01/98 Java RMI 17 © Atze Dijkstra Dept.class (interface) HelloImpl.class (server skeleton code) HelloImpl_Stub.class (server code) HelloAppl.java (interface) HelloImpl.

its class is loaded .Only if not already loaded .Science. remote object) is received (in server or client).Classes only loaded when SecurityManager is running .Stub contains location from which classes may be loaded .Invocation need to be wrapped in to HTTP requests (which are passed) Distributed Object Systems 27/01/98 Java RMI 18 © Atze Dijkstra Dept. e. of Comp.Loaded by appropriate ClassLoader. trojan horse .e.Security • Loading of classes .Firewall inhibits direct communication (via sockets) needed by RMI .Class location may or may not be used . same as class from which new class is needed • Stubs may misbehave.g. UU .When stub (i.Policy implemented in SecurityManager • Other security issues .

Normal garbage collection looks at all references to determine which are still in use . too large a task • RMI runtime counts references .Remote objects may not longer exist even when client thinks so Distributed Object Systems 27/01/98 Java RMI 19 © Atze Dijkstra Dept. last reference gone sends unreference message .Garbage collection • When is a remote object not needed anymore? . reference count is decremented . UU .First time reference sends server a reference message.Science. servers may go down.Incremented when reference enters a Java environment .When stub object itself is garbage collected.Tricky.Not feasible to do 'normal' garbage collection. networks may be separated . of Comp. clients too.

a pointer • Problem: remote access to objects .Objects are represented as pointer to data (which can contain pointers itself) .Either 'normal' or remote object • Normally .Object references • Passing data between client and server: objects are used everywhere .Have a globally unique identification (address).Parameters and results .Normal objects are copied.Object have address.Objects have address which is only valid for machine where object lives (is created) • Solution (in Java RMI): forbid it . port. etc etc . containing host name.Can only be used by invoking methods . made into a clone on other machine • Remote objects .Mapped in server to normal object Distributed Object Systems 27/01/98 Java RMI 20 © Atze Dijkstra Dept. UU . of Comp.Science.

of Comp.Customization of serialization (e.But is graph of objects referring to eachother .Possibly very large • Hosts . byte order) • Communication .Except remote objects (reference is passed) • Other issues .g. not a graph • Java RMI value transfer: serialization .May represent values in different ways (e. UU . files by filename instead of content) Distributed Object Systems 27/01/98 Java RMI 21 © Atze Dijkstra Dept.Passes only sequence of bytes.g.Object + objects referred to (recusrively) are marshalled into sequence of bytes .Science.Passing objects • Between hosts • Object .Is not only sequence of data (bytes) .

UU . of Comp.Science.Class evolution (formats change.. different versions) Distributed Object Systems 27/01/98 Java RMI 22 © Atze Dijkstra Dept.

connection refused.Communication port already in use • While invoking a method on a remote object ..Name not used (during lookup) Distributed Object Systems 27/01/98 Java RMI 23 © Atze Dijkstra Dept.Name already in use (during bind) . . .Error in server (regular or due to RMI) • While naming a remote object .What can go wrong • While publishing an object as remote .Corrupt communication .Same for skeleton . UU .Science. of Comp.Class and/or stub not found or wrong name . or not exported • While returning invocation result .Return value class unknown .Remote object no longer available..Unknown host.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->