Remote Method Invocation Benoît Garbinato

Similar documents
Remote Method Invocation. Benoît Garbinato

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

Remote Method Invocation

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

IBD Intergiciels et Bases de Données

5.4. Events and notifications

JAVA RMI. Remote Method Invocation

Distributed Systems COMP 212. Lecture 10 Othon Michail

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

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

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

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

Verteilte Systeme (Distributed Systems)

Written by: Dave Matuszek

RMI. Remote Method Invocation. 16-Dec-16

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

Distributed Programming in Java. Distribution (2)

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

RMI. (Remote Method Invocation)

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

Remote Objects and RMI

CS 5523 Operating Systems: Remote Objects and RMI

Generic architecture

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

presentation DAD Distributed Applications Development Cristian Toma

Chapter 5 Distributed Objects and Remote Invocation

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

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

CS193k, Stanford Handout #12. Threads 4 / RMI

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

Distributed Objects. Remote Method Invokation

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

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

Distributed Systems. The main method of distributed object communication is with remote method invocation

Remote Method Invocation

Distributed object component middleware I - Java RMI

JAVA RMI Java, summer semester

Distributed object component middleware I - Java RMI

RMI Case Study. A Typical RMI Application

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Lecture VI: Distributed Objects. Remote Method Invocation

Distributed Computing

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

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

Last Class: Network Overview. Today: Distributed Systems

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

Chapter 4: Processes. Process Concept. Process State

Remote Method Invocation

Remote Procedure Call

Chapter 4 Remote Procedure Calls and Distributed Transactions

Communication and Distributed Processing

IJESRT. http: //

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

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

CORBA (Common Object Request Broker Architecture)

Distributed Systems. 5. Remote Method Invocation

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

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

Communication and Distributed Processing

Remote Method Invocation Java RMI & Web-Services

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

THE RMI PROXY USER GUIDE

Distributed Software Systems

Remote Method Invocation in Java

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

Applications. RMI, RPC and events. Request reply protocol External data representation. Operating System

Activation of remote objects

Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63.

Lecture 5: Object Interaction: RMI and RPC

RMI Example RMI. CmpE 473 Internet Programming RMI

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

EDA095 Remote Method Invocation

EDA095 Remote Method Invocation

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

Are Sockets a Good Programming Paradigm? EDA095 Remote Method Invocation. The Remote Procedure Call Model. The Remote Procedure Call Architecture

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

Modulo II Socket, RMI e Corba

Lecture 15: Frameworks for Application-layer Communications

Lecture 15: Frameworks for Application-layer Communications

5 Distributed Objects: The Java Approach

Distributed Information Systems

CHAPTER - 4 REMOTE COMMUNICATION

Chapter 4 Communication

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

A Typical RMI Application

Distributed Systems. Communication (2) Schedule of Today. Distributed Objects. Distributed Objects and RMI. Corba IDL Example

A Report on RMI and RPC Submitted by Sudharshan Reddy B

A Typical RMI Application. Case Study

Distributed Objects SPL/ SPL 201 / 0 1

Course Snapshot. The Next Few Classes

Distributed Applications Programming. Lab 4

Component-Based Software Engineering

Are Sockets a Good Programming Paradigm? EDA095 Remote Method Invocation. The Remote Procedure Call Model. The Remote Procedure Call Architecture

Java Remote Method Invocation Specification

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

RPC and RMI. 2501ICT Nathan

Distributed Systems. Communication (2) Lecture Universität Karlsruhe, System Architecture Group

CSci Introduction to Distributed Systems. Communication: RPC In Practice

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

Transcription:

Remote Method Invocation Benoît Garbinato 1 Fundamental idea (1) Rely on the same programming paradigm for distributed applications as for centralized applications In procedural languages, we will rely on the notion of Remote Procedure Call (RPC) In object-oriented language, we will rely on the notion of Remote Method Invocation (RMI) 2

Fundamental idea (2) client server call / invocation Process A Process B A remote method (procedure) is transparently invoked (called) across the network, as if it was local 3 RPC: some history 1979!! Bill Joy introduces the Berkeley Enhancements, mainly interprocess communication (IPC) facilities. The modern network Unix is born (BSD). mid 80 s! Sun Microsystems uses BSD Unix as operating system for their workstations. They extends it with RPC, on top of which they build NFS and NIS (later on NIS+). 1988!! The Open Software Foundation (OSF) is formed to develop a portable open system platform, known as the Distributed Computing Environment (DCE). The latter proposes DCE RPC as basic communication mechanism. mid 90 s! The Object Management Group (OMG) follows the same approach to devise the Common Object Request Broker Architecture (CORBA) for object-based middleware. At the same time, Sun greatly simplifies & extends the RMI paradigm its Java & Jini platforms. Today!! Everybody talks about Web Services as the next big thing, but it is merely a web-flavored version of the RPC/RMI paradigm, using HTTP & XML. 4

A local method invocation client call stack result parameter 1 parameter 2... parameter n stack frame of foo(...) server parameters result = server.foo(parameters) result 5 A remote method invocation parameters client client stub transport result request reply network result server server stub transport parameters reply request 6

The notion of proxy A proxy is the representative of a server object in the address space of the client A proxy implements the same interface as the server (but not in the same way) client proxy server client space foo(...) foo(...) this is where the real work is done server space 7 Java RMI In Java, Remote method invocation is integrated in the standard class library, via packages such as java.rmi, java.rmi.server, etc. In addition, Sun s Java Development Kit (JDK) includes a set of tools for supporting RMI, e.g., rmic, rmiregistry, etc. We can distinguish three distinct times when building rmi-based applications, namely development, deployment and execution. 8

Execution time 1. The server object registers its name & proxy in the naming service (rmi registry) 2. The client object obtains a proxy of the server object via that naming service 3. The client object can then invoke the server proxy, which will then forward the invocation to the server object 9 Server side: create & bind public class CalendarApp {... public static void main(string[] args) throws Exception { String thename= "Calendar"; CalendarServer theserver= new CalendarServer(); Naming.rebind(theName, theserver); System.out.println("Calendar service is running!"); 10

Client side: lookup & use public class CalendarClient {... public static void main(string[] args) throws Exception { String calservname= "//www.acme.com/calendar"; CalendarService calserv= (CalendarService) Naming.lookup(calServName); calserv.createcalendar("james"); Collection allcals= calserv.getcalendars(); DayCalendar dno= calserv.getcalendar("dr. No"); String[] elist= dno.listevents(); 11 Calendar Application client rmi registry calendar service rebind(...) Dr. no's calendar lookup(...) createcalendar ("James") getcalendar ("Dr.No") new DayCalendarImp("James") James' calendar listevents() listevents() 12

Development time 1. Define the interface of the remote service 2. Implement the client and server classes in a decoupled way, thanks to the interface 3. Use javac to compile all above sources 4. Use the rmic compiler to create the proxy of the remote class for you 13 Typical remote interfaces import java.util.*; import java.rmi.*; public interface CalendarService extends Remote { public DayCalendar createcalendar(string name) throws RemoteException, CalendarException; public DayCalendar getcalendar(string name) throws RemoteException, CalendarException; public ArrayList getcalendars() throws RemoteException; public boolean exists(string name) throws RemoteException; import java.util.*; import java.rmi.*; public interface DayCalendar extends Remote { public boolean isfree(date date) throws RemoteException; public DayEvent plan(dayevent event) throws RemoteException, CalendarException; public String[] listevents() throws RemoteException; public String getname() throws RemoteException; 14

A typical remote class public class CalendarServer extends UnicastRemoteObject implements CalendarService { private Hashtable calendars; public CalendarServer() throws RemoteException { calendars= new Hashtable(); public DayCalendar createcalendar(string name) throws RemoteException, CalendarException { if (calendars.containskey(name)) throw new CalendarException(name + "\" already exists."); DayCalendar newcal= new DayCalendarImpl(name); calendars.put(name, newcal); return newcal; public DayCalendar getcalendar(string name) throws RemoteException, CalendarException { if (!calendars.containskey(name)) throw new CalendarException(name + "\" does not exist."); return ((DayCalendar) calendars.get(name)); public ArrayList getcalendars() throws RemoteException { return new ArrayList(calendars.values()); public boolean exists(string name) throws RemoteException { return calendars.containskey(name); 15 Argument passing rules 1. An argument or a return value can be a primitive type, a local serializable object (i.e, implementing java.io.serializable), or a remote object. 2. A primitive type value is passed by copy. 3. A local object is also passed by copy, using standard object serialization. 4. A remote object is passed by reference, i.e., its proxy is passed rather than the object itself. 16

Deployment time 1. Start the rmi registry 2. Start the server process 3. Start the client process! CalendarService CalendarServer_Stub CalendarService CalendarServer_Stub DayCalendar # rmi registry DayCalendar CalendarException DayEvent DayCalendarImpl CalendarException CalendarServer DayEvent CalendarClient DayCalendarImpl_Stub client machine client process server process " DayCalendarImpl_Stub server machine 17 Checkup On the server we have:! CalendarServer theserver= new CalendarServer(); whereas on the client we have:!! CalendarService calserv=!!!! (CalendarService) Naming.lookup(calServName); why this difference? Where are calendars located? How does the client get access to calendars? How do we communicate with the rmi registry? 18

RMI callbacks (1) A remote object does not need to be registered in the naming service to be remotely accessible, e.g., DayCalendarImpl. The client can also make an object remotely accessible to the server, allowing the latter to asynchronously call back the client, e.g., to notify the client that a new event was scheduled on some calendar. 19 RMI callbacks (2) public interface CalendarListener extends Remote { public void eventplanned(dayevent e) throws RemoteException; public interface DayCalendar extends Remote { public boolean isfree(date date) throws RemoteException; public DayEvent plan(dayevent event) throws RemoteException, CalendarException; public String[] listevents() throws RemoteException; public String getname() throws RemoteException; public void addlistener(calendarlistener l) throws RemoteException; public class CalendarClient extends UnicastRemoteObject implements CalendarListener {... public static void main(string[] args) throws Exception { String calservname= "//www.acme.com/calendar"; CalendarService calserv= (CalendarService) Naming.lookup(calServName); DayCalendar dno= calserv.getcalendar("dr. No"); CalendarListener calist= new CalendarClient(); dno.addlistener(calist); dno.plan(new DayEvent(new Date(), "Conquer the world")); public void eventplanned(dayevent e) throws RemoteException { System.out.println("--> New event planned: " + e); 20

RMI callbacks (3) public class DayCalendarImpl extends UnicastRemoteObject implements DayCalendar { private TreeSet eventset; private ArrayList listeners;... public void addlistener(calendarlistener l) throws RemoteException { listeners.add(l); private void notifylisteners(dayevent e) { Iterator iter= listeners.iterator(); while ( iter.hasnext() ) try { ((CalendarListener) iter.next()).eventplanned(e); catch (RemoteException re) { System.err.println("Notification failed"); ; public DayEvent plan(dayevent event) throws RemoteException, CalendarException { if (eventset.contains(event)) throw new CalendarException("The date is not free"); eventset.add(event); notifylisteners(event); return event; client 1 Dr. no's calendar client 2 addlistener(this)... eventplanned(...) plan(new Event(...)) 21 Dynamic code download (1) The Java platform allows for the dynamic download of classes from any URL (Uniform Resource Locator) 22

Dynamic code download (2) The proxy is located on the client but it conceptually belongs to the server Because we have a Java Virtual Machine on both the server and the client, it is possible to have the proxy move from the server to the client at runtime (dynamic code download) Dynamic code download can be used not only for proxies but for any Java class 23 Dynamic code download (3) this is added to the classpath " java -Djava.rmi.server.codebase=http:/client.com/... java -Djava.rmi.server.codebase=http://server.com/... rmi registry CalendarService CalendarServer_Stub CalendarClient_Stub CalendarListener CalendarService DayCalendar CalendarException % web server $ web server! # DayCalendar CalendarException DayCalendarImpl_Stub CalendarListener DayEvent DayEvent CalendarClient client machine client process server process DayCalendarImpl CalendarServer server machine 24

Security viewpoint From a security viewpoint, downloading classes is a critical action (i.e., potentially dangerous) For this reason, when code download is activated (via the java.rmi.server.codebase property), the Java Virtual Machine requires a security manager to be installed The security policy enforced by the security manager can be expressed declaratively in a security policy file 25 Security manager & policy Source code: Command line: Policy files: (my.policy) if (System.getSecurityManager() == null) System.setSecurityManager(new RMISecurityManager()); java -Djava.security.policy=my.policy... grant { permission java.net.socketpermission "server.com:1024-65535", "connect,accept"; permission java.net.socketpermission "server.com:80", "connect,accept"; ; client Runtime: grant { permission java.net.socketpermission "*:1024-65535", "connect,accept"; permission java.net.socketpermission "*:80", "connect,accept"; ; Some object Java runtime SecurityManager AccesController critical system call server check checkpermission() 26

Distributed Garbage Collection The Java platform transparently extends garbage collection to distributed objects. This extension is known as Distributed Garbage Collection (DGC). A remote object is collected when there no longer exists any remote or local references to it Any object referenced by the naming service (rmi registry) is not collected 27 Unreferenced vs. finalized By implementing the Unreferenced interface, a remote object can ask to be notified when there no longer exists any remote references to it In the unreferenced() method, the remote object is given the opportunity to release some resources, e.g., the remote reference on a another remote object public class DayCalendarImpl extends UnicastRemoteObject implements DayCalendar, Unreferenced {... public void unreferenced() { System.out.println("-> Oups, I am no longer remotely referenced!"); called by the local garbage collector protected void finalize() throws Throwable { System.out.print("This time, I am really about to be garbage collected... ); System.out.print("so bye bye cruel world!"); called by the distributed garbage collector 28

Limitations of DGC An implementation of DGC should ensure Safety, which implies not collecting too early Liveness, which implies eventually collecting Due to its inherent decentralized nature, the implementation of DGC is based on reference counting, which poses several issues: It does not deal properly with circular references It does not deal properly with asynchronous systems Partial solution: the notion of lease 29 The notion of lease A lease is a remote reference with a validity limited in time In Java, remotes references are actually leases If the client does not renew its lease before the associated timeout expires, the reference counter on the server side is decremented Leases are automatically managed for you, i.e., the renewal is automatic as long as the client is alive and the remote reference exists 30

Questions? 31