1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.

Slides:



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

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.
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
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)
Algorithm Programming Distributed Programming in Java Bar-Ilan University תשס " ו by Moshe Fresko.
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,
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
ICS 123 Java RMI ICS 123 Richard N. Taylor and Eric M. Dashofy* UC Irvine * with the usual thanks to David Rosenblum.
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.
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.
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.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Presentation: RMI introduction. Goals of this lesson After this 35 min. lesson you will be: Introduced to Java RMI Ready to present RMI’s position in.
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.
Presentation 11: RMI introduction. Ingeniørhøjskolen i Århus Slide 2 af 20 Goals of this lesson After these 2x35 lessons you will be –Introduced to Java.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
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.
RMI Example. Compilation: /home2/fccheng/temp/RMI2> javac MyObject.java /home2/fccheng/temp/RMI2> javac RemoteServer.java /home2/fccheng/temp/RMI2> javac.
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.
Khoa CNTT 1/37 PHẠM VĂN TÍNH   Java RMI (Remote Method Invocation)
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.
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
Principles of Software Development
Java Distributed Computing
Java Remote Method Invocation (RMI)
Broker in practice: Middleware
Remote Method Invocation
Remote Method Invocation
Java RMI (more) CS-328 Internet Programming.
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
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology

2 Overview RMI applications are often comprised of two separate programs: a server and a client. RMI provides the mechanism by which the server and the client communicate and pass information back and forth. Such an application is sometimes referred to as a distributed object application.

2 Distributed object applications Distributed object applications need to Locate remote objects: Communicate with remote objects: Load class bytecodes for objects that are passed around:

2 Distributed object applications Locate remote objects: –An application can register its remote objects with RMI's simple naming facility, the rmiregistry, or –the application can pass and return remote object references as part of its normal operation.

2 Distributed object applications Communicate with remote objects: –Details of communication between remote objects are handled by RMI; –to the programmer, remote communication looks like a standard Java method invocation.

2 Distributed object applications Load class bytecodes for objects that are passed around: –RMI allows a caller to pass objects to remote objects, –RMI provides the necessary mechanisms for loading an object's code, as well as for transmitting its data.

3 RMI 1.bind/rebind 2. lookup 3. call

Creating Distributed Applications 1. Design and implement the components of your distributed application. 2. Compile sources and generate stubs. 3. Make classes network accessible. 4. Start the application.

Creating Distributed Applications 1. Design and implement the application components: Job: decide on your application architecture and determine local objects and remote objects. –Defining the remote interfaces: A remote interface specifies the methods that can be invoked remotely by a client. –Implementing the remote objects: Remote objects must implement one or more remote interfaces.

Creating Distributed Applications 1. Design and implement the application components: –Implementing the clients: Clients that use remote objects can be implemented at any time after the remote interfaces are defined. Clients can be invoked after the remote objects have been deployed.

3 Creating Distributed Applications 2. Compile sources and generate stubs. –use the javac to compile the source files, which contain the implementation of the remote interfaces and implementations, the server classes, and the client classes. –use the rmic to create stubs for the remote objects. –RMI uses a remote object's stub class as a proxy in clients so that clients can communicate with a particular remote object.

3 Creating Distributed Applications 3. Make classes network accessible. –Make the class files associated with the remote interfaces, stubs, and other classes that need to be downloaded to clients accessible via a Web server. 4. Start the application. –Starting the application includes running the RMI remote object registry, the server, and the client

3 Simple RMI Example Client Site: 1. MyObject.java 2. RemoteClient1.java 3. RemoteClient2.java Server Site: 1. RemoteServer.java 2. RemoteInterface.java 3. MyObject.java

3 Writing an RMI Server Our Remote server accepts tasks from clients, runs the tasks, and returns any results. The server is comprised of an interface and a class. The interface provides the definition for the methods that can be called from the client. Essentially the interface defines the client's viewof the remote object. The class provides the implementation.

Designing a Remote Interface The interface provides the definition for the methods that can be called from the client. Client submit a task to Remote server. Result of the task is sent back to the client. Each of the interfaces contains a single method. See RemoteInterface.java Remote Client Remote Client Remote Server Remote Server Submit task Return result

Remote Interface /* RemoteInterface.java */ public interface RemoteInterface extends java.rmi.Remote { MyObject msgsend (MyObject message) throws java.rmi.RemoteException; } The RemoteInterface interface defines a single method, msgsend, which passes in a MyObject and returns a MyObject, and throws RemoteExceptions. See MyObject.java

public class MyObject implements java.io.Serializable { private int x; private String msg; public MyObject (String s) { msg = s; x = msg.length(); } public int lenMsg() { // length of msg return x; } public String getMsg() { // get msg return msg; } public void setMsg(String s) { // set msg msg = s; }

Implement a Remote Interface Declare the remote interfaces being implemented. (UnicastRemoteObject is a convenience class, defined in the RMI public API, that can be used as a superclass for remote object implementations. ) Define the constructor for the remote object Provide an implementation for each remote method in the remote interfaces Create and install a security manager Create one or more instances of a remote object Register at least one of the remote objects with the RMI remote object registry.

import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class RemoteServer extends UnicastRemoteObject implements RemoteInterface{ String name; public RemoteServer(String name) throws RemoteException{ super(); this.name = name; } public MyObject msgsend(MyObject message) throws RemoteException{ System.out.println("msg got:" + message.getMsg() + ", msg length:" + message.lenMsg()); message.setMsg("My Name is:" + name + ",thanks for your message:"+ message.getMsg()); return message; }

public static void main (String args[]){ System.out.println("Running Server..."); System.setSecurityManager (new RMISecurityManager()); try{ String myName = "ObjectServer Test"; RemoteServer theServer = new RemoteServer(myName); Naming.rebind(myName,theServer); } catch (Exception e){ System.out.println("An Exception occured..."); }

Creating A Client Program Remote Client Remote Server RMI Registry Naming.rebind Server.msgsend Naming.lookup

import java.rmi.*; public class RemoteClient1 { public static void main(String args[]) { System.out.println("Running Client 1..."); System.setSecurityManager(new RMISecurityManager()); try { RemoteInterface server = (RemoteInterface) Naming.lookup("rmi://" + args[0] + "/" + "ObjectServer Test"); MyObject msgObj = new MyObject("Hello There From Client1"); System.out.println("Sending MyObject to Server..."); MyObject retObj = server.msgsend(msgObj); System.out.println(”Server says :" + retObj.retMsg()); } catch (Exception e){ System.out.println("Error while performing RMI"); }

Compiling the Example Programs Building interface: javac RemoteInterface.java javac MyObject.java (Note that both Client and Server sites need these) Building Server programs: javac RemoteServer.java rmic RemoteServer (produce RemoteServer_Stub.class and RemoteServer_Skel.class) Building Client programs: javac RemoteClient1.java javac RemoteClient2.java

Running the Example Programs Start the server 1. $rmiregistry (unix) c:>start rmiregistry (Win) A. By default, the registry runs on port B. To start the registry on a different port, specify the port number on the command line. (Ex. $rmiregistry 1089) 2. $java RemoteServer

Running the Example Programs Start the client 1. $java RemoteClient IP-adderss