5/15/2015B.Ramamurthy1 Creating a Distributed System with RMI B.Ramamurthy.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
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)
Distributed Objects and Remote Invocation
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.
Distributed Object & Remote Invocation Vidya Satyanarayanan.
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.
Remote Method Invocation
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.
6/13/2015B.Ramamurthy1 System Models Bina Ramamurthy (Based on Slides from CDK text)
1 HANDOUT 14 Remote Method Invocation (RMI) BY GEORGE KOUTSOGIANNAKIS THIS DOCUMENT CAN NOT BE REPRODUCED OR DISTRIBUTED WITHOUT TH E WRITTEN PERMISSION.
Java RMI and WS B. Ramamurthy.
EEC-681/781 Distributed Computing Systems Lecture 5 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
Java RMI, JAX-RPC and JWSDP
Introduction to Remote Method Invocation (RMI)
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
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)
+ A Short Java RMI Tutorial Usman Saleem
11 September 2008CIS 340 # 1 Topics To examine the variety of approaches to handle the middle- interaction (continued) 1.RPC-based systems 2.TP monitors.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
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.
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.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
DISTRIBUTED OBJECTS AND REMOTE INVOCATION. Introduction This chapter is concerned with programming models for distributed applications... Familiar programming.
IS473 Distributed Systems CHAPTER 5 Distributed Objects & Remote Invocation.
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.
Distributed Objects & Remote Invocation
 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.
Distributed objects and remote invocation Pages
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.
Distributed programming in Java Faculty:Nguyen Ngoc Tu Session 5 - RMI.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
6/5/2016B.Ramamurthy1 Distributed Objects and Remote Invocation Chapter 5 B.Ramamurthy.
Computer Science Lecture 4, page 1 CS677: Distributed OS Last Class: RPCs RPCs make distributed computations look like local computations Issues: –Parameter.
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
Topic 4: Distributed Objects Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Object Interaction: RMI and RPC 1. Overview 2 Distributed applications programming - distributed objects model - RMI, invocation semantics - RPC Products.
Chapter 4 Remote Method Invocation
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Programming Models for Distributed Application
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Creating a Distributed System with RMI
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Creating a Distributed System with RMI
Creating a Distributed System with RMI
Remote method invocation (RMI)
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
Overview of RMI Architecture
Remote Method Invocation
Distribution Infrastructures
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:

5/15/2015B.Ramamurthy1 Creating a Distributed System with RMI B.Ramamurthy

5/15/2015B.Ramamurthy2 Remote Method Invocation Remote Method Invocation (RMI) is Java’s implementation of object-to-object communication among Java objects to realize a distributed computing model. RMI allows us to distribute our objects on various machines, and invoke methods on the objects located on remote sites.

5/15/2015B.Ramamurthy3 RMI-based Distributed System 4. XYZ Implementation Client Host Server Host XYZ Client Stub XYZ interface uses implements

5/15/2015B.Ramamurthy4 Steps in RMI-based Application 1. Design the interface for the service. 2. Implement the methods specified in the interface. 3. Generate the stub and the skeleton. 4. Register the service by name and location. 5. Use the service in an application.

5/15/2015B.Ramamurthy5 Compile and Register Commands Client Host Server Host XYZ Client Stub XYZ interface uses implements XYZ Implementation rmic rmiregistry Stores object by nameFinds object by name Compile

5/15/2015B.Ramamurthy6 More Details Once the object (or service) is registered, a client can look up that service. A client (application) receives a reference that allows the client to use the service (call the method). Syntax of calling is identical to a call to a method of another object in the same program.

5/15/2015B.Ramamurthy7 Parameter Marshalling Transfer of parameters (or marshalling) is done by the RMI. Complex objects are streamed using Serialization. RMI model of networking for distributed system involves only Java. No need to learn IDL or any other language.

5/15/2015B.Ramamurthy8 Case Study Take a look at: ocs/technotes/guides/rmi/hello/hello- world.html

5/15/2015B.Ramamurthy9 Defining Remote Interface import java.rmi.*; // the interface extends Remote interface // any class implementing Remote can be accessed remotely security permitting public interface XYZ extends Remote { // specify methods that can be called remotely // each method “throws RemoteException” }

5/15/2015B.Ramamurthy10 RemoteException Any time you depend on outside entities there is a potential for problems in communication, networking, server crash etc. Any exception due to these should be handled by the services. This feature imparts robustness to the application. Java mandates this feature for any RMI service.

5/15/2015B.Ramamurthy11 Implementing the Remote Interface import java.rmi.*; import java.rmi.server.*; import java.net.*; // others as needed XYZImpl implements TemperatureServer { The main method instantiates an object for the service, and registers it with rmiregistry.

5/15/2015B.Ramamurthy12 Server Object Name Syntax for the server object name is: //host:port/remoteObjectName Default port number for rmiregistry is 1099 For local host the object name: //localhost/XYZServer For a remote host // /XYZServer

5/15/2015B.Ramamurthy13 Name Binding rebind method binds a server’s object name to the object’s name as it is in the registry. Clients use the name in the registry. There is also a bind() method. But rebind is better since it binds the most recently registered object.

5/15/2015B.Ramamurthy14 The Client import java.rmi.*; // import other packages constructor takes care of lookup of remote object and access.

5/15/2015B.Ramamurthy15 Client Details The name of the server object along with the IP of the remote location is used in Naming class’s lookup method to get an object reference. This object reference is then used for remote method calls. Observe that there is no difference between the local and remote call.

5/15/2015B.Ramamurthy16 Preparing the Application 1. Compile all the class using javac. 2. Then start the registry (this will be running as a daemon) rmiregistry &

5/15/2015B.Ramamurthy17 Preparing the Application 4. Run the server which will register with the RMI registry. Java XYZServerImpl & 5. Run the client. Java XYZClient parameters&

5/15/2015B.Ramamurthy18 Inside RMI Basic RMI classes: /usr/java1.1/src/java/rmi java.rmi.registry.* java.rmi.Naming class (static/class methods) java.rmi.Remote interface (marker interface) java.rmi.server.* Default RMI port 1099 Both lookup from local and remote are acceptable.

5/15/2015B.Ramamurthy19 Implementation of RMI (5.2.5) AccessException.java RemoteException.java AlreadyBoundException.java ConnectException.java ServerException.java ConnectIOException.java ServerRuntimeException.java MarshalException.java StubNotFoundException.java UnexpectedException.jav ServerError.java UnknownHostException.java NoSuchObjectException.java UnmarshalException.java NotBoundException.java RMISecurityException.java RMISecurityManager.java Remote.java MarshalledObject.java Naming.java activation dgc Registry server

5/15/2015B.Ramamurthy20 The role of proxy and skeleton (stub) in remote method invocation object A object B skeleton Request proxy for B Reply Communication Remote Remote referenceCommunication module reference module module for B’s class & dispatcher remote client server servant Object A invokes a remote object in Object B for which it holds a remote object reference. “System Model”

5/15/2015B.Ramamurthy21 RMI Internals: Communication Module Carries out request-reply protocol; On the client side {message type, message id, remote reference to object} are gathered and sent out. At most once invocation semantics; On the server side, it gets local reference for remote reference from remote reference module, invokes a dispatcher with this reference.

5/15/2015B.Ramamurthy22 RMI Internals: Remote Reference module Responsible for translating between local and remote object references and for creating remote object references. A remote object table has a mapping between local and remote references. A table at server (entry for object ref for B) and a table at client (entry for object ref for proxy B).

5/15/2015B.Ramamurthy23 RMI Internals: Remote References Action of remote reference module: See RemoteRef.java interface When a remote object is to be passed as argument or result for the first time, the remote ref is asked to create a remote ref object which is added to the table. When a remote object reference arrives in a request or reply, the remote ref module is asked for corresponding local object ref, which may either a proxy or remote object. If it is not in the table RMI runtime creates it and asks remote ref module to add it to the table.

5/15/2015B.Ramamurthy24 RMI software Layer of software between application level objects and communication and remote reference modules: “Middleware” Proxy: provides remote access transparency. One proxy for every remote object in the client. Dispatcher: A server has one dispatcher and RemoteStub for each class representing a remote object. It receives request message from comm. module It used MessageId to select appropriate method in RemoteStub. RemoteStub and dispatcher use same MessageId. RemoteStub: A class of remote object has a that stands for the remote interface. All the access dependencies are hidden in this class. A remote object has a servant that directly implements the methods. Java 5 creates this dynamically. Binder: binds textual names to remote object references. RMIRegistry is a binder; Naming class; see fig.5.13 We will discuss this next. Server Threads: one thread per invocation Distributed garbage collection: See Andrew Birell’s paper [1995].

Reference Java.rmi The remote method invocation guide, by E. Pitt and K. Mcniff, Addison Wesley, ISBN: , /15/2015B.Ramamurthy25

Client M/C JVM 5/15/2015B.Ramamurthy26 Simple RMI System Model Remote interface Host M/C ClientApp Registry JVM server

Registry (singleton – per system - during production) 5/15/2015B.Ramamurthy27 Name Mortgage Tempertur Reference

Semantics of remote method invocation A remote method has to be declared to throw a remote exception. Clients of a remote method should try, catch and deal with remote exceptions. Arguments of object type to the remote method are passed by deep copy and not by reference Any results of object type returned by deep copy, not by reference Any exception (object) thrown is also returned as deep copy Java.lang.Object is specialized for remote objects and remote references “At most once” semantics: idempotent: very important for transactional systems Remote objects are subject to distributed garbage collection via reference counting, before local garbage collection is applied. To be accessible, a remote object must implement “remote” interface (or the interface marked as Remote by the marker interface) and be exported to the RMI system. Execution of remote object is asynchronous but synchronicity is realized using the underlying network. 5/15/2015B.Ramamurthy28

Serialization Serialization is a the operation of encoding objects into stream of bytes: bytification. De-serialization is taking the bytes and constructing objects out of the byte stream. Is used to marshal and unmarshal arguments and results. If serialization is not addressed your distributed system will not work: whether it be your mobile systems or land networked system. A stumbling block for many who are new to DS. 5/15/2015B.Ramamurthy29

Serialization (contd.) In order for an object to be passed around in a DS it must implement Serializable interface (another marker interface: Remote was the first one we saw) For performance reasons you may want to specify the serialization version (though not required) serialVersionUID 5/15/2015B.Ramamurthy30

Serialization (contd.) (not UML diagram) 5/15/2015B.Ramamurthy31 AA B C B C A B C A B A C2C1 Incorrectly de-serialized Once an object is serialized, serialized object is reused

Reference ocs/technotes/guides/rmi/index.html 5/15/2015B.Ramamurthy32

RMI package: Registry Naming is class that provided lookup, bind, unbind, rebind and list for remote object references: higher level Registry for a Registry interface: with the above methods at a lower level: you have to locate the registry object and then invoke the methods rmi://host:port/name Fully qualified identification/reference for a remote object. 5/15/2015B.Ramamurthy33

Registry You can create a registry Start a registry Get registry location: LocateRegistry class Then do binding, lookup etc. 5/15/2015B.Ramamurthy34

UnicastRemoteObject UnicastRemoteObject is a base for your remote object that provides simple transient point-point RMI servers. There are other features that we have not covered such as security model using policy files that is in the demo that we posted in handout#1 5/15/2015B.Ramamurthy35

5/15/2015B.Ramamurthy36 RMI Internals: Use of Reflection What is reflection? See Reflection package Reflection enables Java code to discover information about the fields, methods and constructors of loaded classes, and To use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. ex.html Reflection feature allowed for dynamic creation of stubs in Java 2 version onwards. Read more about reflection model in computing.

5/15/2015B.Ramamurthy37 RMI Internals: Distributed Garbage Collection Based on reference counts. Local garbage collectors and a distributed support. Each server holds the list of processes that hold remote object references: for example, B.Holders When a client C first receives a remote reference to a particular remote object, say B, it makes a addRef(B) invocation to server of that remote object and then creates proxy; server adds C to B.Holders. When client C’s garbage collector finds that proxy is no longer reachable (ref count), it makes a removeRef(B) invocation to server and then deletes proxy; the server removes C from B.Holders. When B.Holders is empty, server’s local garbage collector will reclaim the space occupied B unless there are any local holders. These extra calls for updates occur during proxy creation and deletion and do not affect normal opertion. Tolerates communication failures: addRef() and removeRef() are idempotent: effects of N > 0 identical requests is the same as for a single request. If addRef() fails with an exception, proxy is not created, removeRef() is transmitted; removeRef() failures are dealt with by “leases” (Jini kind).

5/15/2015B.Ramamurthy38 A Little bit of Reflection Method class, invoke method Invoke method requires two parameters: first the object to receive invocation, second an array of Object parameters. Invoke executes the method on the object and returns result as Object. Method M; Object result = M.invoke(String, Args);

5/15/2015B.Ramamurthy39 Using Reflection in RMI Proxy has to marshal info. about a method and its arguments into a request message. For a method it marshals an object of class Method into the request. It then adds an array of objects for the method’s arguments. The dispatcher unmarshals the Method object and its arguments from request message. The remote object reference is obtained from remote ref. table. The dispatcher then calls the “invoke” method on the object reference and array of arguments values. After the method execution the dispatcher marshals the result or any exceptions into the reply message.

5/15/2015B.Ramamurthy40 Summary We discussed designing a distributed system using RMI We also looked at RMI internal We also learned about marker interface, distributed garbage collection, object marshalling, registry, server-port binding, Naming class of RMI, …