RMI. Remote Method Invocation. 16-Dec-16

Similar documents
Written by: Dave Matuszek

Remote Method Invocation

JAVA RMI. Remote Method Invocation

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Remote Objects and RMI

CS 5523 Operating Systems: Remote Objects and RMI

RMI (Remote Method Invocation) Over the year, there have been 3 different approaches to application development:

Distributed Systems. 5. Remote Method Invocation

Contents. Java RMI. Java RMI. Java RMI system elements. Example application processes/machines Client machine Process/Application A

Remote Method Invocation in Java

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Object Interaction. Object Interaction. Introduction. Object Interaction vs. RPCs (2)

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

5.4. Events and notifications

RMI Example RMI. CmpE 473 Internet Programming RMI

Last Class: Network Overview. Today: Distributed Systems

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414

03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

Distributed Systems. 02r. Java RMI Programming Tutorial. Paul Krzyzanowski TA: Long Zhao Rutgers University Fall 2017

CS193k, Stanford Handout #12. Threads 4 / RMI

RMI. (Remote Method Invocation)

55:182/22C:182. Distributed Application Frameworks Java RMI, CORBA, Web Services (SOAP)

Remote Method Invocation

Chapter 15: Distributed Communication. Sockets Remote Procedure Calls (RPCs) Remote Method Invocation (RMI) CORBA Object Registration

Distributed Computing

RMI Case Study. A Typical RMI Application

RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call

IBD Intergiciels et Bases de Données

JAC444 - Lecture 11. Remote Method Invocation Segment 2 - Develop RMI Application. Jordan Anastasiade Java Programming Language Course

Agent and Object Technology Lab Dipartimento di Ingegneria dell Informazione Università degli Studi di Parma. Distributed and Agent Systems RMI

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Desarrollo de Aplicaciones en Red RMI. Introduction. Considerations. Considerations. RMI architecture

presentation DAD Distributed Applications Development Cristian Toma

How are classes loaded into the Java Virtual Machine (JVM)? from the local file system (CLASSPATH). by an instance of ClassLoader

Generic architecture

Distributed Systems. Distributed Object Systems 2 Java RMI. Java RMI. Example. Applet continued. Applet. slides2.pdf Sep 9,

Distributed Objects SPL/ SPL 201 / 0 1

Communication Basics, RPC & RMI. CS403/534 Distributed Systems Erkay Savas Sabanci University

Course Snapshot. The Next Few Classes. Parallel versus Distributed Systems. Distributed Systems. We have covered all the fundamental OS components:

Distributed Software Systems

Remote Method Invocation Benoît Garbinato

Course Snapshot. The Next Few Classes

Remote Procedure Call

COMP 6231: Distributed System Design

Remote Method Invocation

Department of Computer Science & Engineering. M.Tech(CSE)-I Year-II Semester WEB SERVICES AND SERVICE ORIENTED ARCHITECHTURE (B1513) Mr.K.

Activation of remote objects

Remote Method Invocation. Benoît Garbinato

JAVA RMI Java, summer semester

Distributed Programming with RMI. Overview CORBA DCOM. Prepared By: Shiba R. Tamrakar

Reflection/RMI 4/28/2009

Verteilte Systeme (Distributed Systems)

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Applications. RMI, RPC and events. Request reply protocol External data representation. Operating System

Grid Computing. Java Remote Method Invocation (RMI) RMI Application. Grid Computing Fall 2006 Paul A. Farrell 9/5/2006

1 interface TemperatureSensor extends java.rmi.remote 2 { 3 public double gettemperature() throws java.rmi.remoteexception; 4 public void

Concurrent Object-Oriented Programming

Activation of remote objects

Lab 2 : Java RMI. request sayhello() Hello interface remote object. local object. response "Hello world"

Modulo II Socket, RMI e Corba

Lecture 17 Java Remote Method Invoca/on

Programming with RMI Reminder

Component-Based Software Engineering

A Typical RMI Application

A Typical RMI Application. Case Study

RPC and RMI. 2501ICT Nathan

Chapter 5 Distributed Objects and Remote Invocation

6 Distributed Object-Based Systems

Info 408 Distributed Applications programming 2 nd semester of Credits: 5 Lecturer: Antoun Yaacoub Ph.D.

IJESRT. http: //

Distributed Systems Lecture 2 1. External Data Representation and Marshalling (Sec. 4.3) Request reply protocol (failure modes) (Sec. 4.

Distributed Objects. Chapter Distributing Objects Overview


SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

Distributed Programming in Java. Distribution (2)

Lecture VI: Distributed Objects. Remote Method Invocation

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1

Questions and Answers. A. RMI allows us to invoke a method of java object that executes on another machine.

Chapter 4: Processes. Process Concept. Process State

Distributed object component middleware I - Java RMI

#,!" $* ( #+,$ $$ $# -.,$ / 0' ".12 $ $$ 5/ #$" " " $ $ " # $ / 4 * # 6/ 8$8 ' # 6 $! 6$$ #$ * $ $$ ** 4 # 6 # * 0; & *! # #! #(' 7 / $#$ -.

Distributed object component middleware I - Java RMI

Web. Remote Method Invocation. core. programming. Training Courses: Java, JSP, Servlets, Struts, & JSF:

EAST WEST UNIVERSITY

Java RMI Activation: A running example We have the following classes: MyRemoteInterface: the remote interface. Client: the client that invokes a

Java Technologies. Lecture VII. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

Distributed Systems COMP 212. Lecture 10 Othon Michail

5 Distributed Objects: The Java Approach

Distributed Objects. Remote Method Invokation

Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63.

Lecture 15: Frameworks for Application-layer Communications

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Lecture 15: Frameworks for Application-layer Communications

REMOTE METHOD INVOCATION INTRODUCTION TO RMI, A JAVA API FOR RPC-STYLE INVOCATION OF REMOTE OBJECT METHODS

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák

CSE 124 Distributed programming and Remote Procedure Calls (RPC) February 23, 2016, UCSD Prof. George Porter

Firewall Issues. The possible scenarios: the RMI client, the server, or both can be operating from behind a firewall

Lecture 5: RMI etc. Servant. Java Remote Method Invocation Invocation Semantics Distributed Events CDK: Chapter 5 TVS: Section 8.3

Transcription:

RMI Remote Method Invocation 16-Dec-16

The network is the computer Consider the following program organization: method SomeClass call AnotherClass returned object computer 1 computer 2 If the network is the computer, we ought to be able to put the two classes on different computers RMI is one technology that makes this possible 2

RMI and other technologies CORBA (Common Object Request Broker Architecture) was used for a long time CORBA supports object transmission between virtually any languages Objects have to be described in IDL (Interface Definition Language), which looks a lot like C++ data definitions CORBA is complex and flaky CORBA has fallen out of favor Microsoft supported CORBA, then COM, now.net RMI is purely Java-specific Java to Java communications only As a result, RMI is much simpler than CORBA 3

What is needed for RMI Java makes RMI (Remote Method Invocation) fairly easy, but there are some extra steps To send a message to a remote server object, The client object has to find the object Do this by looking it up in a registry The client object then has to marshal the parameters (prepare them for transmission) Java requires Serializable parameters The server object has to unmarshal its parameters, do its computation, and marshal its response The client object has to unmarshal the response Much of this is done for you by special software 4

Terminology A remote object is an object on another computer The client object is the object making the request (sending a message to the other object) The server object is the object receiving the request As usual, client and server can easily trade roles (each can make requests of the other) The rmiregistry is a special server that looks up objects by name Hopefully, the name is unique! rmic is a special compiler for creating stub (client) and skeleton (server) classes 5

Processes For RMI, you need to be running three processes The Client The Server The Object Registry, rmiregistry, which is like a DNS service for objects You also need TCP/IP active 6

Interfaces Interfaces define behavior Classes define implementation Therefore, In order to use a remote object, the client must know its behavior (interface), but does not need to know its implementation (class) In order to provide an object, the server must know both its interface (behavior) and its class (implementation) In short, The interface must be available to both client and server The class of any transmitted object must be on both client and server The class whose method is being used should only be on the server 7

Classes A Remote class is one whose instances can be accessed remotely On the computer where it is defined, instances of this class can be accessed just like any other object On other computers, the remote object can be accessed via object handles A Serializable class is one whose instances can be marshaled (turned into a linear sequence of bits) Serializable objects can be transmitted from one computer to another It probably isn t a good idea for an object to be both remote and serializable 8

Conditions for serializability If an object is to be serialized: The class must be declared as public The class must implement Serializable However, Serializable does not declare any methods The class must have a no-argument constructor All fields of the class must be serializable: either primitive types or Serializable objects Exception: Fields marked transient will be ignored during serialization 9

Remote interfaces and class A Remote class has two parts: The interface (used by both client and server): Must be public Must extend the interface java.rmi.remote Every method in the interface must declare that it throws java.rmi.remoteexception (other exceptions may also be thrown) The class itself (used only by the server): Must implement the Remote interface Should extend java.rmi.server.unicastremoteobject May have locally accessible methods that are not in its Remote interface 10

Remote vs. Serializable A Remote object lives on another computer (such as the Server) You can send messages to a Remote object and get responses back from the object All you need to know about the Remote object is its interface Remote objects don t pose much of a security issue You can transmit a copy of a Serializable object between computers The receiving object needs to know how the object is implemented; it needs the class as well as the interface There is a way to transmit the class definition Accepting classes does pose a security issue 11

Security It isn t safe for the client to use somebody else s code on some random server System.setSecurityManager(new RMISecurityManager()); The security policy of RMISecurityManager is the same as that of the default SecurityManager Your client program should use a more conservative security manager than the default Most discussions of RMI assume you should do this on both the client and the server Unless your server also acts as a client, it isn t really necessary on the server 12

The server class The class that defines the server object should extend UnicastRemoteObject This makes a connection with exactly one other computer If you must extend some other class, you can use exportobject() instead Sun does not provide a MulticastRemoteObject class The server class needs to register its server object: String url = "rmi://" + host + ":" + port + "/" + objectname; The default port is 1099 Naming.rebind(url, object); Every remotely available method must throw a RemoteException (because connections can fail) Every remotely available method should be synchronized 13

Hello world server: interface import java.rmi.*; public interface HelloInterface extends Remote { public String say() throws RemoteException; 14

Hello world server: class import java.rmi.*; import java.rmi.server.*; public class Hello extends UnicastRemoteObject implements HelloInterface { private String message; // Strings are serializable public Hello (String msg) throws RemoteException { message = msg; public String say() throws RemoteException { return message; 15

Registering the hello world server class HelloServer { public static void main (String[] argv) { try { Naming.rebind("rmi://localhost/HelloServer", new Hello("Hello, world!")); System.out.println("Hello Server is ready."); catch (Exception e) { System.out.println("Hello Server failed: " + e); 16

The hello world client program class HelloClient { public static void main (String[] args) { HelloInterface hello; String name = "rmi://localhost/helloserver"; try { hello = (HelloInterface)Naming.lookup(name); System.out.println(hello.say()); catch (Exception e) { System.out.println("HelloClient exception: " + e); 17

rmic The class that implements the remote object should be compiled as usual Then, it should be compiled with rmic: rmic Hello This will generate files Hello_Stub.class and Hello_Skel.class These classes do the actual communication The Stub class must be copied to the client area The Skel was needed in SDK 1.1 but is no longer necessary 18

Trying RMI In three different terminal windows: 1. Run the registry program: rmiregistry 2. Run the server program: java HelloServer 3. Run the client program: java HelloClient If all goes well, you should get the Hello, World! message 19

Summary 1. Start the registry server, rmiregistry 2. Start the object server 1. The object server registers an object, with a name, with the registry server 3. Start the client 1. The client looks up the object in the registry server 4. The client makes a request 1. The request actually goes to the Stub class 2. The Stub classes on client and server talk to each other 3. The client s Stub class returns the result 20

References Trail: RMI by Ann Wollrath and Jim Waldo http://java.sun.com/docs/books/tutorial/rmi/index.html Fundamentals of RMI Short Course by jguru http://developer.java.sun.com/developer/onlinetraining/ rmi/rmi.html Java RMI Tutorial by Ken Baclawski http://www.eg.bucknell.edu/~cs379/distributedsystems/ rmi_tut.html http://www.cs.rutgers.edu/~pxk/rutgers/notes/pdf/rb-rmi.pdf 21

The End 22