Java Remote Method Invocation

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.
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.
Remote Method Invocation in Java Bennie Lewis EEL 6897.
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
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.
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.
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.
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.
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 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.
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.
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.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
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
Java RMI (more) CS-328 Internet Programming.
Network and Distributed Programming in Java
Creating a Distributed System with RMI
Chapter 40 Remote Method Invocation
Creating a Distributed System with RMI
Remote method invocation (RMI)
Overview of RMI Architecture
Remote Method Invocation
Creating a Distributed System with RMI
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.
Creating a Distributed System with RMI
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Java Remote Method Invocation RMI Java Remote Method Invocation

Java RMI Remote method invocation addresses the incorporation of the network into a programming language, a key issue in network computing. 5/22/2019

RMI Goals Support seamless remote method invocation on objects in different virtual machines. Support callbacks from servers to applets. Integrate the distributed object model into the Java language in a natural way while retaining most of the Java language’s object semantics. Make differences between the distributed object model and local Java object model apparent. Make writing reliable distributed applications as simple as possible. Preserve the safety provided by the Java runtime environment. 5/22/2019

RMI Extended Goals Garbage collection of remote objects Server replication Activation of persistent objects to service an invocation Simple invocation to a single object or invocation to an object replicated at multiple locations. 5/22/2019

JAVA RMI Architecture 5/22/2019

Stubs and Skeletons Client Side Server Side Server Client Stub Network Client m Stub Skeleton m Server 5/22/2019

Tasks of the Stub Initiating a call to the remote object Marshaling arguments to a marshal stream Informing the remote reference layer that the call should be invoked. Unmarshaling the return value or exception from a marshal stream. Informing the remote reference layer that the call is complete. 5/22/2019

Tasks of the Skeleton Unmarshaling arguments from the marshal stream. Making the up-call to the actual remote object implementation Marshaling the return value of the call or an exception (if one occurred) onto the marshal stream. 5/22/2019

How to get Stub/Skeletons? Specify the protocol of the server object Interface definition language: Java Interface has to extend java.rmi.Remote Automatically generate Stub/Skeleton code RMI Compiler 5/22/2019

Parameter Passing in RMI Pass by reference Remote objects implement Remote interface Pass by value (copy) Basic Types Non-remote objects are passed as copies has to implement java.io.Serializable 5/22/2019

Implementing a Remote Interface The class usually extends java.rmi.server.UnicastRemoteObject, thereby inheriting the remote behavior provided by the classes java.rmi.server.RemoteObject and java.rmi.server.RemoteServer. The class can implement any number of remote interfaces. The class can extend another remote implementation class. The class can define methods that do not appear in the remote interface, but those methods can only be used locally and are not available remotely. 5/22/2019

Locating Remote Objects Simple name server provided Server side: BankAccount acct = new BankAcctImpl(); String url = "account"; // bind url to object java.rmi.Naming.bind(url, acct); … Client Side // lookup account acct =(BankAccount) java.rmi.Naming.lookup(“rmi://localhost/account”); 5/22/2019

RMI Registry RMI uses a network-based registry to keep track of the distributed objects. The server object makes a method available for remote invocation by binding itself to a name in the registry. The client object can check for availability of an object by looking up its name in the registry. The registry acts as a limited central management point for RMI. The registry is simply a name repository. It does not address the problem of actually invoking the remote method. 5/22/2019

How RMI works ... When a client invokes a server method, the JVM looks at the stub to do type checking (since the class defined within the stub is an image of the server class). The request is then routed to the skeleton on the server, which in turn calls the appropriate method on the server object. The stub acts as a proxy to the skeleton and the skeleton is a proxy to the actual remote method. 5/22/2019

Sample Application -client package ncworld.rmi1; import java.rmi.*; import java.rmi.server.*; public class Client1 { public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); try {Server1 ro = (Server1) Naming.lookup("doSomething"); System.out.println("Location: ” + System.getProperty("LOCATION")); ro.doSomething(); } catch (Exception e){ e.printStackTrace(); System.exit(-1);} } 5/22/2019

About the Sample-client Client: invokes the doSomething() method of a remote object (of type Server1). All RMI-based applications will need to import java.rmi and java.rmi.server packages. Security manager: grants or denies permissions on the operations performed by the application If you don't set the security manager, RMI will only load classes from local system files as defined by CLASSPATH. 5/22/2019

About the Sample-client ... try/catch block: binds remote object to variable ro (type: Server1) performs the remote method invocation The client can then use ro and invoke its methods as if it was a local object. The client application invokes the doSomething method of the object ro, which in turn invokes the method with the same name on the Server1 object. 5/22/2019

Server interface package ncworld.rmi1; import java.rmi.*; public interface Server1 extends Remote { public void doSomething() throws RemoteException; } 5/22/2019

About the Sample - Server Interface Server1 is used in the client application to declare the remote object type. All remote objects are referenced through interfaces. Two points must be made about the Server1 interface It extends the Remote interface as all RMI interfaces must; and the method doSomething() throws RemoteException which all remote operations must be able to handle. 5/22/2019

Server Implementation (1) package ncworld.rmi1; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class Server1Impl extends java.rmi.server.UnicastRemoteObject implements Server1 { public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); try {Server1Impl obj = new Server1Impl(); Naming.rebind("doSomething", obj); //Naming.bind also possible System.out.println("doSomething bound in registry"); } catch (Exception e) { e.printStackTrace();} } 5/22/2019

Server Implementation (2) public Server1Impl() throws RemoteException { } public void doSomething() throws RemoteException { System.out.println("This message is printed by the Server1 object"); System.out.println("Location: " + System.getProperty("LOCATION")); } 5/22/2019

About the Sample - Server Implementation The Server1Impl class extends the UnicastRemoteObject class. non-replicated remote object whose references are valid only while the server process is alive point-to-point active object references via TCP streams. instantiates an object of type Server1Impl register object using the name doSomething. A remote implementation class must have a zero-argument constructor that may throw RemoteException. Finally, the doSomething method is defined it throws RemoteException. this remote method doesn't really do anything. In a more meaningful application, the remote method may perform a query on a database, or read data from a file and process that data. 5/22/2019

Deployment with JDK We have a client, a server, and an implementation of the server interface. We still need two more pieces -- the stub and the skeleton. JDK 1.1.x up contains tool to generate these rmic rmi1.Server1Impl This will create the two files ServerImpl_Stub.class ServerImpl_Skel.class. Should you want to see the Java source code for these files, use the -keepgenerated option. 5/22/2019

Run with JDK We now have all the necessary pieces for our application. You can open three windows and execute the following commands in a separate window in the order shown below: rmiregistry & java -DLOCATION=server rmi1.Server1Impl java -DLOCATION=client rmi1.Client1 5/22/2019

RMI Summary Language-dependent Passing parameter objects supported Easy to use 5/22/2019