Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,

Slides:



Advertisements
Similar presentations
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.
Advertisements

Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
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.
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.
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
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
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.
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.
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.
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.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
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 Continued IS Outline  Review of RMI  Programming example.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 43 Remote Method Invocation.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
RMI , Naming Service, Serialization and Internationalization Chapter 4
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 Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
 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.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
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.
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.
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.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Principles of Software Development
Java Remote Method Invocation (RMI)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Java RMI (more) CS-328 Internet Programming.
Creating a Distributed System with RMI
Chapter 40 Remote Method Invocation
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Chapter 46 Remote Method Invocation
Using RMI -The Example of A Remote Calculator
Chapter 46 Remote Method Invocation
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:

Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1, JDK-1.2)

Remote Method Invocation ClientServer Client Remote Object Interface StubSkeleton Remote Object Interface Remote Object Implementation You implement this RMI implements this

Interfaces (Transparency) To client, remote object looks exactly like a local object (except that you must bind to it first). Using interfaces: you write interface for remote object you write implementation for remote object RMI creates stub class (implementing the remote object interface) client accesses stub exactly same way it would access a local copy of the remote object

RMI Registry RMI needs a port mapper too: servers can register contact address information clients can locate servers Called RMI registry You must start it yourself (unlike RPC): needs to be started on every machine that hosts server objects program called rmiregistry runs on port 1099 by default (but you can use ‘rmiregistry ’) Programs can access the registry thanks to java.rmi.Naming class.

Example Simple program: write interface for remote object: Remote.java implementation of object: RemoteImpl.java server to run object: RemoteServer.java client to access object: Client.java RMI compiler ‘rmic’ generates: client stub: RemoteImpl_Stub.class (already compiled) server skeleton: RemoteImpl_Skel.class (already compiled)

Example Step 1: write interface Calculator.java import java.rmi.Remote; import java.rmi.RemoteException; public interface Calculator extends Remote { public long add(long a, long b) throws RemoteException; public long sub(long a, long b) throws RemoteException; public long mul(long a, long b) throws RemoteException; public long div(long a, long b) throws RemoteException; } Few rules: interface must extend java.rmi.Remote interface methods must throw java.rmi.RemoteException exception Compile: $ javac Calculator.java

Example Step 2: write remote object CalculatorImpl.java import java.rmi.server.UnicastRemoteObject; import java.rmi.RemoteException; public class CalculatorImpl extends UnicastRemoteObject implements Calculator { // Implementations must have an explicit constructor public CalculatorImpl() throws RemoteException { super(); } public long add(long a, long b) throws RemoteException { return a + b; } public long sub(long a, long b) throws RemoteException { return a - b; } public long mul(long a, long b) throws RemoteException { return a * b; } public long div(long a, long b) throws RemoteException { return a / b; }

Example Implementation class must respect a few constraints: must implement the interface (of course) must inherit from the java.rmi.server.UnicastRemoteObject class must have explicit constructor which throws the java.rmi.RemoteException exception Compile: $ javac CalculatorImpl.java

Example Step 3: generate stub and skeleton RMI compiler: $ rmic CalculatorImpl Generates CalculatorImpl_Stub.class and CalculatorImpl_Skel.class files. Already compiled.

Example Step 4: write server CalculatorServer.java 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(); }

Example Server program creates CalculatorImpl object. Registers object to local RMI registry (‘rebind()’): rebind(String name, Remote obj) associates a name to an object names are in the form of a URL: rmi:// [:port]/ Server waits for incoming requests $ javac CalculatorServer.java

Example Step 5: write CalculatorClient.java import java.net.MalformedURLException; public class CalculatorClient { public static void main(String[] args) { try { Calculator c = (Calculator) Naming.lookup(“rmi://wizard.cse.nd.edu/CalculatorService”); System.out.println(c.add(4,5)); System.out.println(c.sub(4,3)); } catch (Exception e) { System.out.println(“Received Exception:”); System.out.println(e); }

Example Before invoking the server, the client must ‘lookup’ the registry: must provide the URL for remote service gets back a stub which has exactly the same interface as the server can use it as a local object: long x = c.add(4,5); Compile: $ javac CalculatorClient.java

Example Step 6: test it! Start the RMI registry: rmiregistry registry must have access to your classes either start the registry in the same directory as the classes or make sure directory is listed in $CLASSPATH variable Start server: java CalculatorServer Start client: $ java CalculatorClient 9 1 $

Using RMI in a Distributed Context First, test your program on a single host. To use it on 2 machines: server and rmiregistry need the following files: Calculator.class (server object interface) CalculatorImpl.class (server object implementation) CalculatorImpl_Stub.class (stub) CalculatorServer.class (server program) client needs: Calculator.class (server object interface) CalculatorImpl_Stub.class (stub) CalculatorClient.class (client program) nobody needs the skeleton file CalculatorImpl_Skel.class generated only for compatibility with JDK-1.1

Method Parameters Transfer Base types (int, float, char) are transferred directly. Remote objects (inheriting from java.rmi.Remote) are not transferred: instead, a distributed reference to object is shipped any invocation to this object will result in a RMI request Non-remote objects are serialized and shipped: the object itself plus every other object that it refers to (recursively) remote invocations pass objects by value (local by reference) very easy to transfer huge quantities of data without noticing (you have database in memory and you transfer an object which contains a reference to database)