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

Similar documents
JAVA RMI Java, summer semester

RMI. (Remote Method Invocation)

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

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

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

presentation DAD Distributed Applications Development Cristian Toma

5 Distributed Objects: The Java Approach

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

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

Remote Method Invocation in Java

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

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

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

Verteilte Systeme (Distributed Systems)

Remote Procedure Call

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

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

Remote Method Invocation

Distributed Systems. The main method of distributed object communication is with remote method invocation

Distributed Programming in Java. Distribution (2)

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

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

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

RPC and RMI. 2501ICT Nathan

Remote Method Invocation Benoît Garbinato

Remote Method Invocation. Benoît Garbinato

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

Java and Distributed Systems

5.4. Events and notifications

THE RMI PROXY USER GUIDE

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

RMI Case Study. A Typical RMI Application

RMI: Design & Implementation

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

Remote Method Invocation

Remote Objects and RMI

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

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

Programming with RMI Reminder

CS 5523 Operating Systems: Remote Objects and RMI

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Distributed Systems. 5. Remote Method Invocation

Last Class: RPCs. Today:

Distributed object component middleware I - Java RMI

Distributed object component middleware I - Java RMI

Java Remote Method Invocation Specification

RMI. Remote Method Invocation. 16-Dec-16

Advanced Java Programming

Remote Method Invocation

JAVA RMI. Remote Method Invocation

Lecture 18 Inside Java RMI

Distributed Technologies - overview & GIPSY Communication Procedure

Communication Framework

IBD Intergiciels et Bases de Données

Written by: Dave Matuszek

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

Remote Method Invocation R.M.I.

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

Distributed Objects SPL/ SPL 201 / 0 1

Dynamic code downloading using Java TM (Using the java.rmi.server.codebase Property)

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Remote Invocation Vladimir Vlassov and Johan Montelius

Activation of remote objects

Lecture 5: Object Interaction: RMI and RPC

Distributed Information Systems

Communication. Distributed Systems Santa Clara University 2016

A Report on RMI and RPC Submitted by Sudharshan Reddy B

Distributed Computing

CC755: Distributed and Parallel Systems

Distributed Systems COMP 212. Lecture 10 Othon Michail

Object-Oriented Systems Design RMI

Distributed Systems Middleware

Software Paradigms (Lesson 10) Selected Topics in Software Architecture

COMP 6231: Distributed System Design

Communication. Overview

Distributed Software Systems

Last Class: RPCs. Today:

BEA WebLogic. Server. Programming WebLogic RMI

Concurrent Object-Oriented Programming

Activation of remote objects

Chapter 4 Remote Procedure Calls and Distributed Transactions

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

Communication and Distributed Processing

Distributed Objects. Chapter Distributing Objects Overview

Communication and Distributed Processing

Distributed Environments. CORBA, JavaRMI and DCOM

CSci Introduction to Distributed Systems. Communication: RPC

Generic architecture

Lecture 17 Java Remote Method Invoca/on

Object-Oriented Distributed Technology

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

CORBA (Common Object Request Broker Architecture)

Remote Invocation. Today. Next time. l Overlay networks and P2P. l Request-reply, RPC, RMI

RMI Example RMI. CmpE 473 Internet Programming RMI


Java RMI. Algorithmen und Programmierung V Netzprogrammierung. Volker Roth. Wintersemester 2009/2010. Institut für Informatik Freie Universität Berlin

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Chapter 5 Distributed Objects and Remote Invocation

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

BEA WebLogic Server. Programming WebLogic RMI

Transcription:

RMI Remote Method RMI Invocation REMOTE METHOD INVOCATION INTRODUCTION TO RMI, A JAVA API FOR RPC-STYLE INVOCATION OF REMOTE OBJECT METHODS Peter R. Egli 1/19

Contents 1. What is RMI? 2. Important RMI Components 3. RMI Layering 4. RMI Stub and Skeleton 5. RMI Registry 6. RMI Java Packages 7. RMI Transport Layer 8. RMI IDL 9. RMI Server Class Hierarchy 10. RMI Garbage Collection 11. RMI Dynamic Class Loading 12. RMI Parameter Passing 13. RMI Callbacks 14. RMI Remote Object Activation 2/19

1. What is RMI? Remoting: RMI is a lightweight Java technology that provides access to remote methods, similar to RPC, but object-oriented. RMI basically provides remote object access for a client and object registration for servers. API and transport protocol: RMI is both a Java API (java.rmi.* package) as well as a transport protocol definition for transporting RMI calls through a network (JRMI, see below). Java technology: RMI is a Java technology since it requires that client and server objects run in a JVM. By using IIOP as transport protocol, however, it is possible to connect RMI-clients to non-java server objects (CORBA, see below). Network (TCP/IP) Client object Stub Skeleton / stub Server object IIOP: Internet Inter-ORB Protocol 3/19

2. Important RMI Components Client: The client looks up a remote object and calls methods on the obtained remote object. Server: The server registers itself in the RMI registry and accepts method invocations from the client. RMI Registry: The registry is a remote object lookup service. The registry may run on the same host as the server or on a different host. The registry can also be a JNDI server. Web Server: A plain vanilla HTTP server may hold remote object classes for downloading by the client. RMI (lookup an object) RMI Registry RMI (register an object) RMI Client RMI (remote object call) RMI Server HTTP HTTP (code download) Web Server 4/19

3. RMI Layering RMI has 3 layers on the client and server side. Stub layer: Interface between client application (caller) and server object. Remote reference layer: Transport layer: Client object Connects clients to remote service objects. Makes connections between client VM and server VM, formats the data using JRMP (Java Remote Method Protocol) or RMI-IIOP (Internet-Inter-ORB- Protocol, see CORBA). Server object Stub Interface between application and RMI-system Skeleton / stub Remote reference layer Pass calls to the right remote object Remote reference layer 3 layers of RMI system Transport layer Connect client and server VMs through TCP (or UDP) connections using JRMP or RMI-IIOP wire-protocol Transport layer Network (TCP/IP) 5/19

4. RMI Stub and Skeleton RMI uses the proxy design pattern for client and server stub / skeleton: <<Interface>> Subject Both client and server stub implement the same interface. The proxy lives in the client stub layer. <<implements>> + request() <<implements>> Object implementing the interface and registered by the server application with the RMI registry. Proxy <<has>> RealSubject + request() Client stub: Server stub/skeleton: + request() Proxy object on the client for accessing the remote server object. The client stub intercepts the calls of the client and passes it to the remote reference layer. The server stub receives calls from the remote reference layer and passes it to the server object implementing the interface (= RealSubject in the picture above). 6/19

5. RMI Registry (1/2) RMI registry function: The RMI registry is a server registration and client lookup service. It may run anywhere, i.e. does not need to be co-located with the RMI server object. Default port for RMI registry: 1099 (may run on another port as well). Server registration: The servers register (export) objects that implement the service interface using bind() or rebind(): Example: RemServer localobject = new RemServer(); Naming.rebind("MyServ", localobject); Client references: Clients obtain references to server objects (= proxy objects) through the RMI registry using a URL scheme (with an optional port): URL: rmi://<host_name> [:<name_service_port>] /<service_name> Example: RemIf remobject = (RemIf)Naming.lookup("rmi://" + host + "/MyServ"); 7/19

5. RMI Registry (2/2) RMI registry access to server stub classes: The RMI registry needs to have access to the server s stub classes. This can be done in 2 ways (strictly either-or, using both will not work!): 1. CLASSPATH: Add the path to server stub class files to CLASSPATH when starting the RMI registry. 2. Codebase property: Start the server with the codebase property. This way the server registers the remote object along with the path to the class files. The codebase property may be a file or HTTP URL. N.B.: The codebase URL (file or HTTP) must contain a trailing slash / backslash as shown below! Example Windows file codebase property file path: java -Djava.rmi.server.codebase=file:/c:\RemServer\ -cp. RemServer Example Unix codebase property file path: java -Djava.rmi.server.codebase=file:/usr/RemServer/ -cp. RemServer Example Windows and Unix codebase property HTTP path: java -Djava.rmi.server.codebase=http://www.hsz-t.ch/~pegli/RemServer/ -cp. RemServer 8/19

6. RMI Java Packages Online RMI javadoc: https://docs.oracle.com/javase/7/docs/api/ Package java.rmi.* java.rmi.activation.* java.rmi.dgc.* java.rmi.registry.* java.rmi.server.* javax.rmi.* Description Core RMI package with classes and interfaces used by both client and server. Contains interface Remote, classes Naming and RMISecurityManager and some basic exception classes. Classes and interfaces for dynamic activation of remote objects together with RMI daemon (rmid). More information on dynamic invocation see below. Classes and interfaces for distributed garbage collection (DGC). Registry and LocateRegistry classes for directly interacting with a (remote or local) registry. Registry class provides lookup(), rebind(), list() and other methods. Classes for use on the server side like class loader (RMIClassLoader) and UnicastRemoteObject (base class for remote objects). APIs for RMI-IIOP (interoperability between RMI and CORBA). 9/19

7. RMI Transport Layer (1/2) RMI allows using different wire-protocols for encoding and transporting the object requests. Wire protocol = protocol for encoding data (objects) on the wire (network). The RMI transport layer uses stream-based TCP/IP connections only (point-to-point connections, no multicast). a. JRMP (Java RMI Method Protocol): JRMP is the default wire-protocol for RMI. N.B.: In addition to the connection setup packet exchange, the RMI protocol adds additional overhead. Thus RMI is not suited for use on non-lan type networks. Client TCP SYN Server TCP SYN, ACK TCP ACK JRMI version JRMI protocol ack TCP 3-way handshake for connection setup. Client and server agree on the RMI protocol and version to use. RMI call (serialized object data) RMI return (with serialized object data) Actual RMI remote method call. DgcAck Connection teardown (3 or 4 packets) Client indicates to the server that the response has been received (signal to the distributed garbage collector to reclaim the server-side response object). TCP connection teardown. 10/19

7. RMI Transport Layer (2/2) b. HTTP: JRMP dynamically opens TCP connections. Firewalls may block such connections. HTTP as wire-protocol is better suited to get through firewalls (tunneling of RMI calls through an HTTP connection). Client Lookup connection RMI registry Service connection Server object When the client fails to open a JRMP connection to the server, it automatically falls back to HTTP tunneling by encapsulating the request in an HTTP POST request. c. RMI-IIIOP (Internet Inter-ORB Protocol): When using RMI-IIOP, RMI becomes interoperable with CORBA (an RMI client may call a CORBA object). For further information see https://docs.oracle.com/javase/1.5.0/docs/guide/rmiiiop/rmi_iiop_pg.html. 11/19

8. RMI IDL RMI does not have a specific syntax for the description of the interface (IDL-file) but rather uses a compiled Java class as IDL (Java is the IDL). RemServer.java Java compiler (javac.exe) RemServer.class RMI compiler (rmic.exe) RemServer_Stub.class Important rmic options (output of rmic help on command line): -v1.1 -vcompat -v1.2 (default) -iiop -idl Create stubs/skeletons for 1.1 stub protocol version. Create stubs/skeletons compatible with both 1.1 and 1.2 stub protocol versions. Create stubs for 1.2 stub protocol version only Create stubs for IIOP. When present, <options> also includes: -always Create stubs even when they appear current -alwaysgenerate (same as "-always") -nolocalstubs Do not create stubs optimized for same process Create IDL. When present, <options> also includes: -novaluemethods Do not generate methods for valuetypes -always Create IDL even when it appears current -alwaysgenerate (same as "-always") Specify where to find input class files Override location of bootstrap class files Override location of installed extensions -classpath <path> -bootclasspath <path> -extdirs <path> -d <directory> Specify where to place generated class files -J<runtime flag> Pass argument to the java interpreter Class file contains the RMI stub 12/19

9. RMI Server Class Hierarchy A remote (server) object must implement the contracted interface (RemIf) which in turn must extend the base interface Remote. A remote (server) object must extend the class UnicastRemoteObject (adds serializability among other things). Remote Serializable User defined interface RemIf UnicastRemoteObject User defined remote object (class) RemServer 13/19

10. RMI Garbage Collection RMI runs DGC (Distributed Garbage Collection) which frees unused server objects once no client holds a live reference anymore (reference counting algorithm). Garbage collection is hidden to client and server, very much like local GC is hidden to Java applications. A server may optionally implement the Unreferenced interface to be notified about an impending object removal (a kind of destructor call). RMI calls the method unreferenced() before the object is removed. Remote Serializable RemIf UnicastRemoteObject Unreferenced + unreferenced() RemServer 14/19

11. RMI Dynamic Class Loading (1/2) For ease of deployment, stub files can be downloaded on request by the client instead of distributing them manually to each client. The code (stub class files) can be made available for download on a web server. N.B.: The interface file (class file containing the compiled remote interface) is still required both on the client and server side (otherwise client and server will not compile). RMI (lookup an object) RMI Registry RMI Client RMI (remote object call) RMI Server RMI (register an object) HTTP (code download) Web Server 15/19

11. RMI Dynamic Class Loading (2/2) Both client and server need to install a security manager to be able to load classes remotely: System.setSecurityManager( new RMISecurityManger() ); Client and server need a security policy file granting the necessary rights like opening network connections (the following security policy file simply grants everything = no security at all): mysecurity.policy file: grant { permission java.security.allpermission; } Starting the server with the security policy file (note the trailing backslash in the codebase path): java Djava.rmi.server.codebase="http://myserver/foo/" Djava.security.policy=mysecurity.policy MyServer Starting the client with the security policy file: java Djava.security.policy=mysecurity.policy MyClient 16/19

12. RMI Parameter Passing RMI provides the same object and method call semantics as for local objects. But: Arguments to method calls must be serializable, i.e. implement the Serializable interface. Serializable Contained in java.io.serializable package MyArgument Serialization (recursively) flattens objects into a byte-stream, i.e. object attributes that are in turn objects are serialized as well (serialization of a tree of object references). Types that are not serializable: Any object that does not implement Serializable. Any object that would pose a security risk (e.g. FileInputStream). Any object whose value depends on VM-specific information (e.g. Thread). Any object that contains a (non-static, non-transient) unserializable object (recursively). 17/19

13. RMI Callbacks In certain situations it may be desirable to make calls from the server to the client, e.g. for giving progress feedback, warnings or errors etc. There are 2 ways to make the client callable by the server: 1. Client is an RMI server as well (extends UnicastRemoteObject). 2. Client makes itself callable through exportobject. Instead of extending UnicastRemoteObject, the client exports itself as an RMI server: UnicastRemoteObject.exportObject( this ); Remote TimeMonitor + tellmethetime() Remote TimeServer + registermonitor In this example, the server provides an interface for a client to register itself for time updates (registermonitor()). The client needs to export itself through UnicastRemoteObject.exportObject(). TimeClient TimeServer More details see https://docs.oracle.com/cd/e13211_01/wle/rmi/callbak.htm 18/19

14. RMI Remote Object Activation Server objects extending UnicastRemoteObject and registered with the RMI registry run permanently. This may be undesirable when there are a large number of objects (resource usage in terms of memory and TCP connections). RMI provides an alternative through dynamically activatable objects: Remote Serializable RemIf Activatable RemServer Activatable (dynamically instantiatable objects) are registered with rmid (RMI daemon) instead of the rmiregistry daemon (see $JAVA_HOME/bin/rmid.exe). See also https://docs.oracle.com/javase/7/docs/technotes/guides/rmi/activation/overview.html. 19/19