Principles of Software Development

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

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.
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.
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.
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.
Architecture of Software Systems RMI and Distributed Components Martin Rehák.
+ 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.
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.
RMI – Command Line CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
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.
RMI - Eclipse CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 43 Remote Method Invocation.
CORBA – Eclipse CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
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.*
 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.
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.
Remote Method Invocation. Introduction What is Remote Method Invocation? Remote method invocation allows objects residing in one JVM execute methods.
Distributed and Parallel Processing George Wells.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Java Distributed Computing
Chapter 5 Remote Procedure Call
Java Distributed Computing
Java Remote Method Invocation (RMI)
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Broker in practice: Middleware
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Chapter 40 Remote Method Invocation
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
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Principles of Software Development RMI CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu

Outline Remote Method Invocation Program USC CSCI 201L

RMI Overview RMI is a Java-implementation of RPC referred to as a distributed object application An RMI server typically creates some remote objects, makes references to those objects accessible, and waits for clients to invoke methods on those objects An RMI client obtains a remote reference to one or more remote objects on a server and invokes methods on them RMI clients can locate remote objects through an RMI registry, assuming the RMI server has registered its remote objects with it The details of remote communication between server and client are handled by RMI Remote communication looks like regular Java method invocations to the programmer The client can pass a class to a remote server and have it execute methods on that class http://docs.oracle.com/javase/tutorial/rmi/overview.html USC CSCI 201L

RMI Application Example Here are the steps for setting up an RMI application 1. Write the code 1.1 Write the remote interface 1.2 Write the server code 1.3 Write the client code 2. Compile the code 3. Start the RMI registry, the server, and the client USC CSCI 201L

RMI Application Example – Step 1.1 Step 1.1 – Write the remote interface The example here allows a client to send an object over that will add up all of the numbers between a minimum value and a maximum value AddNumbersInterface is the remote interface that allows tasks to be submitted to the engine Since AddNumbersInterface inherits from java.rmi.Remote, its method addNumbers(AddNumbersTask) can be invoked remotely AddNumbersTask is the client interface that defines how the server should add the numbers This code physically exists on the client but will be transmitted to the server to execute Objects are passed between the client and server using serialization, so the class implementing the AddNumbersTask interface and the return type must both be Serializable USC CSCI 201L

RMI Application Example – Step 1.1 AddNumbersInterface.java 1 package sharedobjects; 2 import java.rmi.Remote; 3 import java.rmi.RemoteException; 4 5 // this interface is implemented by the server 6 // it should have a method that takes an object that was implemented on the client 7 // that object will have the code in it that will be executed on the server 8 public interface AddNumbersInterface extends Remote { 9 public long addNumbers(AddNumbersTask ant) throws RemoteException; 10 } AddNumbersTask.java 2 3 public interface AddNumbersTask { 4 public long getMinimum(); 5 public long getMaximum(); 6 public long getSum(); 7 } Line 7 is parameterizing the method without parameterizing the interface since the return type is based on the generic that is passed into the method USC CSCI 201L

RMI Application Example – Step 1.2 Step 1.2 – Write the server code A class that implements a remote interface needs to provide an implementation for each remote method in the interface The server program needs to create the remote objects and export them to the RMI runtime, making them available to receive incoming remote invocations Remote objects are passed by reference from a client Other parameters that are not remote objects are passed by value USC CSCI 201L

RMI Application Example – Step 1.2 1 package server; 2 import java.rmi.Remote; 3 import java.rmi.registry.LocateRegistry; 4 import java.rmi.registry.Registry; 5 import java.rmi.server.UnicastRemoteObject; 6 import sharedobjects.AddNumbersInterface; 7 import sharedobjects.AddNumbersTask; 8 9 public class AddNumbersServer implements AddNumbersInterface { 10 public long addNumbers(AddNumbersTask ant) { 11 System.out.println("Adding from " + ant.getMinimum() + " to " + ant.getMaximum() + " on server"); 12 return ant.getSum(); 13 } 14 15 public static void main(String[] args) { 16 try { 17 Registry registry = LocateRegistry.getRegistry(“localhost”); 18 AddNumbersInterface remoteAddNumbers = new AddNumbersServer(); 19 Remote stub = UnicastRemoteObject.exportObject(remoteAddNumbers, 0); 20 registry.rebind(“AddNumbers”, stub); 21 System.out.println("AddNumbers remote object bound"); 22 } catch (RemoteException re) { 23 System.out.println(“RemoteException: “ + re.getMessage()); 24 } 25 } 26 } LocateRegistry.getRegistry(); binds to port 1099, the default RMI port USC CSCI 201L

RMI Application Example – Step 1.3 Step 1.3 – Write the client code The client for this program needs to define the task that it wants the server to perform (AddNumbersCalculation) This means the client needs to create a class that implements the AddNumbersTask interface The client has a standalone program (AddNumbersClient) that will obtain a reference to the newly-created AddNumbersTask object and request it to be executed on the server This means that it needs to contact the RMI registry and submit the AddNumbersTask to be executed by calling the addNumbers(AddNumbersTask) method on an AddNumbersInterface object USC CSCI 201L

RMI Application Example – Step 1.3 1 package client; 2 import java.io.Serializable; 3 import sharedobjects.AddNumbersTask; 4 5 public class AddNumbersCalculation implements AddNumbersTask, Serializable { 6 public static final long serialVersionUID = 1; 7 private long minNum = 0; 8 private long maxNum = 0; 9 10 public AddNumbersCalculation(long minNum, long maxNum) { 11 this.minNum = minNum; 12 this.maxNum = maxNum; 13 } 14 15 public long getMinimum() { 16 return minNum; 17 } 18 19 public long getMaximum() { 20 return maxNum; 21 } 22 23 public long getSum() { 24 long sum = 0; 25 for (long i=minNum; i <= maxNum; i++) { 26 sum += i; 27 } 28 return sum; 29 } 30 } USC CSCI 201L

RMI Application Example – Step 1.3 1 package client; 2 import java.rmi.registry.LocateRegistry; 3 import java.rmi.registry.Registry; 4 import sharedobjects.AddNumbersInterface; 5 import sharedobjects.AddNumbersTask; 6 7 public class AddNumbersClient { 8 public static void main(String args[]) { 9 try { 10 Registry registry = LocateRegistry.getRegistry("localhost"); 11 AddNumbersInterface remoteAddNumbers = (AddNumbersInterface)registry.lookup(“AddNumbers”); 12 AddNumbersTask ant = new AddNumbersCalculation(0, 1_000_000); 13 long solution = remoteAddNumbers.addNumbers(ant); 14 System.out.println(“SUM(0..1,000,000) = “ + solution); 15 } catch (RemoteException re) { 16 System.out.println(“RemoteException: “ + re.getMessage()); 17 } catch (NotBoundException nbe) { 18 System.out.println(“NotBoundException: “ + nbe.getMessage()); 19 } 20 } 21 } USC CSCI 201L

RMI Application Example – Step 2 Step 2 – Compile the code Eclipse will automatically compile the code, so nothing else is required on this step From the command line Compile the shared object and create a jar file with the .class files Include that jar file when compiling the server and client USC CSCI 201L

RMI Application Example – Step 3 Step 3 – Start the RMI registry The RMI registry is executed by running a program that came with the JDK called rmiregistry To run this within Eclipse, go to “Run->External Tools-> External Tools Configuration…” USC CSCI 201L

Eclipse RMI Application Example – Step 3 Step 4 – Start the RMI registry Click the “New Launch Configuration” button and name it “rmiregistry” For the “Location,” click “Browse File System” to find the rmiregistry program in the bin directory of your JRE directory For the “Working Directory,” click “Browse Workspace” to find the bin directory of your project Click “Apply” then “Run” – the RMI registry should be running but there is no output USC CSCI 201L

Eclipse RMI Application Example – Step 3 Step 4 – Start the RMI server application Run the AddNumbersServer program USC CSCI 201L

Eclipse RMI Application Example – Step 3 Step 4 – Start the RMI client application Run the AddNumbersClient program Server output USC CSCI 201L

Outline Remote Method Invocation Program USC CSCI 201L

Program Modify the RMI application we wrote today to use parallel programming to calculate the sum of the values Use the code from the parallel programming lecture but have this code execute on the server through the remote object Compare the actual runtime of the single-threaded version to the parallel version How many values need to be added before the overhead of RMI lessens to make the parallel version faster than the single-threaded version? USC CSCI 201L