Internet Software Development Remote Method Invocation Paul Krause.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
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.
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
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.
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
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.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Java RMI RMI = Remote Method Invocation. Allows Java programs to invoke methods of remote objects. Only between Java programs. Several versions (JDK-1.1,
RMI Components java.rmi: client-side RMI classes, interfaces, and exceptions java.rmi.server: server-side RMI classes, interfaces, and exceptions java.rmi.registry:
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.
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.
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.
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
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
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)
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Chapter 4 Remote Method Invocation
Java Remote Method Invocation (RMI)
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Remote method invocation (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:

Internet Software Development Remote Method Invocation Paul Krause

Lecture 10 - RMI  Introduction to RMI  Simple Example - “DivideServer”  Demo of this example  Review a more complex example - “StudentEnrollment”

What is RMI?  A high-level networking technology for distributed Java applications  Allows a Java object executing on one machine to remotely invoke methods in an object executing on a second machine  Such method calls have the appearance of operating on objects in the same program

Skeletons and Stubs Client Stub Java Virtual Machine and RMI System Client Machine C Server Skeleton Java Virtual Machine and RMI System Server Machine S

Stub  Presents same interfaces as remote object  Works with JVM and RMI to serialise arguments in the remote method call  Receives results from the remote method call and returns them to the client object

Skeleton  Receives the remote method call and associated arguments  Works with JVM and RMI to deserialize arguments in the remote method call  Invokes appropriate methods in the remote object  Receives return value (if any) from the method call, serializes it and returns it to the client  No longer needed in Java 2

Referencing remote objects  A Registry object maintains a mapping from Server names to remote object references We will use the example “DivideServer” We will use the example “DivideServer”  The remote object is named via a URL using the RMI protocol: rmi://host:port/server rmi://host:port/server host - IP address or name of server machine host - IP address or name of server machine port - optional port number of the Registry on above port - optional port number of the Registry on above server - name of the remote server server - name of the remote server e.g. rmi:// /DivideServer e.g. rmi:// /DivideServer

Key Classes and Interfaces  Remote Interface  Naming Class  RemoteObject Class  RemoteServer Class  UnicastRemoteObject Class  RemoteException Class

Remote Interface  In the java.rmi package  Contains no constants or methods  It is used to designate which interfaces are remote - remote interfaces must extend java.rmi.Remote remote interfaces must extend java.rmi.Remote remote objects must implement a remote interface remote objects must implement a remote interface

Naming Class  In the java.rmi package  Three methods to associate names with remote objects (used at the Server side): static void bind(String name, Remote robj) static void bind(String name, Remote robj) static void rebind(String name, Remote robj) static void rebind(String name, Remote robj) static void unbind(String name) static void unbind(String name)  One method to obtain a name for a remote object (used at the Client side): static Remote lookup(String url) static Remote lookup(String url)

Remote Objects  RemoteObject extends java.lang.Object to provide correct behaviour for remote objects extends java.lang.Object to provide correct behaviour for remote objects  RemoteServer an abstract class that extends RemoteObject. Defines the methods needed to create and export remote objects an abstract class that extends RemoteObject. Defines the methods needed to create and export remote objects  UnicastRemoteObject a concrete subclass of RemoteServer. Extend this class to make a remote object a concrete subclass of RemoteServer. Extend this class to make a remote object

Simple Client/Server Application  Client program takes three arguments: IP address or name of remote server IP address or name of remote server two numbers two numbers  The two numbers are passed to the server  The server divides one into the other and returns the result  From: JavaBeans Programming from the Ground Up, Joseph O’Neil and Herb Schildt

DivideServer.java import java.rmi.*; public interface DivideServer extends Remote { double divide(double d1, double d2) throws RemoteException;}

Remote Interfaces  The remote interface must extend Remote  Remote methods can throw a RemoteException  We now require a server that implements the interface  By convention, we name the implementation of DivideServer DivideServerImpl DivideServerImpl  Remote objects must extend UnicastRemoteObject

DivideServerImpl.java import java.rmi.*; import java.rmi.server.*; public class DivideServerImpl extends UnicastRemoteObject implements DivideServer { public DivideServerImpl( ) throws RemoteException { } public double divide(double d1, double d2) throws RemoteException { return d1/d2; } }

DivideServerApp.java  This is the main program for the server side  Its primary function is to bind the name “DivideServer” to an instance of DivideServerImpl  Note that we need to start this server program running before the client program is invoked

DivideServerApp.java  Core part is: DivideServerImpl divideServerImpl; divideServerImpl = new DivideServerImpl(); Naming.rebind("DivideServer", divideServerImpl);

DivideServerApp.java import java.net.*; import java.rmi.*; public class DivideServerApp { public static void main(String args[]) { try { try { DivideServerImpl divideServerImpl; divideServerImpl = new DivideServerImpl(); Naming.rebind("DivideServer", divideServerImpl); } catch(Exception ex) { catch(Exception ex) {ex.printStackTrace(); }}}

DivideCleint.java  Looks up the object that is bound to the RMI URL  The lookup method of the Naming class returns an object of type Remote  This must then be cast to a DivideServer in order to be able to access the divide method

DivideCleint.java DivideServer divideServer; divideServer = (DivideServer)Naming.lookup(divideServerURL); // Invoke remote method and display results double result = divideServer.divide(d1, d2); System.out.println("The result is: " + result);

DivideCleint.java import java.rmi.*; public class DivideClient { public static void main(String args[]) { try { try { // Make rmi URL to name DivideServer String divideServerURL; divideServerURL = "rmi://" + args[0] + "/DivideServer"; // Obtain reference to that remote object DivideServer divideServer; divideServer = (DivideServer)Naming.lookup(divideServerURL);

DivideCleint.java // Display numbers System.out.println("The first number is: " + args[1]); double d1 = Double.valueOf(args[1]).doubleValue(); System.out.println("The second number is: " + args[2]); double d2 = Double.valueOf(args[2]).doubleValue(); // Invoke remote method and display results double result = divideServer.divide(d1, d2); System.out.println("The result is: " + result); } catch(Exception ex) { catch(Exception ex) {ex.printStackTrace(); }}}

Executing the Application  Use javac to compile all files  Open a command prompt and change to the working directory  Use the rmic compiler to produce a stub class for the remote server class: rmic -v1.2 DivideServerImpl rmic -v1.2 DivideServerImpl  Copy all files to the client machine exercise: You don’t need all of them on the client. Which ones do you need exercise: You don’t need all of them on the client. Which ones do you need

Executing the Application  open a command prompt on the server and start the RMI registry: rmiregistry rmiregistry  open a second command prompt on the server machine and run the server application to bind the remote server object to the registry java DivideApp java DivideApp  Start the client (again, use a command prompt): java DivideClient server1 8 2 java DivideClient server1 8 2

The result  You should get the following output at the client’s command prompt: The first number is: 8 The second number is: 2 The result is: 4.0  Notes: Use IP address if experimenting on a single machine Use IP address if experimenting on a single machine On Windows 2000 you can find out the IP address of a machine using hostname and ipconfig/all On Windows 2000 you can find out the IP address of a machine using hostname and ipconfig/all