CC755: Distributed and Parallel Systems

Similar documents
IBD Intergiciels et Bases de Données

Distributed Programming in Java. Distribution (2)

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

JAVA RMI. Remote Method Invocation

Generic architecture

Lecture 18 Inside Java RMI

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

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

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

Distributed object component middleware I - Java RMI

Distributed object component middleware I - Java RMI

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Remote Method Invocation

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

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

5 Distributed Objects: The Java Approach

Remote Method Invocation

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

Distributed Systems. 5. Remote Method Invocation

Distributed Objects SPL/ SPL 201 / 0 1

Last Class: Network Overview. Today: Distributed Systems

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

5.4. Events and notifications

JAVA RMI Java, summer semester

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

Remote Objects and RMI

RMI Case Study. A Typical RMI Application

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

presentation DAD Distributed Applications Development Cristian Toma

Distributed Applications Programming. Lab 4

Programming with RMI Reminder

Distributed Systems COMP 212. Lecture 10 Othon Michail

Component-Based Software Engineering

Concurrent Programming (RIO) Lesson 9. Ch 8 [BenA 06] Messages Channels Rendezvous RPC and RMI. X=f(..); send X to B. OS kernel.

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

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

Verteilte Systeme (Distributed Systems)

Remote Procedure Call

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

Remote Invocation Vladimir Vlassov and Johan Montelius

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

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

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

Remote Method Invocation R.M.I.

Distributed Systems Project 4 Assigned: Friday March 20 Due: Friday April 3, 11:59pm

Distributed Computing

Concurrency Control in Distributed Environment

RPC and RMI. 2501ICT Nathan

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

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

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

IJESRT. http: //

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

CS 5523 Operating Systems: Remote Objects and RMI

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

ABOUT CORE JAVA COURSE SCOPE:

The Assignment-2 Specification and Marking Criteria

RMI. (Remote Method Invocation)

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

Last Class: RPCs. Today:

Reflection/RMI 4/28/2009

Last Class: RPCs. Today:

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

1 OBJECT-ORIENTED PROGRAMMING 1

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 Method Invocation in Java

COMP 6231 Distributed Systems Design. Tutorial 2 by Alexandre Hudon January 21 st, 2013

Remote Method Invocation

Lecture 17 Java Remote Method Invoca/on

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

Lecture VI: Distributed Objects. Remote Method Invocation

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

Distributed Software Systems

Modulo II Socket, RMI e Corba

RMI Example RMI. CmpE 473 Internet Programming RMI

Chapter 4 Remote Procedure Calls and Distributed Transactions

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák

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

Communication and Distributed Processing

Lecture 5: Object Interaction: RMI and RPC

Written by: Dave Matuszek

Advanced Java Programming

Course Snapshot. The Next Few Classes

Learning Objective. Project Objective

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

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

COMP 6231: Distributed System Design

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Chapter 4: Processes. Process Concept. Process State

Lab 2 : Java RMI. request sayhello() Hello interface remote object. local object. response "Hello world"

RMI. Remote Method Invocation. 16-Dec-16

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

DS 2009: middleware. David Evans

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

Sockets and RMI. CS151 Chris Pollett Dec. 5, 2005.

Developing RMI Based Server (ChatServer)

Advanced Topics in Operating Systems

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

Communication. Distributed Systems Santa Clara University 2016

Transcription:

CC755: Distributed and Parallel Systems Dr. Manal Helal, Spring 2016 moodle.manalhelal.com Lecture 7: Remote Method Invocation (RMI) 1

RMI Y Daniel Liang, Introduction to JAVA Programming, 9th Edition, Prentice Hall, 2013. (http:// www.cs.armstrong.edu/liang/intro9e/) o Chapter 46 in the 9th Edition

Shared Memory Architectures 3

Distributed Memory Architecture 4

RMI Basics RMI is the Java Distributed Object Model for facilitating communications among distributed objects. RMI is a higher-level API built on top of sockets. Socket-level programming allows you to pass data through sockets among computers. RMI enables you not only to pass data among objects on different systems, but also to invoke methods in a remote object. 6 5

The Differences between RMI and RPC RMI is similar to Remote Procedure Calls (RPC) in the sense that both RMI and RPC enable you to invoke methods, but there are some important differences. With RPC, you call a standalone procedure. With RMI, you invoke a method within a specific object. RMI can be viewed as object-oriented RPC. 9 6

The Differences between RMI and Traditional Client/Server Approach A RMI component can act as both a client and a server, depending on the scenario in question. A RMI system can pass functionality from a server to a client and vice versa. A client/server system typically only passes data back and fourth between server and client. 10 7

How does RMI work? An object that resides on the client host and serves as a surrogate for the remote server object. A subinterface of java.rmi.remote that defines the methods for the server object. An object that resides on the server host, communicates with the stub and the actual server object. Client Host Server Host A program that invokes the methods in the remote server object. Server Object Interface Client Program (3) Return Server Stub Server Stub (4) Data Communication RMI Registry Host Server Skeleton Server Object Interface Server Object (1) Register Server Object An instance of the server object interface. (2) Look for Server Object RMI Registry RMI works as follows: (1) A server object is registered with the RMI registry; (2) A client looks through the RMI registry for the remote object; (3) Once the remote object is located, its stub is returned in the client; (4) The remote object can be used in the same way as a local object. The communication between the client and the server is handled through the stub and skeleton. A utility that registers remote objects and provides naming services for locating objects. 11 8

Passing Parameters When a client invokes a remote method with parameters, passing parameters are handled under the cover by the stub and the skeleton. Let us consider three types of parameters: 1. Primitive data type. A parameter of primitive type such as char, int, double, and boolean is passed by value like a local call. 12 9

Passing Parameters, cont. Local object type. A parameter of local object type such as java.lang.string is also passed by value. This is completely different from passing object parameter in a local call. In a local call, an object parameter is passed by reference, which corresponds to the memory address of the object. In a remote call, there is no way to pass the object reference because the address on one machine is meaningless to a different Java VM. Any object can be used as a parameter in a remote call as long as the object is serializable. The stub serializes the object parameter and sends it in a stream across the network. The skeleton deserializes stream into an object. 13 10

Passing Parameters, cont. Remote object type. Remote objects are passed differently from the local objects. When a client invokes a remote method with a parameter of some remote object type, the stub of the remote object is passed. The server receives the stub and manipulates the parameter through the stub. 14 11

RMI Registry How does a client locate the remote object? RMI registry provides the registry services for the server to register the object and for the client to locate the object. You can use several overloaded static getregistry() methods in the LocateRegistry class to return a reference to a Registry. Once a Registry is obtained, you can bind an object with a unique name in the registry using the bind or rebind method or locate an object using the lookup method. java.rmi.registry.locateregistry +getregistry(): Registry +getregistry(port: int): Registry +getregistry(host: String): Registry +getregistry(host:string, port: int): Registry Returns a reference to the remote object Registry for the local host on the default registry port of 1099. Returns a reference to the remote object Registry for the local host on the specified port. Returns a reference to the remote object Registry on the specified host on the default registry port of 1099. Returns a reference to the remote object Registry on the specified host and port. 15 12

RMI Registry: Binding Objects java.rmi.registry.registry +bind(name: String, obj: Remote): void +rebind(name: String, obj: Remote): void +unbind(name: String): void +list(name: String): String[] +lookup(name: String): Remote Binds the specified name with the remote object. Binds the specified name with the remote object. Any existing binding for the name is replaced. Destroys the binding for the specified name that is associated with a remote object. Returns an array of the names bound in the registry. Returns a reference, a stub, for the remote object associated with the specified name. 16 13

Developing RMI Applications 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 17 14

Step 1: Define Server Object Interface 1. Define a server object interface that serves as the contract between the server and its clients, as shown in the following outline: public interface ServerInterface extends Remote { public void service1(...) throws RemoteException; // Other methods } A server object interface must extend the java.rmi.remote interface. 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 18 15

Step 2: Define Server Implementation Object 2. Define a class that implements the server object interface, as shown in the following outline: public class ServerInterfaceImpl extends UnicastRemoteObject implements ServerInterface { public void service1(...) throws RemoteException { // Implement it } // Implement other methods } The server implementation class must extend the java.rmi.server.unicastremoteobject class. The UnicastRemoteObject class provides support for point-to-point active object references using TCP streams. 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 19 16

Step 3: Create and Register Server Object 3. Create a server object from the server implementation class and register it with an RMI registry: ServerInterface server = new ServerInterfaceImpl(...); Registry registry = LocateRegistry.getRegistry(); registry.rebind("remoteobjectname", server); 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 20 17

Step 4: Develop Client Program 4. Develop a client that locates a remote object and invokes its methods, as shown in the following outline: Registry registry = LocateRegistry.getRegistry(host); ServerInterface server = (ServerInterfaceImpl) registry.lookup("remoteobjectname"); server.service1(...); 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 21 18

Example: Retrieving Student Scores from an RMI Server Problem: This example creates a client that retrieves student scores from an RMI server. 22 19

Step 1: Define Server Object Interface 1. Create a server interface named StudentServerInterface. The interface tells the client how to invoke the server's findscore method to retrieve a student score. StudentServerInterface 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 23 20

Step 2: Define Server Implementation Object 2. Create server implementation named StudentServerInterfaceImpl that implements StudentServerInterface. The findscore method returns the score for a specified student. This method returns -1 if the score is not found. StudentServerInterfaceImp 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 24 21

Step 3: Create and Register Server Object 3. Create a server object from the server implementation class and register it with an RMI registry. RegisterWithRMIServer 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 25 22

Step 4: Develop Client Program 4. Create a client as an applet named StudentServerInterfaceClient. The client locates the server object from the RMI registry, uses it to find the scores. StudentServerInterfaceClient 1 Define Server Object Interface 4 Develop Client 2 Define Server Program Implementation Class 3 Create and Register Server Object 26 23

Run Example 1. Start RMI Registry by typing "start rmiregistry" at a DOS prompt from the book directory. By default, the port number 1099 is used by rmiregistry. To use a different port number, simply type the command "start rmiregistry portnumber" at a DOS prompt. On Unix based systems, using a terminal type rmiregistry &. Start RMI 2. Start RegisterWithRMIServer using the following command at C:\book directory: C:\book>java RegisterWithRMIServer Register Object with RMI Registry 3. Run StudentServerInterfaceClient as an application. Run There might be some security setting that need to be fixed. For example: java -Djava.security.manager -Djava.security.policy=/some/path/my.policy RegisterWithRMIServer 27 24

RMI vs. Socket-Level Programming RMI enables you to program at a higher level of abstraction. It hides the details of socket server, socket, connection, and sending or receiving data. It even implements a multithreading server under the hood, whereas with socket-level programming you have to explicitly implement threads for handling multiple clients. RMI applications are scalable and easy to maintain. You can change the RMI server or move it to another machine without modifying the client program except for resetting the URL to locate the server. (To avoid resetting the URL, you can modify the client to pass the URL as a command-line parameter.) In socket-level programming, a client operation to send data requires a server operation to read it. The implementation of client and server at the socket-level is tightly synchronized. RMI clients can directly invoke the server method, whereas socket-level programming is limited to passing values. Socket-level programming is very primitive. Avoid using it to develop client/server applications. As an analogy, socket-level programming is like programming in assembly language, while RMI programming is like programming in a high-level language. 28 25

Developing Three-Tier Applications Using RMI Three-tier applications have gained considerable attention in recent years, largely because of the demand for more scalable and load-balanced systems to replace traditional two-tier client/server database systems. A centralized database system not only handles data access but also processes the business rules on data. Thus, a centralized database is usually heavily loaded because it requires extensive data manipulation and processing. In some situations, data processing is handled by the client and business rules are stored on the client side. It is preferable to use a middle tier as a buffer between a client and the database. The middle tier can be used to apply business logic and rules, and to process data to reduce the load on the database. A three-tier architecture does more than just reduce the processing load on the server. It also provides access to multiple network sites. This is especially useful to Java applets that need to access multiple databases on different servers, since an applet can only connect with the server from which it is downloaded. 29 26

Example: Retrieving Student Scores on a Database Using RMI Problem: This example rewrites the preceding example to find scores stored in a database rather than a hash map. In addition, the system is capable of blocking a client from accessing a student who has not given the university permission to publish his/her score. An RMI component is developed to serve as a middle tier between client and database; it sends a search request to the database, processes the result, and returns an appropriate value to the client. 30 27

RMI Call Backs In a traditional client/server system, a client sends a request to a server, and the server processes the request and returns the result to the client. The server cannot invoke the methods on a client. One of the important benefits of RMI is that it supports callbacks, which enable the server to invoke the methods on the client. With the RMI callback feature, you can develop interactive distributed applications. 31 28

Example: Distributed TicTacToe Using RMI Example 32.7, Distributed TicTacToe Game, was developed using stream socket programming. Write a new distributed TicTacToe game using the RMI. 32 29

Example: Distributed TicTacToe Using RMI TicTacToeInterface CallBack TicTacToeImpl CallBackImpl TicTacToeClientRMI 33 30

Assignment Implement an RMI distributed application for a Math server for two methods: The greatest common divisor (GCD) of two integers using the following code. The greatest common divisor is the largest number which divides both a and b without remainder. public int GCD(int a, int b) { return b==0? a : GCD(b, a%b); } The least common multiple (LCM) of two integers. The least common multiple is the smallest integer which both a and b can divide without remainder, and is given by a*b/gcd(a,b). Submit the source.java files in a zip or jar file (preferably executable jar) as ass4_yourstudentid.jar 31