Java RMI Essentials Based on Mastering RMI Rickard Oberg.

Slides:



Advertisements
Similar presentations
Building Distributed Applications using JAVA - RMI
Advertisements

COS 461 Fall 1997 Network Objects u first good implementation: DEC SRC Network Objects for Modula-3 u recent implementation: Java RMI (Remote Method Invocation)
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.
1 Chapter 9 Network Programming. 2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes.
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.
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.
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.
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)
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
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
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.
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.
Client Call Back Client Call Back is useful for multiple clients to keep up to date about changes on the server Example: One auction server and several.
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 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.
 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.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
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 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.
1 RMI Russell Johnston Communications II. 2 What is 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.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Java Distributed Computing
Chapter 4 Remote Method Invocation
Java Distributed Computing
Java Remote Method Invocation (RMI)
RMI Packages Overview java.rmi java.rmi.server java.rmi.registry
Remote Method Invocation
Java RMI CS-328 Internet Programming.
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Overview of RMI Architecture
Remote Method Invocation
Creating a Distributed System with RMI
Java Remote Method Invocation
Creating a Distributed System with RMI
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Java RMI Essentials Based on Mastering RMI Rickard Oberg

2 Essentials of Remote Invocation What is RMI? –The Principles of RMI –How Does RMI Differ from Ordinary Java RMI/JRMP Architecture –Stubs –Marshalling –RMI Threading & Network Connection Management –Distributed Garbage Collection –Naming Summary

3 What is RMI? RMI is a specification (API) for accessing objects from a remote JVM. What is specified? –How objects are to be coded. –How objects can be located & invoked. –How parameters & returned values are passed. Java Remote Method Protocol (JRMP) is Sun’s implementation of the RMI API.

4 The Principles of RMI Meta-principle Make RMI like MI as much as possible. Objects are invoked by calling methods. Expose interfaces not implementation. Exceptions report errors in the computation. GC determines the lifecycle of objects. Get classes that are not part of system classpath via classloading.

5 How Does RMI Differ from Local MI? Remote exceptions –Remote methods throw java.rmi.RemoteExeption. Pass by value –All arguments are pass-by-value. –Serializing may hurt performance for large objects. Latency Invocations take much longer to complete. Security Arguments/returned value are sent over a network. Is privacy an issue?

6 RMI/JRMP Architecture Stubs Marshalling RMI Threading & Network Connection Management Distributed Garbage Collection Naming

7 Stubs Stub –The client has a proxy for the remote object: the stub. –The stub implements the remote object’s interface[s]. –The RMI compiler (rmic) generates the stub. –Remote methods invoked by the client are delegated to the JRMP engine. –The JRMP forwards the call to the server. –The server executes the method. –The result is returned to the client.

8 MyServer MyServer Stub RemoteRef [host=myhost, port=1234, ObjID=0] JRMP > CLIENT MyServerImpl MyServer ServerSocket [port=1234] End-point > Object table > JRMP exported objects SERVER MyServer instance maps to ObjID=0

9 The Remote Interface It is a set of remotely invoked methods. It has the following characteristics: _______________________________________ public interface MyRemoteInterface extends java.rmi.Remote // possibly indirectly { public myMethod( p1, … ) throws java.rmi.RemoteException // declare other remote methods … } _______________________________________ All parameters & return type are serializable.

10 The Hello Interface package masteringrmi.helloworld.interfaces; import java.rmi.Remote; import java.rmi.RemoteException; public interface HelloWorld extends Remote { public String helloWorld( String name ) throws RemoteException; }

11 The Hello Interface … Style: create a contract package It contains the “contract” between client & server: Remote interfaces of server objects Application exceptions throwable by any remote interface Data container classes for data moved between client & server. –Client & server get contract classes & interfaces. –Server also gets implementation classes.

12 Implementing the Remote Interface public class HelloWorldImpl extends UnicastRemoteObject implements HelloWorld { public HelloWorldImpl() throws RemoteException {} public String helloWorld( String name ) { return “Hello “ + name + “!”; }

13 Implementing the Remote Interface … public class HelloWorldImpl implements HelloWorld { public HelloWorldImpl() throws RemoteException { UnicastRemoteObject.exportObject( this ); } public String helloWorld( String name ) { return “Hello “ + name + “!”; }

14 Implementing the Remote Interface … UnicastRemoteObject constructor exports the object Makes it available for incoming invocations. The exportObject method does this explicitly. Extending UnicastRemoteObject inherits distributed implementations of: –equals, hashCode, & toString.

15 RMI/JRMP Architecture Stubs Marshalling RMI Threading & Network Connection Management Distributed Garbage Collection Naming

16 Marshalling Marshalling creates a byte[] from an object. Unmarshalling does the reverse. To marshal, Java serializes the object. To unmarshal, Java deserializes the byte[]. public class foo implements Serializable Foo Copy of Foo Bytes SerializationDeserialization

17 Dynamic Classloading We defer discussion of this until later.

18 Security To dynamically download stubs, the client: –Sets a security manager: ______________________________________________________ import java.rmi.RMISecurityManager;... if ( System.getSecurityManager() == null ) System.setSecurityManager( new RMISecurityManager() ); ________________________________________________ –Has a policy file that permits downloading ________________________________________________ grant { permission java.security.AllPermission; } ________________________________________________

19 Class Versioning Server changes are propagated to clients that subsequently download the stub. What about running clients that already have the stub? Basically, this is a problem. –serial version UID can be used to detect incompatibilities. –Jini further ameliorates the version problem.

20 RMI/JRMP Architecture Stubs Marshalling RMI Threading & Network Connection Management Distributed Garbage Collection Naming

21 RMI Threading & Network Connection Management “Since RMI on the same remote object may execute concurrently, a remote object implementation needs to make sure its implementation is thread-safe.” The RMI specification, section 3.2

22 Network Connections RMI specifies socket factory interfaces to get sockets on the client & server: –Java.rmi.server.RMIClientSocketFactory –Java.rmi.server.RMIServerSocketFactory Override the default implementation (to provide encryption, authentication, …) Selecting an features at run time is desirable: Some jobs want encryption, some do not. Custom implementations are discussed later.

23 Threading Model The JRMP implementation for the server –Instantiates a thread for each connection. –It listens for its associated client’s calls. –It handles each call to completion. The JRMP implementation for the client –Concurrent calls from a client cause concurrent threads connecting to the server. –This may swamp a server. –If your client makes concurrent calls, you may want a different implementation.

24 RMI/JRMP Architecture Stubs Marshalling RMI Threading & Network Connection Management Distributed Garbage Collection Naming

25 Distributed Garbage Collection RMI has distributed garbage collection (DGC). Server tracks clients who have its stub. Server keeps a count of such clients. Count is decremented when client: –explicitly relinquishes reference OR –doesn’t renew its lease (default 10 min.), e.g., client crashed: “Leasing” is due to Miller & Drexler, in –Incentive Engineering for Computational Resource Management. K. E. Drexler & M. S. Miller, B. A. Huberman (ed.), (Studies in Computer Science & Artificial Intelligence), If local & remote references == 0, it is garbage.

26 The Unreferenced Interface A server can implement Unreferenced It has 1 method: unreferenced. It is called when there are no remote references to the object. Being bound in the RMI registry counts as a remote reference. –It must unbind itself before unreferenced can be invoked.

27 RMI/JRMP Architecture Stubs Marshalling RMI Threading & Network Connection Management Distributed Garbage Collection Naming

28 Naming Rmiregistry allows: –A server to store its (serialized) stub on a web server –A client to download & deserialize the stub. The essential information: the url of the serialized stub file.