Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University.

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.
1 Chapter 9 Network Programming. 2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes.
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.
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
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.
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,
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 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.
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.
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.
1 RMI Russell Johnston Communications II. 2 What is RMI? Remote Method Invocation.
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.
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.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
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.
Chapter 40 Remote Method Invocation
Overview of RMI Architecture
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
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Remote Method Invocation CS587x Lecture Department of Computer Science Iowa State University

Introduction of RMI What is Remote Method Invocation? Bulb Server public class LightBulb { private boolean lightOn; public void on() { lightOn = true; } public void off() { lightOn = false; } public boolean isOn() { return lightOn; } client Bulb.on() client Bulb.off() Bulb is a remote object

Introduction of RMI What is Remote Method Invocation? Bulb Server public class LightBulb { private boolean lightOn; public void on() { lightOn = true; } public void off() { lightOn = false; } public boolean isOn() { return lightOn; } client Bulb.on() client Bulb.off() Bulb is a remote object 1.How to identify a remote object and its methods? 2.How to invoke a method of a remote object (e.g., parameters passing, result returning)? 3.How to locate a remote object?

Introduction of RMI Primary goal of RMI Allow programmers to develop distributed Java programs with the same syntax and semantic used for non-distributed programs RMI vs. RPC RMI is for Java only, allowing Java objects on different JVM to communicate each other RMI is object-oriented  Input parameters could be objects These objects could be executed in a remote host  Return value could be an object as well

RMI Architecture Each remote object has two separate parts Definition of its behavior  Clients are concerned about the definition of a service  Coded using a Java interface, which defines the behavior Implementation of its behavior  Servers are focused on providing the service  Coded using a Java class, which defines the implementation

RMI Layers Stubs Remote Reference Layer Skeletons Remote Reference Layer Transport Layer (TCP/IP) RMI System Client CodeServer Code Each remote object has two interfaces Client interface – a stub/proxy of the object Server interface – a skeleton of the object The communication of stub and skeleton is done across the RMI link Read parameters/make call/accept return/write return back to the stub Remote reference layer defines and supports the invocation semantics of the RMI connection

Java Application C RPC Implementation GetLocalTime(time, valid) GetLocalOS(OS, valid) BaseStruct Send/Recv() TCP/UDP Socket Send/Recv() Call the RPC implementation GetLocalOSRPC_n Stubs Remote Reference Layer Skeletons Remote Reference Layer Transport Layer (TCP/IP) RMI Client CodeServer Code :: J2C

RMI Components RMI registry Each remote object needs to register their location RMI clients find remote objects via the lookup service Server hosting a remote object Construct an implementation of the object Provide access to methods via skeleton Register the object to the RMI registry Client using a remote object Ask registry for location of the object Construct stub Call methods via the object’s stub RMIRegistry clientserver 1.register server objects 2. look for server object 3. call and data communication 3. return server stub

Steps of Using RMI 1. Create Service Interface 2. Implement Service Interface 3. Create Stub and Skeleton Classes 4. Create RMI Server 5. Create RMI Client 1. Define Service Interface 2. Develop Service Implementation 4. Create and register Server Object 3. rmic 5. Develop Client program stubskeleton

1. Defining RMI Service Interface Declare an Interface that extends java.rmi.Remote Stub, skeleton, and implementation will implement this interface Client will access methods declared in the interface Example public interface RMILightBulb extends java.rmi.Remote { public void on () throws java.rmi.RemoteException; public void off() throws java.rmi.RemoteException; public boolean isOn() throws java.rmi.RemoteException; }

2. Implementing RMI Service Interface Provide concrete implementation for each methods defined in the interface public class RMILightBulbImpl extends java.rmi.server.UnicastRemoteObject implements RMILightBulb { public RMILightBulbImpl() throws java.rmi.RemoteException {setBulb(false);} private boolean lightOn; public void on() throws java.rmi.RemoteException { setBulb(true); } public void off() throws java.rmi.RemoteException {setBulb(false);} public boolean isOn() throws java.rmi.RemoteException {return getBulb(); } public void setBulb (boolean value) { lightOn = value; } public boolean getBulb () { return lightOn; } }

3. Generating Stub & Skeleton Classes Simply run the rmic command on the implementation class Example: rmic RMILightBulbImpl creates the classes:  RMILightBulbImpl_Stub.class Client stub  RMILightBulbImpl_Skeleton.class Server skeleton

4. Creating RMI Server Create an instance of the service implementation Register with the RMI registry (binding) import java.rmi.*; import java.rmi.server.*; public class LightBulbServer { public static void main(String args[]) { try { RMILightBulbImpl bulbService = new RMILightBulbImpl(); RemoteRef location = bulbService.getRef(); System.out.println (location.remoteToString()); String registry = "localhost"; if (args.length >=1) { registry = args[0]; } String registration = "rmi://" + registry + "/RMILightBulb"; Naming.rebind( registration, bulbService ); } catch (Exception e) { System.err.println ("Error - " + e); } } }

5. Creating RMI Client Obtain a reference to the remote interface Invoke desired methods on the reference import java.rmi.*; public class LightBulbClient { public static void main(String args[]) { try { String registry = "localhost"; if (args.length >=1) { registry = args[0]; } String registration = "rmi://" + registry + "/RMILightBulb"; Remote remoteService = Naming.lookup ( registration ); RMILightBulb bulbService = (RMILightBulb) remoteService; bulbService.on(); System.out.println ("Bulb state : " + bulbService.isOn() ); System.out.println ("Invoking bulbservice.off()"); bulbService.off(); System.out.println ("Bulb state : " + bulbService.isOn() ); } catch (NotBoundException nbe) { System.out.println ("No light bulb service available in registry!"); } catch (RemoteException re) { System.out.println ("RMI - " + re); } catch (Exception e) { System.out.println ("Error - " + e); } }

Steps of Running RMI Make the classes available in the server host's, registry host's, and client host's classpath Copy, if necessary Start the registry rmiregistry Start the server java LightBulbServer reg-hostname Start the client java LightBulbClient reg-hostname

Another Example: Compute Server Task Server Client An Example of Corporate Server Task Result result task

Task interface public interface Task { Object run(); } When run is invoked, it does some computation and returns an object that contains the results

Remote Interface of ComputeServer import java.rmi.* public interface ComputeServer extends Remote { Object compute(Task task) throws RemoteException; } The only purpose of this remote interface is to allow a client to create a task object and send it to the Server for execution, returning the results

Remote Object ComputeServerImpl import java.rmi.*; Import java.rmi.server.*; public class ComputeServerImpl extends UnicastRemoteObject implements ComputeServer { public ComputeServerImpl() throws RemoteException { } public Object compute(Task task) { return task.run(); } public static void main(String[] args) throws Exception { ComputeServerImpl server = new ComputeServerImpl(); Naming.rebind(“ComputeServer”, server); }

A Task Example public class MyTask implements Task, Serializable { double data[]; MyTask() { ReadFile(data, “c:\data.txt”); } double run() { // some CPU-intensive operations on data[]; }

Submitting a Task public class RunTask { public static void main(String[] args) throws Exception { Mytask myTask = new MyTask(); // set the data[] of myTask; // submit to the remote compute server and get result back Remote cs = Naming.lookup(“rmi://localhost/ComputeServer”); Double result = (ComputeServer) cs).compute(myTask); }

RMI Safety and Security RMISecurityManager imposes restrictions on downloaded objects the same on applets No access to local disk I/O No socket connection except to codebase, etc. public static void main(String[] args) throws Exception { System.setSecurityManager(new RMISecurityManager()); ComputeServerImpl server = new ComputeServerImpl(); Naming.rebind(“ComputeServer”, server); return; }

Firewalls Firewalls block all network traffic, with the exception of those intended for certain “well-known” ports RMI traffic is typically blocked by firewall RMI transport layer opens dynamic socket connections between the client and the server to facilitate communication Client Stub Firewalls WWW Server

RMI Solutions The sequence of trying to make connections: Communicate directly to the server’s port using sockets If this fails, build a URL to the server’s host and port and use an HTTP post request on that URL, sending the information to the skeleton as the body of the POST. need to set system property http.proxyhost If this also fails, build a URL to the server’s host using port 80, the standard HTTP port, using a CGI script that will forward the posted RMI request to the server. java-rmi.cgi script needs to be install java.rmi.server.hostname = host.domain.com A more efficient solution is using servlet If all fails, RMI fails.

Summary RMI is a Java middleware to deal with remote objects based on RPC communication protocol Interface defines behaviour and class defines implementation Remote objects are pass across the network as stubs and nonremote objects are copies RMI will not replace CORBA since a JAVA client may require to interact with a C/C++ server RMI fits well in n-tier architectures since it can intermix easily with servlets