EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

1 Communication in Distributed Systems REKs adaptation of Tanenbaums Distributed Systems Chapter 2.
Remote Method Invocation (RMI) Mixing RMI and sockets
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
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 Procedure CallCS-4513, D-Term Remote Procedure Call CS-4513 Distributed Computing Systems (Slides include materials from Operating System.
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
Remote Object 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.
DISTRIBUTED FILE SYSTEM USING RMI
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
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
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)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Communication in Distributed Systems –Part 2
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
EEC-681/781 Distributed Computing Systems Lecture 4 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
1 Java Programming II Java Network II (Distributed Objects in Java)
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W
+ A Short Java RMI Tutorial Usman Saleem
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
15 - RMI. Java RMI Architecture Example Deployment RMI is a part of J2SE (standard edition), but is used by J2EE) A J2EE server is not nessesary for using.
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.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
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.
Silberschatz, Galvin, and Gagne  1999 Applied Operating System Concepts Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote.
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.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Remote Procedure Call RPC
Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Computer Science Lecture 3, page 1 CS677: Distributed OS Last Class: Communication in Distributed Systems Structured or unstructured? Addressing? Blocking/non-blocking?
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 2, 3: Communication 1/30/20161Distributed Systems - COMP 655.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
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.
1 RMI Russell Johnston Communications II. 2 What is RMI? Remote Method Invocation.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
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.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Prof. Leonardo Mostarda University of Camerino
Java Remote Method Invocation (RMI)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Using RMI -The Example of A Remote Calculator
Java Remote Method Invocation
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University

2 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Outline Remote Procedure Call Remote Method Invocation Case study: Java RMI –Material taken from

3 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Conventional Procedure Call Parameter passing in a local procedure call: the stack before the call to read() The stack while the called procedure is active count = read(fd, buf, bytes);

4 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing in Procedure Call Passing by value Passing by reference Read() fd = 10; bytes = 1024; buf = 0x ; count = read(fd, buf, bytes); buffer fd = 10; bytes = 1024; buf = 0x ; 0x

5 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Remote Procedure Call Observations: –Application developers are familiar with simple procedure model –Well-engineered procedures operate in isolation (black box) –There is no fundamental reason not to execute procedures on separate machine Conclusion: communication between caller & callee can be hidden by using procedure-call mechanism

6 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Client and Server Stubs Remote Procedure Call (RPC) achieves distribution transparency by using a client stub and a server stub The client stub provides the interface of the procedure call => illusion of a local call interface –It packs the parameters into a message and requests that message be sent to the server The server stub is a piece of code that transforms requests coming in over the network into local procedure calls

7 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao RPC between Client and Server

8 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Steps of Remote Procedure Call

9 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing for RPC Marshaling: must convert the parameters into a message Marshaling is not trivial: –Client and server machines may have different data representations (think of byte ordering) –Wrapping a parameter means transforming a value into a sequence of bytes –Client and server have to agree on the same encoding –Client and server need to properly interpret messages, transforming them into machine-dependent representations

10 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Passing Value Parameters Original message on the Pentium The message after receipt on the SPARC The message after being inverted. The little numbers in boxes indicate the address of each byte

11 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing A procedure The corresponding message

12 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao External Data Representation Data structures: –“flattened” on transmission –rebuilt upon reception Primitive data types: –Byte order (big-endian: MSB comes first) –ASCII vs UNICODE (2 bytes per character) –Marshalling/unmarshalling To/from agreed external format

13 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao External Data Representation XDR (RFC 1832), CDR (CORBA), Java: –data -> byte stream –object references HTTP/MIME: –data -> ASCII text

14 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao CORBA CDR Example The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1934} 0–3 4–7 8–11 12–15 16– –27 5 "Smit" "h___" 6 "Lond" "on__" 1934 index in sequence of bytes4 bytes notes on representation length of string ‘Smith’ length of string ‘London’ unsigned long

15 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Interface Definition Language In order to allow servers to be accessed by differing clients, Interface Definition Language (IDL) is usually used to allow various platforms to call the RPC –The first popular implementation of RPC on Unix was Sun's RPC, which was used as the basis for NFS From IDL, client and server stubs can be generated automatically to facilitate development

16 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing While passing value parameters is relatively straightforward, passing reference parameters is difficult If we introduce a remote reference mechanism, access transparency can be enhanced: –Remote reference offers unified access to remote data –Remote references can be passed as parameter in RPCs

17 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Asynchronous RPC The interconnection between client and server in a traditional RPC The interaction using asynchronous RPC

18 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Asynchronous RPC A client and server interacting through two asynchronous RPCs. This scheme is also called deferred synchronous RPC

19 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Remote Distributed Objects Data and operations encapsulated in an object Operations are implemented as methods, and are accessible through interfaces Object offers only its interface to clients Object server (or host server) is responsible for a collection of objects Server skeleton handles (un)marshaling and object invocation Client stub (proxy) implements interface

20 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Distributed Objects

21 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Client-to-Object Binding Object reference: denotes server, object, and communication protocol. Having an object reference allows a client to bind to an object: –Client loads associated stub code –Stub is instantiated and initialized for specific object Two ways of binding: –Implicit: Invoke methods directly on the referenced object –Explicit: Client must first explicitly bind to object before invoking it

22 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Remote Method Invocation Steps Client invokes method at stub Stub marshals request and sends it to server Server ensures referenced object is active Request is unmarshaled by object’s skeleton, and referenced method is invoked Result is marshaled and passed back to client Client stub unmarshals reply and passes result to client application

23 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao RMI: Parameter Passing Passing objects by value: A client may pass a complete object as parameter value: –An object has to be marshaled: Marshall its state Marshall its methods, or give a reference to where an implementation can be found –Server unmarshals object. Note that we have now created a copy of the original object

24 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao RMI: Parameter Passing Passing objects by reference: Much easier than in the case of RPC: –One can simply bind to referenced object, and invoke methods –Unbind when referenced object is no longer needed

25 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing Passing an object by reference or by value

26 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Java RMI Architecture Design goal: to create a Java distributed object model that integrates naturally into the Java programming language and the local object model The definition of a remote service is coded using a Java interface The implementation of the remote service is coded in a class Interfaces define behavior and classes define implementation

27 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Java RMI Architecture Layers Stub and Skeleton layer: intercepts method calls made by the client to the interface and redirects these calls to a remote RMI service Remote reference layer: to interpret and manage references made from clients to the remote service objects Transport layer: provides basic connectivity, as well as some firewall penetration strategies Transport Layer Remote Reference Layer Stubs & Skeletons Client ProgramServer Program RMI System

28 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Stub and Skeleton Layer Java RMI follows the Proxy pattern –The stub class plays the role of the proxy –The remote service implementation class plays the role of the RealSubject > Subject Request() RealSubject Request() Proxy Request()

29 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Remote Reference Layer Defines and supports the invocation semantics of the RMI connection –This layer provides a RemoteRef object that represents the link to the remote service implementation object –The stub objects use the invoke() method in RemoteRef to forward the method call –The RemoteRef object understands the invocation semantics for remote services

30 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Transport Layer The Transport Layer makes network connection between JVMs Java Remote Method Protocol (JRMP): Java RMI’s wire protocol (proprietary) on top of TCP/IP

31 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao RMI Registry RMI Registry ( rmiregistry ): a simple naming service that comes with Java RMI –It runs on each machine that hosts remote service objects, by default on port 1099 –It accepts registration request only from the local RMI servers –It accepts queries for services anywhere

32 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao RMI Registry To access the remote server from client side: –Query a registry by invoking the lookup() method on the static Naming class –The method lookup() accepts a URL that specifies the server host name and the name of the desired service rmi:// [: ]/ –The method returns a remote reference to the service object

33 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Steps to Create a Remote Service First create a local object that implements that service Next, export that object to Java RMI. When the object is exported, Java RMI creates a listening service that waits for clients to connect and request the service After exporting, register the object in the Java RMI Registry under a public name

34 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Using Java RMI A working Java RMI system is composed of several parts: –Interface definitions for the remote services –Implementations of the remote services –Stub and Skeleton files –A server to host the remote services –An RMI Naming service that allows clients to find the remote services –A class file provider (an HTTP or FTP server) –A client program that needs the remote services

35 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Steps to Build a System Design your system Write and compile Java code for interfaces Write and compile Java code for implementation classes Generate Stub and Skeleton class files from the implementation classes Write Java code for a remote service host program Develop Java code for Java RMI client program Install and run Java RMI system

36 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Service Interface public interface Calculator extends java.rmi.Remote { public long add(long a, long b) throws java.rmi.RemoteException; public long sub(long a, long b) throws java.rmi.RemoteException; public long mul(long a, long b) throws java.rmi.RemoteException; public long div(long a, long b) throws java.rmi.RemoteException; } To compile it: > javac Calculator.java

37 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Implementation of Remote Service public class CalculatorImpl extends java.rmi.server.UnicastRemoteObject implements Calculator { // Implementations must have an explicit constructor // in order to declare the RemoteException exception public CalculatorImpl() throws java.rmi.RemoteException { super(); } public long add(long a, long b) throws java.rmi.RemoteException { return a + b; } …

38 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Stubs and Skeletons To generate the stub and skeleton files, invoke the RMI compiler, rmic The compiler runs on the remote service implementation class file > rmic CalculatorImpl After you run rmic you should find the file CalculatorImpl_Stub.class

39 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Host Server Remote RMI services must be hosted in a server process import java.rmi.Naming; public class CalculatorServer { public CalculatorServer() { try { Calculator c = new CalculatorImpl(); Naming.rebind(" rmi://localhost:1099/CalculatorService ", c); } catch (Exception e) { System.out.println("Trouble: " + e); } } public static void main(String args[]) { new CalculatorServer(); } }

40 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Client import java.rmi.Naming; import java.rmi.RemoteException; import java.net.MalformedURLException; import java.rmi.NotBoundException; public class CalculatorClient { public static void main(String[] args) { try { Calculator c = (Calculator) Naming.lookup( "rmi://localhost/CalculatorService"); System.out.println( c.sub(4, 3) ); System.out.println( c.add(4, 5) ); System.out.println( c.mul(3, 6) ); System.out.println( c.div(9, 3) ); } …

41 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Running the RMI System Make sure you change to the directory that contains the classes you have written Launch a terminal, start Java RMI registry > rmiregistry Launch another terminal, start the server > java CalculatorServer Launch the 3 rd terminal, start the client > java CalculatorClient

42 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing in Java RMI When Java RMI calls involve passing parameters or accepting a return value –How does RMI transfer these between JVMs? –What semantics are used? –Does RMI support pass-by-value or pass-by- reference?

43 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing in Java RMI Primitive parameters: pass by value –For both input parameter and return type, Java RMI makes a copy of a primitive data type and send it to the destination Object parameters: pass by value –The object to be passed, together with all the objects it references, are serialized and copied over

44 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Parameter Passing in Java RMI Remote object parameters: pass by reference –A client can obtain a reference to a remote object through the Java RMI Registry program –A client can obtain a remote reference as a result of making a remote method call

45 Fall Semester 2006EEC-681: Distributed Computing SystemsWenbing Zhao Distributed Garbage Collection in Java RMI Java takes care of memory management Distributed garbage collection is needed in Java RMI –Many challenges to do so. Most prominent problem is that a client might quit without notice –Solution: lease based. The resource is granted to a client for certain period of time. It is the client’s responsibility to renew the lease. The resource is reclaimed if lease is not renewed