 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.

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.
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.
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.
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.
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
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.
Practical Issues of RPCCS-4513, D-Term Remote Procedure Call Practical Issues CS-4513 Distributed Computing Systems (Slides include materials from.
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 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.
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.
Presentation: RMI Continued 2 Using The Registry & Callbacks.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
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.
Silberschatz, Galvin, and Gagne  1999 Applied Operating System Concepts Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved TDTS04 Föreläsning.
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.
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.
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.*
Presentation: RMI Continued 2 Using The Registry & Callbacks.
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.
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.
Java Remote Method Invocation (RMI)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Advanced Remote Method Invocations
Knowledge Byte In this section, you will learn about:
Network and Distributed Programming in Java
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Remote Method Invocation
Creating a Distributed System with RMI
Using RMI -The Example of A Remote Calculator
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 Distributed Systems IT332

Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming  Client-Side RMI programming 2

RMI  Consider the following program organization:  RMI is one technology that makes this possible  Allows distributed java objects across the network  General Idea:  Instantiate an object on another machine  Invoke methods on the remote object 3 SomeClass AnotherClass method call returned object computer 1computer 2

RMI and other technologies  CORBA (Common Object Request Broker Architecture)  CORBA supports object transmission between virtually any languages  Objects have to be described in IDL (Interface Definition Language)  CORBA is complex and flaky  RMI is purely Java-specific  Java to Java communications only  As a result, RMI is much simpler than CORBA 4

RMI Architecture 5 rmi registry Server ProgramClient Program RMI Machine Boundary

RMI Components  The RMI application contains the THREE components:  RMI Server: contains objects whose methods are to be called remotely.  RMI Client: gets the reference of one or more remote objects from Registry with the help of object  RMI Registry: is a naming service. RMI server programs use this service to bind the remote java object with the names. Clients executing on local or remote machines retrieve the remote objects by their name registered. 6

Invocation Lifecycle Client Client Code Stub Network Server RMI Object Skeleton Invoke method via stub Serializes arguments, transmit Calls actual method with args Receives, deserialises arguments Returns response / exception Serialises response, transmit Returns response Receives, deserialises response

Steps for Developing an RMI System 1. Define the remote interface 2. Develop the the server program by implementing the remote interface. 3. Develop the client program. 4. Compile the Java source files. 5. Generate the client stubs and server skeletons. 6. Run the RMI registry. 7. Run the remote server objects. 8. Run the client 8

Step 1: Defining the Remote Interface  To create an RMI application, the first step is the defining of a remote interface between the client and server objects. /* SampleServer.java */ import java.rmi.*; public interface SampleServer extends Remote { public int sum(int a,int b) throws RemoteException; }

Step 2: Develop the remote object and its interface  The server is a simple unicast remote server.  Create server by extending java.rmi.server.UnicastRemoteObject.  The server uses the RMISecurityManager to protect its resources while engaging in remote communication. /* SampleServerImpl.java */ import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class SampleServerImpl extends UnicastRemoteObject implements SampleServer { SampleServerImpl() throws RemoteException { super(); }

Step 2: Develop the remote object and its interface  Implement the remote methods  The server must bind its name to the registry, the client will look up the server name.  Use java.rmi.Naming class to bind the server name to registry. In this example the name call “ SAMPLE-SERVER ”.  In the main method of your server object, the RMI security manager is created and installed. /* SampleServerImpl.java */ public int sum(int a,int b) throws RemoteException { return a + b; }

/* SampleServerImpl.java */ public static void main(String args[]) { try { System.setSecurityManager(new RMISecurityManager()); //set the security manager //create a local instance of the object SampleServerImpl Server = new SampleServerImpl(); //put the local instance in the registry Naming.rebind("SAMPLE-SERVER", Server); System.out.println("Server waiting....."); } catch (java.net.MalformedURLException me) { System.out.println("Malformed URL: " + me.toString()); } catch (RemoteException re) { System.out.println("Remote exception: " + re.toString()); } }

Step 3: Develop the client program  In order for the client object to invoke methods on the server, it must first look up the name of server in the registry. You use the java.rmi.Naming class to lookup the server name.  The server name is specified as URL in the from ( rmi://host:port/name )  Default RMI port is  The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name is “ SAMPLE-SERVER ”  The remote method invocation is programmed using the remote interface name ( remoteObject ) as prefix and the remote method name ( sum ) as suffix.

import java.rmi.*; import java.rmi.server.*; public class SampleClient { public static void main(String[] args) { // set the security manager for the client System.setSecurityManager(new RMISecurityManager()); //get the remote object from the registry try { System.out.println("Security Manager loaded"); String url = "//localhost/SAMPLE-SERVER"; SampleServer remoteObject = (SampleServer)Naming.lookup(url); System.out.println("Got remote object"); System.out.println(" = " + remoteObject.sum(1,2) ); } catch (RemoteException exc) { System.out.println("Error in lookup: " + exc.toString()); } catch (java.net.MalformedURLException exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); }

Step 4 & 5: Compile the Java source files & Generate the client stubs and server skeletons  Once the interface is completed, you need to generate stubs and skeleton code. The RMI system provides an RMI compiler ( rmic ) that takes your generated interface class and procedures stub code on its self. > javac SampleServer.java > javac SampleServerImpl.java > rmic SampleServerImpl > javac SampleClient.java

Step 6: Start the RMI registry  The RMI applications need install to Registry. And the Registry must start manual by call rmiregisty.  The rmiregistry us uses port 1099 by default. You can also bind rmiregistry to a different port by indicating the new port number as : rmiregistry > rmiregistry  Remark: On Windows, you have to type in from the command line: > start rmiregistry

Steps 7 & 8: Start the remote server objects & Run the client  Once the Registry is started, the server can be started and will be able to store itself in the Registry. > java SampleServerImpl > java SampleClient

Java Policy File  In Java 2, the java application must first obtain information regarding its privileges. It can obtain the security policy through a policy file. In above example, we allow Java code to have all permissions, the contains of the policy file policy.all is:  Now, we given an example for assigning resource permissions: grant { permission java.io.filePermission “ /tmp/* ”, “ read ”, “ write ” ; permission java.net.SocketPermission “ somehost.somedomain.com:999 ”, ” connect ” ; permission java.net.SocketPermission “ *: ”, ” connect,request ” ; permission java.net.SocketPermission “ *:80 ”, ” connect ” ; }; grant { permission java.security.AllPermission; };

Comment for the Java Policy File 1. Allow the Java code to read/write any files only under the /tmp directory, includes any subdirectories 2. Allow all java classes to establish a network connection with the host “ somehost.somedomain.com ” on port Allows classes to connection to or accept connections on unprivileged ports greater than 1024, on any host 4. Allows all classes to connect to the HTTP port 80 on any host.  You can obtain complete details by following links: spec.doc3.html

References    ut.html ut.html  p.pdf p.pdf 20