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

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

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

JAVA RMI. Remote Method Invocation

Lecture VI: Distributed Objects. Remote Method Invocation

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

Verteilte Systeme (Distributed Systems)

Communication. Overview

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

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

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

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

Remote Invocation. Today. Next time. l Overlay networks and P2P. l Request-reply, RPC, RMI

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

Distributed Information Systems

Remote Procedure Call

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

IPC. Communication. Layered Protocols. Layered Protocols (1) Data Link Layer. Layered Protocols (2)

Distributed Systems. Chapter 02

Communication. Distributed Systems Santa Clara University 2016

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

Programming with RMI Reminder

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

5 Distributed Objects: The Java Approach

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

Overview. Communication types and role of Middleware Remote Procedure Call (RPC) Message Oriented Communication Multicasting 2/36

CSC 634: Networks Programming

Lecture 5: Object Interaction: RMI and RPC

Last Class: RPCs. Today:

Chapter 4 Communication

Today CSCI Communication. Communication in Distributed Systems. Communication in Distributed Systems. Remote Procedure Calls (RPC)

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

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

Distributed Systems. 5. Remote Method Invocation

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

Communication. Communication. Distributed Systems. Networks and protocols Sockets Remote Invocation Messages Streams. Fall /10/2001 DoCS

Remote Method Invocation

#,!" $* ( #+,$ $$ $# -.,$ / 0' ".12 $ $$ 5/ #$" " " $ $ " # $ / 4 * # 6/ 8$8 ' # 6 $! 6$$ #$ * $ $$ ** 4 # 6 # * 0; & *! # #! #(' 7 / $#$ -.

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

Remote Method Invocation

RPC and RMI. 2501ICT Nathan

RMI. (Remote Method Invocation)

CSci Introduction to Distributed Systems. Communication: RPC

Remote Objects and RMI

RMI: Design & Implementation

Distributed Objects SPL/ SPL 201 / 0 1

CHAPTER - 4 REMOTE COMMUNICATION

Remote Invocation. Today. Next time. l Indirect communication. l Request-reply, RPC, RMI

Remote Method Invocation

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

Remote Invocation Vladimir Vlassov and Johan Montelius

Distributed Computing

Course Snapshot. The Next Few Classes

Lecture 06: Distributed Object

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

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

CS 5523 Operating Systems: Remote Objects and RMI

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

Distributed Systems 8. Remote Procedure Calls

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

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Written by: Dave Matuszek

Distributed Systems. How do regular procedure calls work in programming languages? Problems with sockets RPC. Regular procedure calls

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

RMI. Remote Method Invocation. 16-Dec-16

Last Class: Network Overview. Today: Distributed Systems

DISTRIBUTED COMPUTING

Distributed Information Processing

A Report on RMI and RPC Submitted by Sudharshan Reddy B

Remote Method Invocation Benoît Garbinato

Operating Systems. 18. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Spring /20/ Paul Krzyzanowski

Lecture 8: February 17

MODELS OF DISTRIBUTED SYSTEMS

Chapter 5 Distributed Objects and Remote Invocation

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

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

Interprocess Communication

Remote Method Invocation. Benoît Garbinato

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

DS 2009: middleware. David Evans

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

presentation DAD Distributed Applications Development Cristian Toma

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Communication. Layered Protocols. Topics to be covered. Layered Protocols. Introduction

Chapter 3: Client-Server Paradigm and Middleware

Advanced Topics in Distributed Systems. Dr. Ayman A. Abdel-Hamid. Computer Science Department Virginia Tech

Distributed Systems COMP 212. Lecture 8 Othon Michail

Distributed Systems COMP 212. Lecture 10 Othon Michail

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

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

JAVA RMI Java, summer semester

Last Class: RPCs. Today:

Distributed Object-Based Systems The WWW Architecture Web Services Handout 11 Part(a) EECS 591 Farnam Jahanian University of Michigan.

Lecture 8: February 19

Distributed Systems. Edited by. Ghada Ahmed, PhD. Fall (3rd Edition) Maarten van Steen and Tanenbaum

RMI Case Study. A Typical RMI Application

Verteilte Systeme (Distributed Systems)

Chapter 4 Remote Procedure Calls and Distributed Transactions

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

Transcription:

EEC-681/781 Distributed Computing Systems Lecture 4 Department of Electrical and Computer Engineering Cleveland State University wenbing@ieee.org Outline Inter-process communications Computer networks Remote process calls Remote object invocations Case study: Java RMI Material taken from http://java.sun.com/developer/onlinetraining/rmi/rmi.html 2 Inter-Process Communications (IPC) 3 The OSI Network Architecture 4 Techniques: Shared data Message passing Objectives: Data exchange Synchronization: processes at different hosts, executing at different rates, need to influence the overall execution pattern => Constraints on the order of events 1

Low-level Layers 5 Transport Layer 6 Physical layer: contains the specification and implementation of bits, and their transmission between sender and receiver Data link layer: prescribes the transmission of a series of bits into a frame to allow for error and flow control Network layer: describes how packets in a network of computers are to be routed Important: The transport layer provides the actual communication facilities for most distributed systems. Standard Internet protocols: TCP: connection-oriented, reliable, streamoriented communication UDP: unreliable (best-effort) datagram communication Application Layer 7 Middleware Layer 8 Many application protocols are directly implemented on top of transport protocols that do a lot of application-independent work Transfer Encoding Naming Distribution Replication FTP FTP 7-bit text + 8-bit binary Host + path Pull Caching + DNS tricks WWW HTTP 8-bit + content type URL Pull Caching + DNS tricks Middleware is invented to provide common services and protocols that can be used by many different applications: A rich set of communication protocols Marshaling and unmarshaling of data Naming protocols Security protocols Scaling mechanisms What remains are truly application-specific protocols 2

Middleware Protocols 9 Conventional Procedure Call 10 An adapted reference model for networked communication count = read(fd, buf, bytes); Parameter passing in a local procedure call: the stack before the call to read() The stack while the called procedure is active Basic Remote Procedure Call Operation 11 Client and Server Stubs 12 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 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 to 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 3

RPC between Client and Server 13 Steps of a Remote Procedure Call 14 Parameter Passing 15 Passing Value Parameters 16 Parameter marshaling: There s more than just wrapping parameters into a message: 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: How are basic data values represented (integers, floats, characters) How are complex data values represented (arrays, unions) Client and server need to properly interpret messages, transforming them into machine-dependent representations 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 4

Parameter Passing 17 External Data Representation 18 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 A procedure The corresponding message to/from agreed external format External Data Representation 19 CORBA CDR example 20 XDR (RFC 1832), CDR (CORBA), Java: data -> byte stream object references HTTP/MIME: data -> ASCII text 5

Interface Definition Language 21 Parameter Passing 22 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 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 Asynchronous RPC 23 Asynchronous RPC 24 The interconnection between client and server in a traditional RPC The interaction using asynchronous RPC A client and server interacting through two asynchronous RPCs. This scheme is also called deferred synchronous RPC 6

Remote Distributed Objects 25 Distributed Objects 26 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 is responsible for a collection of objects Common organization of a remote object with clientside proxy. Server skeleton handles (un)marshaling and object invocation Client stub (proxy) implements interface Client-to-Object Binding 27 Remote Method Invocation 28 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 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 7

RMI: Parameter Passing 29 RMI: Parameter Passing 30 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 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 Parameter Passing 31 Java RMI Architecture 32 The situation when passing an object by reference or by value 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 8

33 34 Java RMI Architecture Layers Stub and Skeleton Layer 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 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 35 36 Remote Reference Layer Transport 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 The Transport Layer makes network connection between JVMs Java Remote Method Protocol (JRMP): Java RMI s wire protocol (proprietary) on top of TCP/IP 9

RMI Registry 37 Steps to Create a Remote Service 38 RMI Registry (rmiregistry): a simple naming service that comes with Java RMI It runs on each machine that hosts remote service objects and accepts queries for services, by default on port 1099 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://<host_name>[:<name_service_port>]/<service_name> The method returns a remote reference to the service object 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 Using Java RMI 39 Steps to Build a System 40 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 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 10

Service Interface 41 Implementation of Remote Service 42 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 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; Stubs and Skeletons 43 Host Server 44 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 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(); 11

Client 45 Running the RMI System 46 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) ); 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 Parameter Passing in Java RMI 47 Parameter Passing in Java RMI 48 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-byreference? 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 Remote object parameters: pass by reference (proxy) 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 12

Distributed Garbage Collection in Java RMI 49 Java takes care of memory management JVM has an automatic garbage collector that will reclaim the memory from any object that has been discarded by the running program Distribution 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 13