Distributed Systems. Distributed Object Systems 2 Java RMI. Java RMI. Example. Applet continued. Applet. slides2.pdf Sep 9,

Similar documents
Distributed Computing

Last Class: Network Overview. Today: Distributed Systems

JAVA RMI. Remote Method Invocation

Distributed Systems. 5. Remote Method Invocation

Course Snapshot. The Next Few Classes. Parallel versus Distributed Systems. Distributed Systems. We have covered all the fundamental OS components:

Remote Objects and RMI

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

Course Snapshot. The Next Few Classes

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development:

IBD Intergiciels et Bases de Données

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

CS 5523 Operating Systems: Remote Objects and RMI

JAVA RMI Java, summer semester

Remote Method Invocation

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University

Remote Procedure Call

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

How are classes loaded into the Java Virtual Machine (JVM)? from the local file system (CLASSPATH). by an instance of ClassLoader

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

5.4. Events and notifications

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Written by: Dave Matuszek

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

RMI. Remote Method Invocation. 16-Dec-16

CSci Introduction to Distributed Systems. Communication: RPC In Practice

RPC and RMI. 2501ICT Nathan

Grid Computing. Java Remote Method Invocation (RMI) RMI Application. Grid Computing Fall 2006 Paul A. Farrell 9/5/2006

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

Chapter 15: Distributed Communication. Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine.

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414

5 Distributed Objects: The Java Approach

RMI. (Remote Method Invocation)

RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call

COMP 6231: Distributed System Design

Distributed Programming in Java. Distribution (2)

Lab 2 : Java RMI. request sayhello() Hello interface remote object. local object. response "Hello world"

Lecture VI: Distributed Objects. Remote Method Invocation

Remote Method Invocation

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP)

Agent and Object Technology Lab Dipartimento di Ingegneria dell Informazione Università degli Studi di Parma. Distributed and Agent Systems RMI

Distributed Software Systems

Distributed Objects SPL/ SPL 201 / 0 1

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course

Distributed Objects. Chapter Distributing Objects Overview

presentation DAD Distributed Applications Development Cristian Toma

Verteilte Systeme (Distributed Systems)

Distributed Programming with RMI. Overview CORBA DCOM. Prepared By: Shiba R. Tamrakar

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Antoun Yaacoub Ph.D.

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

RMI Example RMI. CmpE 473 Internet Programming RMI

Remote Method Invocation

03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

Distributed object component middleware I - Java RMI

Distributed object component middleware I - Java RMI

Component-Based Software Engineering

BEA WebLogic. Server. Programming WebLogic RMI

Distributed Information Systems

RMI Case Study. A Typical RMI Application

Generic architecture

Outline. Chapter 4 Remote Procedure Calls and Distributed Transactions. Remote Procedure Call. Distributed Transaction Processing.

Remote Method Invocation R.M.I.

Programming with RMI Reminder

Remote Method Invocation in Java

Remote Invocation Vladimir Vlassov and Johan Montelius

Chapter 4 Remote Procedure Calls and Distributed Transactions

EAST WEST UNIVERSITY

BEA WebLogic Server. Programming WebLogic RMI

Communication and Distributed Processing

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

DISTRIBUTED COMPUTING

REMOTE METHOD INVOCATION INTRODUCTION TO RMI, A JAVA API FOR RPC-STYLE INVOCATION OF REMOTE OBJECT METHODS

Communication and Distributed Processing

CS193k, Stanford Handout #12. Threads 4 / RMI

Remote Method Invocation. Benoît Garbinato

Remote Method Invocation Benoît Garbinato

DIFFERENCE BETWEEN APPLET AND APPLICATION

Distributed Systems COMP 212. Lecture 10 Othon Michail

CC755: Distributed and Parallel Systems

Dynamic code downloading using Java TM (Using the java.rmi.server.codebase Property)

A Typical RMI Application

Java RMI Activation: A running example We have the following classes: MyRemoteInterface: the remote interface. Client: the client that invokes a

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Lecture 5: RMI etc. Servant. Java Remote Method Invocation Invocation Semantics Distributed Events CDK: Chapter 5 TVS: Section 8.3

Web. Remote Method Invocation. core. programming. Training Courses: Java, JSP, Servlets, Struts, & JSF:

IJESRT. http: //

Lecture 06: Distributed Object

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java

A Typical RMI Application. Case Study

Distributed Systems Lecture 2 1. External Data Representation and Marshalling (Sec. 4.3) Request reply protocol (failure modes) (Sec. 4.

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák

CHAPTER - 4 REMOTE COMMUNICATION

The Common Object Request Broker Architecture (CORBA)

Java RMI. Algorithmen und Programmierung V Netzprogrammierung. Volker Roth. Wintersemester 2009/2010. Institut für Informatik Freie Universität Berlin

6 Distributed Object-Based Systems

Object-Oriented Systems Design RMI

Remote Method Invocation Java RMI & Web-Services

Transcription:

Distributed Object Systems 2 Java RMI Piet van Oostrum Distributed Systems What should a distributed system provide? Illusion of one system while running on multiple systems Transparancy Issues Communication, failure handling, synchronization Protection, security Resource management (allocation of process, devices, memory, re-allocation, garbage collection) Naming (locating objects) Deadlock prevention September 9, 2008 Piet van Oostrum 1 Java RMI Communicating entities object remote method call object Example Hello world (or: a difficult way of saying) Process Process Interprocess communication service Communication Communication software software Communication hardware Embedded in language Java Object variant of remote procedure call Adds naming compared with RPC Restricted to Java environments But now also with a bridge to Corba Piet van Oostrum 2 Piet van Oostrum 3 Applet Applet continued Application (applet) code, client public class HelloApplet extends java.applet.applet String message = ""; public void paint(graphics g) g.drawstring(message, 25, 50); Get the message from some remote object public interface Hello extends java.rmi.remote String sayhello() throws java.rmi.remoteexception; public void init() try Hello obj = (Hello) Naming.lookup("//" + getcodebase().gethost() + "/HelloServer"); message = obj.sayhello(); catch (Exception e) System.out.println("HelloApplet: exception:"); e.printstacktrace(); Piet van Oostrum 4 Piet van Oostrum 5 slides2.pdf Sep 9, 2008 1

Server code Server code 2 public class HelloImpl implements Hello // constructor public HelloImpl() throws RemoteException super(); // method public String sayhello() throws RemoteException return "Hello RMI World!"; public static void main(string args[]) // Create and install the security manager System.setManager(new RMIManager()); try HelloImpl obj = new HelloImpl(); Naming.rebind("HelloServer", obj); System.out.println("HelloImpl created and bound"); catch (Exception e) System.out.println("HelloImpl.main: exception:"); e.printstacktrace(); Piet van Oostrum 6 Piet van Oostrum 7 Example (cont d) Server side Creates an object which does what it should do (i.e. implements Hello interface) Tells the registry to register the object under some name (registry should be running) Stops (waiting for requests) Runtime environment directs requests to object, invoking sayhello Client side Asks registry for object corresponding to name on some machine Invokes methods on object RMI features Distributed object model Objects: normal and remote Idea Remote object exists on other host (or other process in same host) Remote object can be used as normal object Behavior described by interface Environment takes care of remote invocation Differences normal and remote objects Remote references can be distributed freely Clients only know/use interface, not actual implementation Passing remote objects by reference, normal objects by copying Failure handling more complicated since invocation itself can also fail Don t need separate IDL (use Java interface) Piet van Oostrum 8 Piet van Oostrum 9 Implementation architecture Java Environment 1 Application or Applet Stub Skeleton Remote Reference Java Environment 2 Application or Applet Stub Skeleton Remote Reference Implementation architecture Client interacts with stub (e.g. in env 1), invokes stub method (proxy pattern) Stub uses administration of remote reference to locate server (e.g. env 2) Invocation packaged and passed via transport and network to server Handled by skeleton which invokes locally appropriate method Transport Dist GC Transport Dist GC Loader Loader Piet van Oostrum 10 Piet van Oostrum 11 slides2.pdf Sep 9, 2008 2

Client side Server side Client side Server side Remote Remote RemoteServer Hello RemoteServer Unicast Client uses interface Remote Unicast Server implements interface Remote via extending Hello is a Remote Hello Impl public interface Hello extends java.rmi.remote Server implements Hello public class HelloImpl implements Hello Piet van Oostrum 12 Piet van Oostrum 13 Hello invocation Server HelloImpl makes itself known to naming service Remote Hello HelloStub RemoteServer Unicast HelloImpl HelloSkeleton HelloImpl obj = new HelloImpl("HelloServer"); Naming.rebind("HelloServer", obj); Client asks Naming service for the stub getcodebase().gethost() gets the host that the Applet comes from obj = (Hello)Naming.lookup ("//" + getcodebase().gethost() + "/HelloServer"); Separate compiler (rmic) makes stub and skeleton Recent Java: created at runtime Client invokes stub for Hello message = obj.sayhello(); Piet van Oostrum 14 Piet van Oostrum 15 Exceptions Extra things may go wrong Connection may break Server may be down (or go down halfway invocation) Server may refuse (e.g. too busy) Server does not trust data from client (security problem) etc. Exceptions Extra category of exceptions: RemoteException May be thrown by all remote methods public interface Hello extends java.rmi.remote String sayhello() throws java.rmi.remoteexception; Piet van Oostrum 16 Piet van Oostrum 17 slides2.pdf Sep 9, 2008 3

Exceptions public class HelloImpl implements Hello public String sayhello() throws RemoteException Locating remote objects How to get a remote reference As a result value of another (remote) method invocation Via a naming service Given an URL (Uniform Resource Locator) and server made known to naming service String url = "//www.cs.uu.nl/hello" ; HelloImpl hello = new HelloImpl() ; java.rmi.naming.bind( url, hello ) ; Failure must ultimately be handled by client Piet van Oostrum 18 Piet van Oostrum 19 Locating remote objects Looked up by client hello = (Hello)java.rmi.Naming.lookup( url ) ; Naming service itself may also be server Naming service is bootstrap service, so needs fixed way of finding it Naming Registry maps names to objects Default registry of objects uses URL s as names [rmi:]//java.sun.com:2001/root Registry maintains flat name space Binding name to object void bind( String url, Remote obj ) Unbinding void unbind( String url ) Rebinding void rebind( String url, Remote obj ) Listing String[ ] list( String url ) Piet van Oostrum 20 Piet van Oostrum 21 From source to client and server Hello.java (interface) javac (java compiler) Hello.class (interface) HelloImpl_Skel.class (server skeleton code) HelloImpl.java (server source) HelloImpl.class (server code) From source to code: Java compiler From code to stubs: RMI compiler HelloAppl.java (client source) HelloAppl.class (client code) rmic (rmi stub compiler) HelloImpl_Stub.class (client stub code) From name to object (at runtime): rmiregistry or rmid as separate name server on well-known location (TCP/IP port) Server and client are started as separate programs Loading of classes When stub (i.e. remote object) is received (in server or client), its class is loaded Only if not already loaded Loaded by appropriate ClassLoader, same as class from which new class is needed Stubs may misbehave, e.g. trojan horse Classes only loaded when Manager is running Stub contains location from which classes may be loaded Class location may or may not be used Policy implemented in Manager (policy file defines what is allowed) Piet van Oostrum 22 Piet van Oostrum 23 slides2.pdf Sep 9, 2008 4

Other security issues Firewall may inhibit direct communication (via sockets) needed by RMI Invocation need to be wrapped into HTTP requests (which are passed) Garbage collection When is a remote object not needed anymore? Normal garbage collection looks at all references to determine which are still in use Not feasible to do normal garbage collection, too large a task RMI runtime counts references Incremented when reference enters a Java environment When stub object itself is garbage collected, reference count is decremented First time reference sends server a reference message, last reference gone sends unreference message Newer implementations also use a lease mechanism (java.rmi.dgc) Tricky, servers may go down, clients too, networks may be separated Remote objects may not longer exist even when client thinks so Piet van Oostrum 24 Piet van Oostrum 25 Object references Passing data between client and server: objects can be used everywhere Parameters and results Either normal or remote object Normally (non-remote) Objects are represented as pointer to data (which can contain pointers itself) Object have address, a pointer Problem: remote access to objects Objects have address which is only valid for machine where object lives (is created) Parameter passing in remote method calls Non-remote objects Passed by value (copy) by serializing Graph of related objects is packaged (marshalled) at client side Possibly very large Packaged data is unmarshalled at server side and reconstructed into local object graph Changes made on them are not reflected in the original Remote objects Stub contains information on location of server object Can only be used by invoking methods Have a globally unique identification (address), containing host name, port, etc. etc. Mapped in server to normal object They are passed by reference Similar for results Piet van Oostrum 26 Piet van Oostrum 27 Example class ChangingObj int val; public void change(int v) val = v; public int val() return val; We do remote_obj.method(changingobj) and method calls changingobj.change(somevalue) then our changingobj will not be effected However if we would make ChangingObj into a Remote object it would Piet van Oostrum 28 Serialisation Java RMI value transfer: serialization Object + objects referred to (recursively) are marshalled into sequence of bytes Except remote objects (reference is passed) Other issues Objects to be passed to other machines must implement Serializable Most standard classes (e.g from java.lang and java.util) are serializable Customization of serialization (e.g. files by filename instead of content) Class evolution (formats change, different versions) Piet van Oostrum 29 slides2.pdf Sep 9, 2008 5

What can go wrong While publishing an object as remote Class and/or stub not found or wrong name Same for skeleton Communication port already in use While invoking a method on a remote object Unknown host, connection refused, Remote object no longer available, or not exported While returning invocation result Corrupt communication Return value class unknown Error in server (regular or due to RMI) While naming a remote object Name already in use (during bind) Name not used (during lookup) Example with factory object Interface: public interface HelloFactory extends Remote Hello create(string msg) throws RemoteException; Client: HelloFactory fact = (HelloFactory)Naming.lookup ("//hostname/hellofactory"); Hello obj = fact.create("hello Factory World"); message = obj.sayhello(); Piet van Oostrum 30 Piet van Oostrum 31 Server with factory public class HelloFactoryImpl implements HelloFactory public Hello create(string msg) throws RemoteException return new HelloImpl(msg); HelloFactoryImpl fact = new HelloFactoryImpl(); // Bind this instance to the name "HelloFactory" Naming.rebind("HelloFactory", fact); Summary Java remote objects built-in in the language (library) all Java so no IDL necessary remote objects not transparent: Remote interface, RemoteExceptions parameter passing different naming service most nitty-gritty dealt with by RMI runtime security manager garbage collection with refcounts and/or leasing creating remote objects with factory HelloImpl constructor should now accept the string as parameter Piet van Oostrum 32 Piet van Oostrum 33 slides2.pdf Sep 9, 2008 6