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.

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.
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.
Remote Method Invocation (RMI) Mixing RMI and sockets
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.
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.
Remote Method Invocation
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.
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.
DISTRIBUTED FILE SYSTEM USING RMI
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
1 HANDOUT 14 Remote Method Invocation (RMI) BY GEORGE KOUTSOGIANNAKIS THIS DOCUMENT CAN NOT BE REPRODUCED OR DISTRIBUTED WITHOUT TH E WRITTEN PERMISSION.
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
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.
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
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.
Sun’s Jini Lab 2 Service Registration Client Lookup.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
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.
Silberschatz, Galvin, and Gagne  1999 Applied Operating System Concepts Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote.
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.
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.
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.
Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
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.
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.
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)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Overview of RMI Architecture
Remote Method Invocation
Java Remote Method Invocation
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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 with each other on one JVM why not do the same on several JVM’s? Build on top of the Socket layer Build on top of the Socket layer Break down objects into a string of bytes and send these over the wire Break down objects into a string of bytes and send these over the wire Use Client/Server architecture Use Client/Server architecture

Client/Server Architecture Client requests data from server Client requests data from server Server sends the data to the client (response) Server sends the data to the client (response) Data is exchanged in standard format Data is exchanged in standard format RMI: Remote calls will go in both directions RMI: Remote calls will go in both directions Client Object: is the object one of whose methods issue a remote call Client Object: is the object one of whose methods issue a remote call Remote Object is the object on the server whose method is called Remote Object is the object on the server whose method is called

We need a Proxy Object The client calls a method on a special type of interface that is implemented by the remote object The client calls a method on a special type of interface that is implemented by the remote object Call this interface a stub Call this interface a stub We still have to deal with the parameters and return values, i.e. convert them into an appropriate format We still have to deal with the parameters and return values, i.e. convert them into an appropriate format Call this conversion marshalling Call this conversion marshalling

Marshalling Objects need to be disassembled to this format Objects need to be disassembled to this format Formatted object is sent over the wire Formatted object is sent over the wire Object needs to be reassembled on the other side Object needs to be reassembled on the other side Hence use character format: if the parameter of return value is a primitive type just copy it (as a sequence of bytes) Hence use character format: if the parameter of return value is a primitive type just copy it (as a sequence of bytes) If it is an object then disassemble to a string If it is an object then disassemble to a string Call this last process serialization Call this last process serialization

What is a Stub? It defines a remote interface It defines a remote interface Contains methods that will be eventually called remotely Contains methods that will be eventually called remotely It extends java.rmi.Remote It extends java.rmi.Remote All its methods must throw a java.rmi.RemoteException All its methods must throw a java.rmi.RemoteException

The Stub Produces An identifier of the remote object An identifier of the remote object A description of the method invoked A description of the method invoked Marshalled parameters Marshalled parameters

Server Side There is another interface for the call (now local) that has to unmarshall the parameters and make the actual call with these There is another interface for the call (now local) that has to unmarshall the parameters and make the actual call with these Called a skeleton (not needed by programmer) Called a skeleton (not needed by programmer) Possible return value has to be marshalled and sent back to the client Possible return value has to be marshalled and sent back to the client Note the dynamic nature of marshalled objects must be accomodated Note the dynamic nature of marshalled objects must be accomodated Skeleton resides on the server Skeleton resides on the server

Stubs must be downloaded! From server to client, since it is the remote object’s methods that must be called From server to client, since it is the remote object’s methods that must be called If the client is to know about the stub, then the latter must be registered somewhere If the client is to know about the stub, then the latter must be registered somewhere The client must look the stub up The client must look the stub up The server enters the stub into the registry with Naming.rebind() The server enters the stub into the registry with Naming.rebind() The client looks it up with Naming.lookup() The client looks it up with Naming.lookup()

Naming Lookup Stubs are normally downloaded when the client calls a remote method Stubs are normally downloaded when the client calls a remote method What do you do when there is no remote interface to facilitate downloading? What do you do when there is no remote interface to facilitate downloading? Use the bootstrap registry service the first time round Use the bootstrap registry service the first time round This associates a name (string) to an object on the server. This associates a name (string) to an object on the server.

Naming Lookup (ctd) The server Naming.rebind() accepts a (unique) name--a normal string, say xxx The server Naming.rebind() accepts a (unique) name--a normal string, say xxx The client accesses it by means of a so- called RMI URL, e.g. rmi://localhost:90/xxx The client accesses it by means of a so- called RMI URL, e.g. rmi://localhost:90/xxx This is the argument to Naming.lookup() to obtain the remote reference. This is the argument to Naming.lookup() to obtain the remote reference.

Defining the Remote Interface It extends java.rmi.Remote It extends java.rmi.Remote Must be public Must be public Contains declarations of methods to be called remotely Contains declarations of methods to be called remotely Is the way to pass remote objects Is the way to pass remote objects All methods must declare java.rmi.RemoteException in their throws clause All methods must declare java.rmi.RemoteException in their throws clause

How to Generate Stubs Stubs and skeletons are generated on the server from class files Stubs and skeletons are generated on the server from class files Use the RMI compiler rmic Use the RMI compiler rmic Format: Format: rmic rmic Generates both in same directory as the class file Generates both in same directory as the class file

Naming Conventions Assume the remote interface is called xxx Assume the remote interface is called xxx Then the stub is called xxx_Stub Then the stub is called xxx_Stub The skeleton is called xxx_Skel The skeleton is called xxx_Skel The original class file is called xxxImpl The original class file is called xxxImpl The client’s class is called xxxClient The client’s class is called xxxClient

Write the Implementation Implement the remote interface Implement the remote interface Extend java.rmi.server.UnicastRemoteObject Extend java.rmi.server.UnicastRemoteObject Implement the methods to be called remotely Implement the methods to be called remotely Other medthods may be available only locally Other medthods may be available only locally Constructor must throw a remote exception Constructor must throw a remote exception

UnicastRemoteObject Objects of this type are accessible by the TCP/IP protocol Objects of this type are accessible by the TCP/IP protocol It automatically connects to the RMI runtime system It automatically connects to the RMI runtime system Can perform equality checks with other remote objects Can perform equality checks with other remote objects You can also construct objects of this type with a specific port and,optionally, a SocketFactory on both server and client. You can also construct objects of this type with a specific port and,optionally, a SocketFactory on both server and client.

Set Up the Server Write a java main program Write a java main program Instantiate classes to become remote objects Instantiate classes to become remote objects Put in a Security Manager Put in a Security Manager Bind the remote objects to a name in the registry (more later) Bind the remote objects to a name in the registry (more later)

Set Up a Client Obtain references to remote objects from Naming.lookup() Obtain references to remote objects from Naming.lookup() Call methods on those remote objects Call methods on those remote objects Should set up a Security Manager Should set up a Security Manager

How to Proceed 1. Write the remote interface. This is shared between client and server 2. Write the remote object implementation 3. Write the client application that invokes methods of Compile all programs: javac xxx*.java -d classes javac xxx*.java -d classes 5.Write server program that creates the remote objects

Running Your Program 1. Start the RMI registry: start rmiregistry start rmiregistry 2. Locate classes to make stubs: run rmic 3. Start the server: java -Djava.security.policy = server.policy xxxServer java -Djava.security.policy = server.policy xxxServer 4. Run the client: java -Djava.security.policy = client.policy xxxClient java -Djava.security.policy = client.policy xxxClient