Lecture VI: Distributed Objects. Remote Method Invocation

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

JAVA RMI. Remote Method Invocation

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

Remote Procedure Call

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

Distributed Systems. 5. Remote Method Invocation

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

Distributed Objects SPL/ SPL 201 / 0 1

Remote Method Invocation

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

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

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

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

5 Distributed Objects: The Java Approach

Verteilte Systeme (Distributed Systems)

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Distributed Information Systems

Distributed Programming in Java. Distribution (2)

Remote Method Invocation

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

IBD Intergiciels et Bases de Données

Remote Objects and RMI

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

Lecture 5: Object Interaction: RMI and RPC

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

Remote Method Invocation

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

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

CS 5523 Operating Systems: Remote Objects and RMI

Lecture 06: Distributed Object

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

Distributed Computing

RPC and RMI. 2501ICT Nathan

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

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

RMI: Design & Implementation

Remote Method Invocation. Benoît Garbinato

Remote Method Invocation Benoît Garbinato

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

Last Class: Network Overview. Today: Distributed Systems

Written by: Dave Matuszek

Chapter 5 Distributed Objects and Remote Invocation

presentation DAD Distributed Applications Development Cristian Toma

JAVA RMI Java, summer semester

RMI. Remote Method Invocation. 16-Dec-16

Generic architecture

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

Remote Method Invocation in Java

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

5.4. Events and notifications

RMI. (Remote Method Invocation)

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

Distributed Systems COMP 212. Lecture 10 Othon Michail

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

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

Last Class: RPCs. Today:

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Chapter 4 Remote Procedure Calls and Distributed Transactions

Communication and Distributed Processing

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

CHAPTER - 4 REMOTE COMMUNICATION

Programming with RMI Reminder

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

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

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

Last Class: RPCs. Today:

Communication and Distributed Processing

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

Remote Invocation Vladimir Vlassov and Johan Montelius

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

DS 2009: middleware. David Evans

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Distributed Software Systems

Component-Based Software Engineering

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

DISTRIBUTED COMPUTING

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

COMP 6231: Distributed System Design

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

Course Snapshot. The Next Few Classes

Distributed object component middleware I - Java RMI

Distributed object component middleware I - Java RMI

Java Programming Tutorial 1

Chapter 6 Introduction to Defining Classes

CSci Introduction to Distributed Systems. Communication: RPC

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

IJESRT. http: //

RMI Case Study. A Typical RMI Application

Remote Method Invocation R.M.I.


CC755: Distributed and Parallel Systems

Lecture 15: Frameworks for Application-layer Communications

Lecture 15: Frameworks for Application-layer Communications

RMI & RPC. CS 475, Spring 2019 Concurrent & Distributed Systems

416 Distributed Systems. RPC Day 2 Jan 12, 2018

Communication. Distributed Systems Santa Clara University 2016

CORBA (Common Object Request Broker Architecture)

About this exam review

BEAAquaLogic. Service Bus. Interoperability With EJB Transport

Transcription:

Lecture VI: Distributed Objects. Remote Method Invocation CMPT 401 Summer 2007 Dr. Alexandra Fedorova

Remote Method Invocation In an object-oriented language (usually Java) A way to call a method on an object That lives in another process.. Possibly on a different computer Pearson Education 2001 2

Object-Oriented Jargon Buster: Object Real-world objects have: State Behavior Objects in a programming language are similar: Their state is represented by attributes Their behavior is represented by methods 3

Example: Bicycle Object class Bicycle { private int cadence = 0; private int speed = 0; private int gear = 1; attributes Object definition is described in a class void changecadence(int newvalue) { cadence = newvalue; void changegear(int newvalue) { gear = newvalue; void brake(int decrement) { speed = speed - decrement; method 4

Example: Using Bicycle public static void main(){ Bicycle mynewbike = new Bicycle(); mynewbike.changegear(5); Create a new Bicycle object Invoke a method on an object Cannot access private attributes directly mynewbike.gear = 5; //Illegal!!! 5

Object-Oriented Jargon Buster: Interface A definition of methods, Just signatures, no implementation public interface MotorBike{ void kickstart(); void squeezeclutch(); void turnthrottle(int degrees); 6

Implementing the Interface class Bicycle implements MotorBike{... private boolean enginestarted; private boolean clutchleversqueezed; private int throttlesettingdegrees;... public void kickstart(){ enginestarted = true; This class must provide implement methods in this interface some additional variables for the new methods public void squeezeclutch(){ clutchleversqueezed = true; implementation of the interface public void setthrottle(int degrees){ throttlesettingdegrees = degrees; 7

Object-Oriented Jargon Buster: Exceptions A way to handle with errors during execution of a method In C you usually return an error code from a function In Java you throw an exception public interface MotorBike{ void kickstart(); void squeezeclutch(); void turnthrottle(int degrees); void changegear(int gear) throws ClutchNotSqueezedException; new declaration of changegearmethod that may generate an exception 8

Throwing an Exception class Bicycle implements MotorBike{... public void changegear(int newgear) throws ClutchNotSqueezed Exception{ if(!clutchleversqueezed) throw new ClutchNotSqueezedException(); else gear = newgear; new implementation of changegearthat may generate an exception Can t change gears unless clutch is squeezed Create an Exception object that may contain information about the error 9

Catching An Exception As you saw, is a method may throw an exception, this is specified in the method s signature The code calling that method must be written to handle that exception public static void main(){ MotorBike mydirtbike = new MotorBike(); try{ mydirtbike.changegear(5); catch(clutchnotsqueezedexception cnse) { System.out.println( Can t change gears unless you squeeze the clutch! ); wrap code that might throw exception in trycatch clause code that handles the exception 10

A Remote Object Pearson Education 2001 A remote object will advertise and implement a remote interface Remote invocation can only invoke methods in the remote interface 11

A Remote Object in Java extends interface Remote Must declare a remote interface that is the interface that extends the interface Remote Each method in a remote interface must be declared to throw a RemoteException public interface BankAccount extends java.rmi.remote { public void deposit(float amount) throws java.rmi.remoteexception; public void withdraw(float amount) throws OverdrawnException, java.rmi.remoteexception; throws Remote exception public float getbalance() throws java.rmi.remoteexception; 12

A Bird Eye s View of RMI Client program knows the interface Server program implements the interface Client invokes remote methods described by the interface using the RMI system 13

Implementation and Proxy proxy creates location transparency The actual implementation of the interface lives on the server There is a proxy implementation on the client The client invokes the proxy implementation The proxy implementation communicates with the actual implementation and returns the result to the client 14

RMI System Stub and Skeleton Layer: intercepts calls from client and redirects to Remote Reference Layer Remote Reference Layer interpretsrefenerencesto remote objects, knows what to do with them. Passes messages to the Transport Layer Transport Layer sends messages using request-reply protocol 15

Stub and Skeleton Layer Client Server The stub: stub Marshalls call parameters Sends them to the server Unmarshalls return parameters Returns them to the client program skeleton The skeleton: actual implementation Reads the parameters for the method call from the link Makes the call to the remote service implementation object Accepts the return value Writes the return value back to the stub. 16

Remote Reference Layer (RRL) Client RRL: knows if the remote object (still) exists knows where to locate server holding the remote object called by the stub Server RRL: knowsif the local object exists knows where to locate the local implementation calls the skeleton 17

Transport Layer Java Runtime Environment code that enables JVM to run Manages connection between Java Virtual Machines Used over the network and on the local host There is a messaging protocol implemented over TCP/IP 18

Components of the Transport Layer Messaging protocol (e.g., Java Remote Method Protocol JRMP) TCP/IP IIOP BEA Weblogic protocol Ninja RMI protocol UDP/IP Messaging protocol provides at-most-once semantics Any layer can be switched by an alternative: e.g., TCP/IP with UDP/IP Sun and IBM are working on next version of RMI that will use IIOP, the open protocol used in CORBA Bea Weblogicand Ninja RMI use their proprietary messaging protocols 19

Differences in Java 1.2 Stubs and skeletons are not used, invocation is done using Java reflection (we will not discuss it, read about it in the book) In Java 1.1 you could communicate with an object only if it had been previously instantiated on the server In Java 1.2 you can activatea dormant object dynamically. A dormant object could be an object that existed before, then was written to disk, but currently does not exist in the server memory In Java 1.1 you could communicate with only one instance of remote object In Java 1.2 you can communicate with multiple objects via multicast Today we assume the Java 1.1 implementation 20

Local vs. Remote Objects Remote objects are defined using a Remote interface definition Local objects are defined using a Class definition Why is there a difference? A class usually has a constructor, so you can construct an object described by a class in a local memory using the constructor An interface does not have a constructor, which is the right thing for the remote object You should not be able to create a remote object in a local memory, so you are not given a constructor 21

Creation of Remote Object Client remote object reference Server remote object instance Server creates an instance of remote object Client wants to invoke a method on that remote object But first it must obtain a reference to the remote object How does the client obtain the remote reference? 22

Remote Object References Namingand Directory Service [well known DNS name and port] rmiregistry 3. Create a service that listens for invocations on that object Server 1. Create an object instance 2. Export to RMI registry 4. Register object under public name 23

Server Creates and Registers Remote Object import java.rmi.naming; public class BankServer { public BankServer() { try { BankAccountImplimplements BankAccount interface BankAccount b = new BankAccountImpl(); Naming.rebind("rmi://localhost:1099/ BankService", c); catch (Exception e) { System.out.println("Trouble: " + e); Create a BankAccount object Register object under public name public static void main(string args[]) { new CalculatorServer(); 24

Client Obtains Remote Reference public class BankClient { public static void main(string[] args){ try { BankAccount b = (BankAccount) Naming.lookup( "rmi://localhost /BankService"); catch (RemoteException re) {... //handle exception Obtain remote object reference via rmiregistry 25

The Entire RMI Program Written by the programmer BankAccount.java Remote interface BankAccountImpl.java Implementation of remote interface on the server BankServer.java The server that creates an instance of BankAccountImpl and binds it BankClient.java The client that obtainsremote object reference and invokes remote methods on it Generated by rmic compiler (rmic BankAccountImpl.java) BankAccount_Stub.class BankAccount_Skel.class 26

Local vs. Remote Parameter Passing For a local call Primitive types are passed by value -a primitive type variable is copied on the caller s stack Object references are passed by value an object reference (not the entire object) is copied on the caller s stack For a remote call Primitive types are copied to the message sent to the server Entire object, not just the reference is copied All objects referenced by the parameter object are copied too! (Like pointer picking) Java serialization is a format to convert an object and object that it references in a linear form. Objects are serialized before they are passed remotely and deserialized on the other side 27

There s More to RMI System What do you need a web server for? Sometimes a client passes or a server returns an object whose class definition is not available locally In that case, the definition is downloaded from the web server 28

Distributed Garbage Collection In C you have to explicitly deallocatememory that is no longer used In Java, unused objects are garbage collected: local JVM automatically destroys objects that are not referenced by anyone Garbage collection must also work with RMI Java RMI system implements a distributed garbage collector 29

Distributed Garbage Collection (cont) RMI Remote Layer on the server counts the number of remote references to each remote object it exports When there are no more local and remote references to the object, the object is destroyed The client should tell the server when it no longer uses the object But what if it does not? 30

Distributed Garbage Collection (cont) Each remote reference has an associated lease time Client RMI layer must renew the lease on the reference if the reference is still in use on the client When all leases expire, the server can destroy the object Client must be prepared to deal with disappeared objects 31

Is RMI Transparent? 32

RMI is Transparent For remote invocations a programmer uses the same syntax as for local invocations Hides details for argument marshalling/unmarshalling Hides client/server communication details Garbage collection works in a distributed manner 33

RMI is Not Transparent Call invocation semantics Local invocation has exactly-once semantics RMI has at-most-once semantics If RMI had at-least-once semantics, programmer would need to be sure that remote operations are idempotent RMI is subject to partial failures Server, registry or network can fail independently of the client RMI-specific failure mode is exposed to the programmer (must catch RemoteException) Latency of RMI is higher than that of local invocation Should the programmer be allowed to set a timeout or abort an RMI that s taking too long? 34

Is RMI Transparent? The Verdict The syntax (i.e., how you call the method) is transparent The interface is not transparent (extent Remote, throw RemoteException) 35

Shouldn t RMI Be Transparent? Yes, it should be Why burden programmer with the knowledge that the method is remote? Any method can throw an exception. There is no need to distinguish RemoteException No, it should not be RMI is slower than local invocation. A programmer would want to use RMI judiciously A good program shows descriptive error messages to the user. If you hide remoteness, you cannot give descriptive error messages for remote errors A programmer of remote object must guard against concurrent access by multiple clients 36

Summary Java RMI is language-specific abstraction for communication in a distributed system A Java program can invoke a method on an object located in another JVM on another host Remote objects are registered with a global naming service Client can obtain a remote reference by name The syntax of calling a remote method is transparent The interface is not transparent It is considered a bad idea to provide full transparency 37