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.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

What is RMI? Remote Method Invocation –A true distributed computing application interface for Java, written to provide easy access to objects existing.
Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.
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.
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.
DISTRIBUTED FILE SYSTEM USING 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.
1 HANDOUT 14 Remote Method Invocation (RMI) BY GEORGE KOUTSOGIANNAKIS THIS DOCUMENT CAN NOT BE REPRODUCED OR DISTRIBUTED WITHOUT TH E WRITTEN PERMISSION.
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.
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.
CS603 Communication Mechanisms: DCE RPC (cont.) 23 January 2002.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
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.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
Java Remote Method Invocation (RMI) ). Distributed Systems  a collection of independent computers that appears to its users as a single coherent system.
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-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
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.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
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.
Presentation: RMI introduction. Goals of this lesson After this 35 min. lesson you will be: Introduced to Java RMI Ready to present RMI’s position in.
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.
Presentation 11: RMI introduction. Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java.
Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
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)
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.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
Netprog Java RMI1 Remote Method Invocation.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Java Distributed Computing
Chapter 4 Remote Method Invocation
Java Distributed Computing
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Remote method invocation (RMI)
Overview of RMI Architecture
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
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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. –Platform-dependent objects such as file descriptors and sockets cannot be serialized. During an RMI local objects are passed by object copying whereas remote objects are passed by reference. A remote object is built from two different classes: –Server class – implementation of server-side code. –Client class – implementation of a proxy. In Java, a proxy is serializable and is used as a reference to the remote object. –It is possible to marshal a proxy and send it as a series of bytes to another process. –Passing proxies as parameters works because each process is executing in the same Java virtual machine.

Remote Method Invocation (RMI) RMI java.net TCP/IP stack Application network The Java Remote Method Invocation (RMI) system allows an object running in one Java Virtual Machine (VM) to invoke methods on an object running in another Java VM. Java RMI provides applications with transparent andlightweight access to remote objects. RMI defines a high-level protocol and API. Programming distributed applications in Java RMI is simple.  It is a single-language system.  The programmer of a remote object must consider its behavior in a concurrent environment.

Java RMI A Java RMI application is referred to as a distributed object application which needs to: –Locate remote objects: Applications can use one of two mechanisms to obtain references to remote objects. An application can register its remote objects with RMI's simple naming facility, the rmiregistry, or the application can pass and return remote object references as part of its normal operation. –Communicate with remote objects: Details of communication between remote objects are handled by RMI; to the programmer, remote communication looks like a standard Java method invocation. –Load class bytecodes for objects that are passed around: Because RMI allows a caller to pass objects to remote objects, RMI provides the necessary mechanisms for loading an object's code, as well as for transmitting its data.

Java RMI Java RMI extends the Java object model to provide support for distributed objects in the Java language. It allows objects to invoke methods on remote objects using the same syntax as for local invocations. Type checking applies equally to remote invocations as to local ones. The remote invocation is known because RemoteExceptions has been handled and the remote object is implemented using the Remote interface. The semantics of parameter passing is different from the local invocation because the invoker and the target reside on different machines.

RMI Implementation Java Virtual Machine Client Object Java Virtual Machine Remote Object StubSkeleton Client Host Server Host

Remote References and Interfaces Remote References –Refer to remote objects, but can be invoked on a client just like a local object reference Remote Interfaces –Declare exposed methods like an RPC specification –Implemented on the client like a proxy for the remote object

Stubs and Skeletons Client Stub –lives on the client –pretends to be the remote object Sever Skeleton –lives on the server –receives requests from the stub –talks to the true remote object –delivers the response to the stub

Remote Interface Stub Remote Object (Server) ClientSkeleton implements Remote Interface

RMI Implementation Reference Layer – determines if referenced object is local or remote. Transport Layer – packages remote invocations, dispatches messages between stub and skeleton, and handles distributed garbage collection. Both layers reside on top of java.net.

RMI Registry the RMI registry is a simple server-side bootstrap naming facility that allows remote clients to get a reference to a remote object Servers name and register their objects to be accessed remotely with the RMI Registry. Clients use the name to find server objects and obtain a remote reference to those objects from the RMI Registry. A registry (using the rmiregistry command) is a separate process running on the server machine.

Registry RMI Registry Architecture Java Virtual Machine Client Java Virtual Machine Stub Remote Object Skeleton Java Virtual Machine “Bob” Server

Creating Distributed Applications Using RMI Steps to create a RMI application: 1.Design and implement the components of your distributed application. 2.Compile sources and generate stubs. 3.Make classes network accessible. 4.Start the application.

Design and Implement the Application Components This step includes: –Defining the remote interfaces: A remote interface specifies the methods that can be invoked remotely by a client. –Implementing the remote objects: Remote objects must implement one or more remote interfaces. The remote object class may include implementations of other interfaces (either local or remote) and other methods (which are available only locally). If any local classes are to be used as parameters or return values to any of these methods, they must be implemented as well. –Implementing the clients: Clients that use remote objects can be implemented at any time after the remote interfaces are defined, including after the remote objects have been deployed.

Compile Sources and Generate Stubs This step includes: –Use the javac compiler to compile the source files, which contain the implementation of the remote interfaces and implementations, the server classes, and the client classes. –Use the rmic compiler to create stubs for the remote objects. RMI uses a remote object's stub class as a proxy in clients so that clients can communicate with a particular remote object.

Make Classes Network Accessible and Start the Application Make Classes Network Accessible: –In this step you make everything - the class files associated with the remote interfaces, stubs, and other classes that need to be downloaded to clients - accessible via a Web server. Start the Application –Starting the application includes running the RMI remote object registry (rmiregistry), the server, and the client.

Java RMI - Example The files needed for creating a Java RMI application are:  A remote interface defines the remote interface provided by the service. Usually, it is a single line statement specifies the service function (HelloInterface.java). (An interface is the skeleton for a public class.)  A remote object implements the remote service. It contains a constructor and required functions. (Hello.java)  A client that invokes the remote method. (HelloClient.java)  The server offers the remote service, installs a security manager and contacts rmiregistry with an instance of the service under the name of the remote object. (HelloServer.java)

HelloInterface.java import java.rmi.*; public interface HelloInterface extends Remote { public String say(String msg) throws RemoteException; }

Hello.java import java.rmi.*; import java.rmi.server.*; public class Hello extends UnicastRemoteObject implements HelloInterface { private String message; public Hello(String msg) throws RemoteException { message = msg; } public String say(String m) throws RemoteException { // return input message - reversing input and suffixing // our standard message return new StringBuffer(m).reverse().toString() + "\n" + message; }

HelloClient.java import java.rmi.*; public class HelloClient { public static void main(String args[]) { String path = "//localhost/Hello"; try { if (args.length < 1) { System.out.println("usage: java HelloClient... \n"); } else path = "//" + args[0] + "/Hello"; HelloInterface hello = (HelloInterface) Naming.lookup(path); for (int i = 0; i < args.length; ++i) System.out.println(hello.say(args[i])); } catch(Exception e) { System.out.println("HelloClient exception: " + e); }

HelloServer.java import java.rmi.*; import java.rmi.server.*; public class HelloServer { public static void main(String args[]) { // Create and install a security manager if (System.getSecurityManager() == null) System.setSecurityManager(new RMISecurityManager()); try { Naming.rebind("Hello", new Hello("Hello, world!")); System.out.println("server is running..."); } catch (Exception e) { System.out.println("Hello server failed:" + e.getMessage()); }

Steps to Build a RMI application - Example Write the following Java code: Interface - HelloInterface.java Implementation class – Hello.java Client – HelloClient.java Server – HelloServer.java Compile the code javac Hello.java HelloClient.java HelloInterface.java HelloServer.java Generate Stub and Skeleton class files from the implementation classes (make sure that your classpath contains your current directory) rmic Hello

Steps to Build a RMI application - Example Start the RMI registry (in a separate window or in the background) rmiregistry & (be sure to kill this process when you're done) Start the server in one window or in the background with the security policy java -Djava.security.policy=policy HelloServer or without the security policy java HelloServer Run the client in another window java HelloClient testing

Registry RMI Steps Java Virtual Machine Client Java Virtual Machine Stub Remote Object Skeleton Java Virtual Machine “Bob” Server Server creates and registers remote object Client obtains a remote reference from the registry, and a stub is created