Java Remote Method Invocation (RMI) ). Distributed Systems  a collection of independent computers that appears to its users as a single coherent system.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

Building Distributed Applications using JAVA - RMI
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.
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.
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.
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)
+ A Short Java RMI Tutorial Usman Saleem
COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye.
Java RMI: Remote Method Invocation January 2000 Nancy McCracken Syracuse University.
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.
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.
Distributed Objects and Middleware. Sockets and Ports Source: G. Coulouris et al., Distributed Systems: Concepts and Design.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 43 Remote Method Invocation.
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.
Java Network Programming Network Programming Spring 2000 Jeffrey E. Care
 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.
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.
Distributed Objects. Contents I. The Roles of Client and Server II. Remote Method Calls III. The RMI Programming Model IV. Parameters and Return Values.
Java Distributed Computing
Java Distributed Computing
Java Remote Method Invocation (RMI)
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Chapter 40 Remote Method Invocation
Overview of RMI Architecture
Chapter 46 Remote Method Invocation
Chapter 46 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) )

Distributed Systems  a collection of independent computers that appears to its users as a single coherent system

Models of Distribution  Message passing  Distributed objects  Event-based architectures  Space-based paradigms

Distributed Object Model  Views a distributed system as a series of interacting objects  Based on some underlying message passing protocol invisible to the programmer  Three main technologies: RMI, CORBA and DCOM

Distributed Object Computing  Enable any object in the local system to directly interact with an object on a remote host  Goals:  Let any object reside anywhere in the network, and allow an application to interact with these objects in the same way as they do with a local object.  Provide the ability to construct an object on one host and transmit it to another host.  Enable an agent on one host to create an object on another host.

What Is RMI?  A mechanism that allows the invocation of a method that exists in another address space  Java-to-Java only  Client-Server Protocol  High-level API  Transparent  Lightweight

Related Technologies  RPC (“Remote Procedure Calls”)  Developed by Sun  Platform-specific  CORBA (“Common Object Request Broker Architecture”)  Developed by OMG  Access to non-Java objects (as well as Java)  DCOM (“Distributed Common Object Model”)  Developed by Microsoft  Access to Win32 objects  LDAP (“Lightweight Directory Access Protocol”)  Finding resources on a network

RMI  Client – the process that invokes a method on a remote object  Server – the process that owns the remote object  Object Registry – a name server that relates objects with names  Objects are registered with the Object Registry, under a unique name.  The Object Registry is used to obtain access to remote objects, using their names.

Remote Objects (Diagram) Java Virtual Machine Client Object Client TCP Java Virtual Machine Remote Object Server

RMI Layers Java Virtual Machine Client Object Stub Remote Reference Layer Transport Layer 11/18/2003 TCP Java Virtual Machine Remote Object Skeleton Remote Reference Layer Transport Layer

RMI Architecture in the OSI model Application Layer Presentation Layer Session Layer Transport Layer Network Layer Data-link layer Physical Layer User Application StubSkeleton Remote Reference Layer TCP IP Hardware Interface Network

Remote Objects  Remote Objects  Live on server Java Virtual Machine Client Object Stub Remote Reference Layer Transport Layer Client Java Virtual Machine Remote Object Skeleton Remote Reference Layer TCP Transport Layer Server  Accessed as if they were local

Stubs and Skeletons  Stub  lives on client Java Virtual Machine Client Object Stub Remote Reference Layer Transport Layer Client Java Virtual Machine Remote Object Skeleton Remote Reference Layer TCP Transport Layer Server  pretends to be remote object - a proxy for the remote object  Skeleton  lives on server  receives requests from stub, talks to the remote object and delivers response to stub  Stubs and skeletons are not written by the programmer! They are generated by a special compiler “rmic”

Stubs and Skeletons  Stub – responsibilities  Initiate remote calls Java Virtual Machine Client Object Stub Remote Reference Layer Transport Layer Client Java Virtual Machine Remote Object Skeleton Remote Reference Layer TCP Transport Layer Server  Marshals arguments to be sent  Informs the remote reference layer that a call should be invoked on the server  Unmarshals a return value (or exception)  Informs the remote reference layer that the call is complete

Stubs and Skeletons  Skeleton – responsibilities Java Virtual Machine Client Object Stub Remote Reference Layer Transport Layer Client Java Virtual Machine Remote Object Skeleton Remote Reference Layer TCP Transport Layer Server  Unmarshals incoming arguments  Calls the actual remote object implementation  Marshals return values for transport to the client  Marshaling – definition  The process of converting native programming language data types to a format suitable for transmission across a network

Remote Interfaces and Stubs Remote Interface implements Remote Object ClientStubSkeleton (Server) 11/18/2003

Remote Interfaces  Declare exposed methods – the methods that can be called from remote locations  Extend java.rmi.Remote  The remote object implements this interface  Act like a proxy for the remote object

Remote Reference Layer Java Virtual Machine Client Object Stub Remote Reference Layer Transport Layer Client Java Virtual Machine Remote Object Skeleton Remote Reference Layer TCP Transport Layer Server  Sets up connections to remote address spaces  Manages connections  Listens for incoming calls  Communicates via TCP/IP

Object Registries  Name and look up remote objects  Remote objects register by name  Clients obtain a remote reference to the remote object  A registry is a running process on the same host as the RMI server

HTTP Tunneling  Cool: if it can’t make the connection normally, it will tunnel through port 80  Allows clients behind firewall to make remote calls to server  Note: does not work server -> client

RMI System Architecture Client Virtual Machine Client Stub Client “Fred” Server Virtual Machine Remote Object Skeleton Server Server Registry Registry Virtual Machine

RMI Flow 1. Server Creates Remote Object 2. Server Registers Remote Object Client Stub “Fred” Server Virtual Machine Remote Object 1 Skeleton Server 2 Registry Virtual Machine

RMI Flow Client Virtual Machine Client Stub 3434 Server Virtual Machine 3. Client requests object from Registry 4. Registry returns remote reference Skeleton Server “Fred” Registry Virtual Machine

RMI Flow Client Virtual Machine Client 5 Stub 6 Server Virtual Machine Remote Object 7 Skeleton Server 5. Client invokes stub method 6. Stub talks to skeleton 7. Skeleton invokes remote object method Registry Virtual Machine

Part II: RMI Usage 11/18/2003and Distributed Programming

Creating Remote Objects  Define a Remote Interface  extends java.rmi.Remote  Define a class that implements the Remote Interface  extends java.rmi.RemoteObject  or java.rmi.UnicastRemoteObject

Remote Interface Example import java.rmi.*; public interface Adder extends Remote { public int add(int x, int y) throws RemoteException; } ECE 451:Introduction to Parallel 11/18/2003

Remote Class Example import java.rmi.*; import java.rmi.server.*; public class AdderImpl extends UnicastRemoteObject implements Adder { public AdderImpl() throws RemoteException { } public int add(int x, int y) throws RemoteException { return x + y; } }

Inheritance Diagram in Java ObjectRemote RemoteObject RemoteStubRemoteServer Unicast RemoteObject

Compiling Remote Classes  Compile the Java class  javac  reads.java file  produces.class file  Compile the Stub and Skeleton  rmic  reads.class file  produces _Skel.class and _Stub.class

Compiling Remote Classes (Diagram) Adder.java (interface) javac Adder.class (interface classfile) javac AdderImpl_Skel.class (skeleton classfile) AdderImpl.java (remote class) AdderImpl.class (classfile) rmic AdderImpl_Stub.class (stub classfile) ECE 451:Introduction to Parallel 11/18/2003and Distributed Programming

Registering Remote Classes  start the registry  running process  Unix: rmiregistry &  Windows: start /m rmiregistry

Registry CLASSPATH  Registry VM needs to be able to find stub file(s)  You must set the CLASSPATH to include the directory containing the stub file  An easy way to check CLASSPATH is to use the javap command, supplying a fully package qualified class name. It uses the current CLASSPATH to find and print the interface to a class.  Or, your server needs to specify the java.rmi.server.codebase System property (more later)

Create the server  Creates a new instance of the remote object  Registers it in the registry with a name  That’s it ECE 451:Introduction to Parallel 11/18/2003and Distributed Programming

RMI Server Example try { AdderImpl adder = new AdderImpl(); Naming.rebind("adder", adder); System.out.println("Adder bound"); } catch (RemoteException re) { re.printStackTrace(); } catch (MalformedURLException me) { me.printStackTrace(); }

Launch the Server % java AdderServer & Adder bound ECE 451:Introduction to Parallel 11/18/2003and Distributed Programming

Server Logging  invoke from command line java -Djava.rmi.server.logCalls=true YourServerImpl  or enable inside program RemoteServer.setLog(System.err);

Creating an RMI Client  Install a Security Manager  to protect from malicious stubs  Find a registry  use java.rmi.Naming  Lookup the name, returns a reference  Cast the reference to the appropriate Remote Interface  Just use it!

RMI URLs rmi:// host [: port ]/ name  default port is 1099  Specifies hostname of registry  can also use relative URLs  name only  assumes registry is on local host

RMI Client Example System.setSecurityManager( new RMISecurityManager()); Adder a = (Adder) Naming.lookup("adder"); int sum = a.add(2,2); System.out.println("2+2=" + sum);

Remote Interfaces vs. Remote Classes  Remember that the reference is to an interface  You must make references, arrays, etc. out of the interface type, not the implementation type  You can’t cast the remote reference to a normal reference  So name your Remote Objects with “Impl” (so you don’t get confused)

Parameter Passing  All parameters are passed by value  Primitive types  passed by value  Objects  passed by value  use Java Object Serialization

Object Serialization  saves the state (data) of a particular instance of an object  serialize - to save  unserialize - to load

Java Serialization  writes object as a sequence of bytes  writes it to a Stream  recreates it on the other end  creates a brand new object with the old data

java.io.Serializable  Objects that implement the java.io.Serializable interface are marked as serializable  Also subclasses  empty interface - just a marker – no need to implement any special methods

RMI Security  Server is untrusted  Stubs could be malicious  rmic is OK, but someone could custom- code an evil stub: it’s just a.class file

RMI Security Managers  AppletSecurityManager  stub can only do what an applet can do  RMISecurityManager  disables all functions except class definition and access  A downloaded class is allowed to make a connection if the connection was initiated via the RMI transport.  None  Stub loading disabled  Stubs still work if they are in local classpath

Limitations of RMI  Java-only  but you can use JNI on the server  Uses TCP, not UDP  At least two sockets per connection  Untested for huge loads

Sun vs. Microsoft  RMI is not shipped as part of Microsoft’s products  RMI will still work in applications  include java.rmi.* class files in your classpath  download rmi.zip from ftp.microsoft.com  RMI will work in applets  include java.rmi.* class files (or rmi.zip) in your codebase  extra download time

RMI Chat Server Objects Message interface MessageReceiver - receiveMessage(Message) ChatClient implements interface ChatServer - login(MessageReceiver) - sendMessage(Message) ChatServerImpl Dispatcher remote reference MessageQueue local reference

Summary  RMI is a very clean API  Easy way to write distributed programs  Wire protocol may need improvement for large-scale problems