RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.

Slides:



Advertisements
Similar presentations
What is RMI? Remote Method Invocation –A true distributed computing application interface for Java, written to provide easy access to objects existing.
Advertisements

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.
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.
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.
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
Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology.
Company LOGO Remote Method Invocation Georgi Cholakov, Emil Doychev, University of Plovdiv “Paisii.
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.
RMI1 Remote Method Invocation Slides Adapted from “Core Java 2” by Cay Horstmann, the RMI Tutorial from Sun, and Coulouris text on Distributed Systems.
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.
Java RMI. What is RMI? RMI is an RPC system for an object based language. Objects provide a natural granularity for the binding of functions. –RMI allows.
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
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.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
Internet Software Development Remote Method Invocation Paul Krause.
1 Java Programming II Java Network II (Distributed Objects in Java)
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
+ A Short Java RMI Tutorial Usman Saleem
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.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
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.
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.
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.
Example: RMI Program How to write it.
 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.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Remote Method Invocation with Java-RMI
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
RMI Example. Compilation: /home2/fccheng/temp/RMI2> javac MyObject.java /home2/fccheng/temp/RMI2> javac RemoteServer.java /home2/fccheng/temp/RMI2> javac.
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.
Khoa CNTT 1/37 PHẠM VĂN TÍNH   Java RMI (Remote Method Invocation)
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.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
第十一讲 分布式编程 Socket and RMI 李庆旭. 2 本章内容提要  Socket TCP /IP protocol suit Socket A TCP Server and a TCP Client Supporting Multiple Concurrent Clients A UDP.
Netprog Java RMI1 Remote Method Invocation.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Distributed Objects. Contents I. The Roles of Client and Server II. Remote Method Calls III. The RMI Programming Model IV. Parameters and Return Values.
Distributed Objects and Java RMI
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Lecture 12: Java RMI Distributed Systems
Network and Distributed Programming in Java
Creating a Distributed System with RMI
5. Remote Method Invocation (RMI) 5. 1
Chapter 40 Remote Method Invocation
Creating a Distributed System with RMI
Remote Method Invocation
Creating a Distributed System with RMI
CS 584 Lecture 18 Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday.
Java Remote Method Invocation
Creating a Distributed System with RMI
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann

RMI2 Overview Objects sending requests to one another is the central tenet of OOP. This is typically done within the same virtual machine. Java’s RMI extends this to intranets and the internet.

RMI3 Client Virtual Machine Server Virtual Machine method call with parameters return values and exceptions The roles of client and server only apply to a single method call. It is entirely possible for the roles to be reversed. RMI

4 A Client import java.rmi.*; public class ProductClient { public static void main(String args[]) { System.setSecurityManager( new RMISecurityManager()); String url = "rmi://localhost/";

RMI5 try { Product c1 = (Product)Naming.lookup(url + "toaster"); Product c2 = (Product)Naming.lookup(url + "microwave"); System.out.println(c1.getDescription()); System.out.println(c2.getDescription()); } catch( Exception e) { System.out.println("Error " + e); } System.exit(0); }

RMI6 Notes about the client The default behavior when running a Java application is that no security manager is installed. A Java application can read and write files, open sockets, start print jobs and so on. Applets, on the other hand, immediately install a security manager that is quite restrictive. A security manager may be installed with a call to the static setSecurityManager method in the System class.

RMI7 Notes about the client Any time you load code from another source (as this client is by dynamically downloading the stub class), you need a security manager. By default, the RMISecurityManager restricts all code in the program from establishing network connections. But, this program needs network connections. -- to reach the RMI registry -- to contact the server objects So, Java requires that we write a policy file.

RMI8 Notes about the client The Naming class provides methods for storing and obtaining references to remote objects in the remote object registry. Callers on a remote (or local) host can lookup the remote object by name, obtain its reference, and then invoke remote methods on the object. lookup is a static method of the Naming class that returns a reference to an object that implements the remote interface. Its single parameter contains a URL and the name of the object.

RMI9 Notes about the client The object references c1 and c2 do not actually refer to objects on the server. Instead, these references refer to a stub class that must exist on the client. Product c1 = (Product)Naming.lookup(url + "toaster"); Product c2 = (Product)Naming.lookup(url + "microwave"); The stub class is in charge of object serialization and transmission. it’s the stub object that actually gets called by the client with the line System.out.println(c1.getDescription());

RMI10 File client.policy grant { permission java.net.SocketPermission "*: ", "connect"; }; This policy file allows an application to make any network connection to a port with port number at least (The RMI port is 1099 by default, and the server objects also use ports >= 1024.)

RMI11 Notes About the client When running the client, we must set a system property that describes where we have stored the policy. javac ProductClient.java java –Djava.security.policy=client.policy ProductClient

RMI12 Files on the server Product.java // Product.java import java.rmi.*; public interface Product extends Remote { String getDescription() throws RemoteException; }

RMI13 Notes on Product Interface This interface must reside on both the client and the server. All interfaces for remote objects must extend remote. Each method requires the caller to handle a RemoteException because network problems can occur.

RMI14 Files on the server ProductImpl.java // ProductImpl.java import java.rmi.*; import java.rmi.server.*; public class ProductImpl extends UnicastRemoteObject implements Product { private String name; public ProductImpl(String n) throws RemoteException { name = n; } public String getDescription() throws RemoteException { return "I am a " + name + ". Buy me!"; }

RMI15 Notes on ProductImpl.java This file resides on the server. It is used to automatically generate the stub class that is required by the client. In order to create such a stub class we can use the rmic program on the server: javac ProductImpl.java rmic –v1.2 ProductImpl This creates the file ProductImpl_Stub.class ( skeleton classes are no longer needed in JDK1.2 )

RMI16 Files on the server ProductServer.java // ProductServer.java import java.rmi.*; import java.rmi.server.*; public class ProductServer { public static void main(String args[]) { try { System.out.println("Constructing server implementations..."); ProductImpl p1 = new ProductImpl("Blackwell Toaster"); ProductImpl p2 = new ProductImpl("ZapXpress Microwave");

RMI17 System.out.println("Binding server implementations to registry..."); Naming.rebind("toaster", p1); Naming.rebind("microwave",p2); System.out.println("Waiting for invocations from clients..."); } catch(Exception e) { System.out.println("Error: " + e); }

RMI18 Notes on the ProductServer.java The server program registers objects with the bootstrap registry service, and the client retrieves stubs to those objects. You register a server object by giving the bootstrap registry service a reference to the object and a unique name. ProductImpl p1 = new ProductImpl(“Blackwell Toaster”); Naming.rebind("toaster", p1);

RMI19 Summary of Activities 1.Compile the java files: javac *.java 2.Run rmic on the ProductImpl.class producing the file ProductImpl_Stub.class rmic –v1.2 ProductImpl 3.Start the RMI registry start rmiregistry 4.Start the server start java ProductServer 5.Run the client java –Djava.security.policy=client.policy ProductClient

RMI20 Parameter Passing in Remote Methods When a remote object is passed from the server, the client receives a stub: Product c1 = (Product)Naming.lookup(url + "toaster"); Using the stub, it can manipulate the server object by invoking remote methods. The object, however, remains on the server.

RMI21 Parameter Passing in Remote Methods It is also possible to pass and return any objects via a remote method call, not just those that implement the remote interface. The method call c1.getDescription() returned a full blown String object to the client. This then became the client’s String object. It has been copied via java serialization.

RMI22 Parameter Passing in Remote Methods This differs from local method calls where we pass and return references to objects. To summarize, remote objects are passed across the network as stubs. Nonremote objects are copied. Whenever code calls a remote method, the stub makes a package that contains copies of all parameter values and sends it to the server, using the object serialization mechanism to marshall the parameters.