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

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)
What is RMI? Remote Method Invocation –A true distributed computing application interface for Java, written to provide easy access to objects existing.
RMI Varun SainiYing Chen. What is RMI? RMI is the action of invoking a method of a remote interface on a remote object. It is used to develop applications.
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
Remote Method Invocation in Java Bennie Lewis EEL 6897.
Advanced Programming Rabie A. Ramadan Lecture 4. A Simple Use of Java Remote Method Invocation (RMI) 2.
Java Remote Method Invocation (RMI) In Java we implement object systems: O1O2 O3 thread 1thread 2 execution scheme JVM 1JVM 2 distribution scheme.
Remote Method Invocation
FONG CHAN SING (143334) WONG YEW JOON (143388). JAVA RMI is a distributive system programming interface introduced in JDK 1.1. A library that allows an.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Tutorials 2 A programmer can use two approaches when designing a distributed application. Describe what are they? Communication-Oriented Design Begin with.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
Sockets  Defined as an “endpoint for communication.”  Concatenation of IP address + port.  Used for server-client communication.  Server waits for.
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
CSE331: Introduction to Networks and Security Lecture 11 Fall 2002.
CMPT Dr. Alexandra Fedorova Lecture VI: Distributed Objects. Remote Method Invocation.
Introduction to Remote Method Invocation (RMI)
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
Communication in Distributed Systems –Part 2
.NET Mobile Application Development Remote Procedure Call.
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
Programming Languages and Paradigms Object-Oriented Programming.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
1 Java Programming II Java Network II (Distributed Objects in Java)
+ A Short Java RMI Tutorial Usman Saleem
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
11 September 2008CIS 340 # 1 Topics To examine the variety of approaches to handle the middle- interaction (continued) 1.RPC-based systems 2.TP monitors.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
Client Call Back Client Call Back is useful for multiple clients to keep up to date about changes on the server Example: One auction server and several.
Java Remote Method Invocation RMI. Idea If objects communicate with each other on one JVM why not do the same on several JVM’s? If objects communicate.
Remote Method Invocation onlineTraining/rmi/RMI.html.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
CSE 451: Operating Systems Winter 2015 Module 22 Remote Procedure Call (RPC) Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Eric Tryon Brian Clark Christopher McKeowen. System Architecture The architecture can be broken down to three different basic layers Stub/skeleton layer.
Florida State UniversityCOP Advanced Unix Programming Remote Method Invocation /rmi/index.html.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
1 RMI Russell Johnston Communications II. 2 What is RMI? Remote Method Invocation.
Java Distributed Object Model A remote object is one whose methods can be invoked from another JVM on a different host. It implements one or more remote.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Distributed programming in Java Faculty:Nguyen Ngoc Tu Session 5 - RMI.
Netprog Java RMI1 Remote Method Invocation.
Using RMI The Example of A Remote Calculator 1. Parts of A Working RMI System A working RMI system is composed of several parts. –Interface definitions.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Object Interaction: RMI and RPC 1. Overview 2 Distributed applications programming - distributed objects model - RMI, invocation semantics - RPC Products.
Java Remote Method Invocation (RMI)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Programming Models for Distributed Application
CSE 451: Operating Systems Winter 2006 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Winter 2007 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Winter 2004 Module 19 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Using RMI -The Example of A Remote Calculator
Java Remote Method Invocation
CSE 451: Operating Systems Messaging and Remote Procedure Call (RPC)
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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

2 CMPT 401 Summer 2007 © A. 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

3 CMPT 401 Summer 2007 © A. Fedorova 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

4 CMPT 401 Summer 2007 © A. Fedorova Example: Bicycle Object class Bicycle { private int cadence = 0; private int speed = 0; private int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void brake(int decrement) { speed = speed - decrement; } Object definition is described in a class attributes method

5 CMPT 401 Summer 2007 © A. Fedorova 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!!!

6 CMPT 401 Summer 2007 © A. Fedorova Object-Oriented Jargon Buster: Interface public interface MotorBike{ void kickStart(); void squeezeClutch(); void turnThrottle(int degrees); } A definition of methods, Just signatures, no implementation

7 CMPT 401 Summer 2007 © A. Fedorova Implementing the Interface class Bicycle implements MotorBike{... private boolean engineStarted; private boolean clutchLeverSqueezed; private int throttleSettingDegrees;... public void kickStart(){ engineStarted = true; } public void squeezeClutch(){ clutchLeverSqueezed = true; } public void setThrottle(int degrees){ throttleSettingDegrees = degrees; } This class must provide implement methods in this interface some additional variables for the new methods implementation of the interface

8 CMPT 401 Summer 2007 © A. Fedorova 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 changeGear method that may generate an exception

9 CMPT 401 Summer 2007 © A. Fedorova 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 changeGear that may generate an exception Can’t change gears unless clutch is squeezed Create an Exception object that may contain information about the error

10 CMPT 401 Summer 2007 © A. Fedorova 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 try- catch clause code that handles the exception

11 CMPT 401 Summer 2007 © A. Fedorova 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

12 CMPT 401 Summer 2007 © A. Fedorova A Remote Object in Java 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; public float getBalance() throws java.rmi.RemoteException; } extends interface Remote throws Remote exception

13 CMPT 401 Summer 2007 © A. Fedorova 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

14 CMPT 401 Summer 2007 © A. Fedorova Implementation and Proxy 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 proxy creates location transparency

15 CMPT 401 Summer 2007 © A. Fedorova RMI System Stub and Skeleton Layer: intercepts calls from client and redirects to Remote Reference Layer Remote Reference Layer interprets refenerences to remote objects, knows what to do with them. Passes messages to the Transport Layer Transport Layer sends messages using request-reply protocol

16 CMPT 401 Summer 2007 © A. Fedorova Stub and Skeleton Layer The skeleton: –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. ClientServer stub skeleton actual implementation The stub: –Marshalls call parameters –Sends them to the server –Unmarshalls return parameters –Returns them to the client program

17 CMPT 401 Summer 2007 © A. Fedorova 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: –knows if the local object exists –knows where to locate the local implementation –calls the skeleton

18 CMPT 401 Summer 2007 © A. Fedorova Transport Layer Manages connection between Java Virtual Machines Used over the network and on the local host There is a messaging protocol implemented over TCP/IP Java Runtime Environment – code that enables JVM to run

19 CMPT 401 Summer 2007 © A. Fedorova Components of the Transport Layer 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 Weblogic and Ninja RMI use their proprietary messaging protocols TCP/IP Messaging protocol (e.g., Java Remote Method Protocol – JRMP) UDP/IP IIOP BEA Weblogic protocol Ninja RMI protocol

20 CMPT 401 Summer 2007 © A. Fedorova 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 activate a 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

21 CMPT 401 Summer 2007 © A. Fedorova 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

22 CMPT 401 Summer 2007 © A. Fedorova Creation of Remote Object 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? ClientServer remote object instance remote object reference

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

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

25 CMPT 401 Summer 2007 © A. Fedorova 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

26 CMPT 401 Summer 2007 © A. Fedorova 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

27 CMPT 401 Summer 2007 © A. Fedorova 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

28 CMPT 401 Summer 2007 © A. Fedorova 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

29 CMPT 401 Summer 2007 © A. Fedorova Distributed Garbage Collection In C you have to explicitly deallocate memory 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

30 CMPT 401 Summer 2007 © A. Fedorova 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?

31 CMPT 401 Summer 2007 © A. Fedorova 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

32 CMPT 401 Summer 2007 © A. Fedorova Is RMI Transparent?

33 CMPT 401 Summer 2007 © A. Fedorova 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

34 CMPT 401 Summer 2007 © A. Fedorova 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?

35 CMPT 401 Summer 2007 © A. Fedorova 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 )

36 CMPT 401 Summer 2007 © A. Fedorova 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

37 CMPT 401 Summer 2007 © A. Fedorova 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