Distributed Systems COMP 212. Lecture 10 Othon Michail

Similar documents
JAVA RMI. Remote Method Invocation

5.4. Events and notifications

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

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

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

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

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

Remote Objects and RMI

RMI. (Remote Method Invocation)

Remote Method Invocation in Java

Distributed Programming in Java. Distribution (2)

Remote Method Invocation Benoît Garbinato

presentation DAD Distributed Applications Development Cristian Toma

Distributed Objects SPL/ SPL 201 / 0 1

RMI Case Study. A Typical RMI Application

Remote Procedure Call

Remote Method Invocation. Benoît Garbinato

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

Last Class: Network Overview. Today: Distributed Systems

CS 5523 Operating Systems: Remote Objects and RMI

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

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

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

Remote Method Invocation

Verteilte Systeme (Distributed Systems)

Programming with RMI Reminder

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

RMI Example RMI. CmpE 473 Internet Programming RMI

Generic architecture

Remote Method Invocation

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

Remote Method Invocation R.M.I.

THE RMI PROXY USER GUIDE

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Chapter 4 Remote Procedure Calls and Distributed Transactions

Communication and Distributed Processing

Distributed object component middleware I - Java RMI

IBD Intergiciels et Bases de Données

Distributed object component middleware I - Java RMI

Lecture 15: Frameworks for Application-layer Communications

Lecture 15: Frameworks for Application-layer Communications

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

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

Distributed Computing

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

Component-Based Software Engineering

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

Communication and Distributed Processing

Outline. Chapter 4 Remote Procedure Calls and Distributed Transactions. Remote Procedure Call. Distributed Transaction Processing.

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

Distributed Objects. Remote Method Invokation

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

Distributed Systems. 5. Remote Method Invocation

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

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

Remote Method Invocation

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

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

Written by: Dave Matuszek

Chapter 5 Distributed Objects and Remote Invocation

Lecture VI: Distributed Objects. Remote Method Invocation

Modulo II Socket, RMI e Corba

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


RMI. Remote Method Invocation. 16-Dec-16

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

Remote Method Invocation Java RMI & Web-Services

Course Snapshot. The Next Few Classes

COMP 6231 Distributed Systems Design. Tutorial 2 by Alexandre Hudon January 21 st, 2013

CC755: Distributed and Parallel Systems

IJESRT. http: //

A Typical RMI Application

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

A Typical RMI Application. Case Study

Object-Oriented Systems Design RMI

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

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

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

Distributed Information Systems

Distributed Software Systems

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

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

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

Java WebStart, Applets & RMI

JAVA RMI Java, summer semester

5 Distributed Objects: The Java Approach

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

Activation of remote objects

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java

4:40pm - 6:10pm (90 min)

Sockets and RMI. CS151 Chris Pollett Dec. 5, 2005.

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Reflection/RMI 4/28/2009

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

RPC and RMI. 2501ICT Nathan

Communication. Distributed Systems Santa Clara University 2016

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

Remote Invocation Vladimir Vlassov and Johan Montelius

Transcription:

Distributed Systems COMP 212 Lecture 10 Othon Michail

RMI: Remote Method Invocation Allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. Provides for remote communication between objects written in Java Remote objects: can be thought of as an expansion of the RPC mechanism 2/42

RMI: Remote Method Invocation Objects: hide their internals by means of a well-defined interface Can be easily replaced/adapted as long as the interface remains the same state: object s data methods: operations on those data interface: what makes methods available outside the object An object may offer multiple interfaces An interface may be implemented by multiple objects Method calls support state changes within the object through the defined interface The separation between interfaces and objects implementing them is crucial for DSs Allows us to place an interface on one machine (client) while the object implementation resides on another (server) 3/42

The Distributed Object Common organization of a remote object with client-side proxy The proxy can be thought of as the client stub of RPCs The skeleton can be thought of as the server stub of RPCs 4/42

Remote Objects: Parameter Passing The situation when passing an object by reference or by value Note: O1 is passed by value; O2 is passed by reference Transparency: The only distinction visible to the programmer is that local objects have different data types than remote objects Otherwise, both are treated very much the same 5/42

Example: Java RMI In Java, distributed objects are integrated into the language core results in a very high degree of distribution transparency with exceptions, where efficiency is more important Java does not support RPC, only distributed objects The distributed object s state is stored on the server Interfaces are made available to remote clients via distributed object proxies To build the DS application, the programmer: implements the client proxy as a class, and the server skeleton as another class 6/42

Java RMI 7/42

Client-server Applications Using RMI Create the Interface to the server Create the Server Create the Client Compile the Interface (javac) Compile the Server (javac) Compile the Client (javac) Generate Stubs and Skeletons (no longer required) Start the RMI registry (rmiregistry) Start the RMI Server Start the RMI Client 8/42

A Simple Example We will build a program (client) that requests access to a remote object which resides on a server The remote object that we shall implement has a very simple functionality: Return the current time in milliseconds since 1st January 1970, 00:00:00 GMT 9/42

The Interface Code import java.rmi.*; public interface Second extends Remote { long getmilliseconds() throws RemoteException; All the remote interfaces extend Remote (java.rmi) Objects created using this interface will have facilities that enable them to have remote messages sent to them The interface must be declared public in order for clients to be able to access objects which have been developed by implementing the interface All methods that are called remotely must throw the exception RemoteException 10/42

Remote Object import java.rmi.*; import java.util.date; import java.rmi.server.unicastremoteobject; public class SecondImpl extends UnicastRemoteObject implements Second { public SecondImpl() throws RemoteException { ; public long getmilliseconds() throws RemoteException { return(new Date().getTime()); // The method gettime returns the time in msecs // since 1st January 1970, 00:00:00 GMT ; 11/42

The Remote Object Code Explained (1) public class SecondImpl extends UnicastRemoteObject implements Second The class SecondImpl implements the remote interface Second and provides a remote object It extends another class known as UnicastRemoteObject which implements a remote access protocol NOTE: using UnicastRemoteObject enables us not to worry about access protocols 12/42

The Remote Object Code Explained (2) public SecondImpl() throws RemoteException { This constructor calls the superclass constructor, of the UnicastRemoteObject class During construction, a UnicastRemoteObject is exported Is available to accept incoming requests by listening for incoming calls from clients on an anonymous port 13/42

The Remote Object Code Explained (3) public long getmilliseconds() throws RemoteException { return(new Date().getTime()); // The method gettime returns the time in msecs // since 1st January 1970, 00:00:00 GMT This method is the implementation of the getmilliseconds method found in the interface Second This just returns the time in milliseconds NOTE: Again since it is a method which can be invoked remotely it could throw a RemoteException object 14/42

The Server Code import java.rmi.naming; public class Server { public static void main(string[] args) { // RMISecurityManager smanager = new RMISecurityManager(); // System.setSecurityManager(sManager); try { SecondImpl remote = new SecondImpl(); Naming.rebind ( Dater", remote); System.out.println( Object bound to name"); catch(exception e) { System.out.println("error occurred at server + e.getmessage()); 15/42

The Server Code Explained (1) public static void main(string[] args) { // RMISecurityManager smanager = new RMISecurityManager(); // System.setSecurityManager(sManager); try { SecondImpl remote = new SecondImpl(); Naming.rebind ( Dater", remote); System.out.println( Object bound to name"); catch(exception e) { System.out.println("error occurred at server + e.getmessage()); Loads a security manager for the remote object If this is not done, then RMI will not download code operations of downloaded code are subject to a security policy 16/42

The Server Code Explained (2) public static void main(string[] args) { // RMISecurityManager smanager = new RMISecurityManager(); // System.setSecurityManager(sManager); try { SecondImpl remote = new SecondImpl(); Naming.rebind ( Dater", remote); System.out.println( Object bound to name"); catch(exception e) { System.out.println("error occurred at server + e.getmessage()); Creates an object 17/42

The Server Code Explained (3) public static void main(string[] args) { // RMISecurityManager smanager = new RMISecurityManager(); // System.setSecurityManager(sManager); try { SecondImpl remote = new SecondImpl(); Naming.rebind ( Dater", remote); System.out.println( Object bound to name"); catch(exception e) { System.out.println("error occurred at server + e.getmessage()); Finally, informs the RMI naming service that the object that has been created (remote) is given the string name Dater Once a remote object is registered (bound) with the RMI registry on the local host, callers on a remote (or local) host can lookup the remote object by name ( Dater here), obtain its reference, and then invoke remote methods on the object 18/42

The Essential Steps in Writing an RMI Server create and install a security manager create an instance (or many instances if required) of a remote object register the remote object(s) with the RMI registry 19/42

The Client Code import java.rmi.*; public class TimeClient { public static void main(string[] args) { try { Second sgen = (Second) Naming.lookup("rmi://localhost/Dater"); System.out.println("Milliseconds are + sgen.getmilliseconds()); catch(exception e) { System.out.println("Problem encountered accessing remote object + e); 20/42

The Client Code Explained (1) public static void main(string[] args) { try { Second sgen = (Second) Naming.lookup("rmi://localhost/Dater"); System.out.println("Milliseconds are + sgen.getmilliseconds()); catch(exception e) { System.out.println("Problem encountered accessing remote object + e); Looks up the object within the naming service which is running on the server using the static method lookup The method lookup obtains a reference to the object identified by the string "Dater" which is resident on the server that is identified by localhost (i.e., the host name) 21/42

The Client Code Explained (2) public static void main(string[] args) { try { Second sgen = (Second) Naming.lookup("rmi://localhost/Dater"); System.out.println("Milliseconds are + sgen.getmilliseconds()); catch(exception e) { System.out.println("Problem encountered accessing remote object + e); Finally, the method getmilliseconds is invoked on the sgen object 22/42

The Essential Steps in Writing an RMI Client Create and install the security manager (omitted in our example) Construct the name of the remote object Use the Naming.lookup method to look up the remote object with name defined in the previous step Invoke the remote method on the remote object 23/42

Why Would it Work? You could ask me: And who provides the naming service? The naming service implemented by the RMI registry is started on the server by: > start rmiregistry Starts a remote object registry on the specified port on the current host If the port is omitted, starts on 1099 Usually runs in the background Binds remote objects to names Clients on local and remote hosts can then look up remote objects and make remote method invocations 24/42

RMI with Java 5 J2SE 5.0 (and later) support dynamic generation of stub classes at runtime, that is, no need to do anything about this Compile the interface, Server, and Client (javac) Start the rmiregistry > start rmiregistry Start the server > java Server Start the client > java TimeClient 25/42

Some More Advanced Stuff Parameter passing Example Mobile code Security 26/42

Parameter Passing Only primitive types and reference types that implement the Serializable interface can be used as parameter/return value types for remote methods 27/42

TimeTeller.java import java.util.date; public class TimeTeller implements java.io.serializable { public long getmilliseconds() { System.out.println("TimeTeller"); return(new Date().getTime()); // The method gettime returns the time in msecs ; 28/42

New SecondImpl.java import java.util.date; import java.rmi.*; import java.rmi.server.unicastremoteobject; public class SecondImpl extends UnicastRemoteObject implements Second { public TimeTeller gettimeteller() throws RemoteException{ return new TimeTeller(); 29/42

New TimeClient.java import java.rmi.*; public class TimeClient { public static void main(string[] args) { try { Second sgen = (Second) Naming.lookup("rmi://localhost/Dater"); System.out.println("Server Milliseconds are + sgen.getmilliseconds()); TimeTeller tt = sgen.gettimeteller(); System.out.println("Local Milliseconds are " + tt.getmilliseconds()); catch(exception e) { System.out.println("Problem encountered accessing remote object "+e); 30/42

Code Migration Under certain circumstances, in addition to the usual passing of data, passing code (even while it is executing) can greatly simplify the design of a distributed system However, code migration can be inefficient and very costly So, why migrate code? 31/42

Reasons for Migrating Code Why? Biggest single reason: better performance The big idea is to move a computation intensive task from a heavily loaded machine to a lightly loaded machine on demand and as required 32/42

Code Migration Examples Moving (part of) a client to a server processing data close to where the data resides. It is often too expensive to transport an entire database to a client for processing, so move the client to the data. Moving (part of) a server to a client checking data prior to submitting it to a server. The use of local error-checking (with JavaScript) on webforms is a good example of this type of processing. Error-check the data close to the user, not at the server. 33/42

Classic Code Migration Example Searching the web by roaming : Rather than search and index the web by requesting the transfer of each and every document to the client for processing, the client relocates to each site and indexes the documents it finds in situ The index is then transported from site to site, in addition to the executing process 34/42

Another Big Advantage: Flexibility The principle of dynamically configuring a client to communicate to a server The client first fetches the necessary software, and then invokes the server. This is a very flexible approach. 35/42

Major Disadvantage Security Concerns Blindly trusting that the downloaded code implements only the advertised interface while accessing your unprotected hard-disk and does not send the juiciest parts to heaven-knowswhere may not always be such a good idea. 36/42

Dynamic Code Loading Ability to download the bytecodes (or simply code) of an object's class if the class is not defined in the receiver's virtual machine The types and the behaviour of an object, previously available only in a single virtual machine, can be transmitted to another, possibly remote, virtual machine Java RMI passes objects by their true type, so the behaviour of those objects is not changed when they are sent to another virtual machine From Oracle s tutorial on Java RMI 37/42

Security Manager The JDK 1.2 security model is more sophisticated than the model used for JDK 1.1 JDK 1.2 contains enhancements for finergrained security and requires code to be granted specific permissions to be allowed to perform certain operations. You need to specify a policy file From Oracle s tutorial on Java RMI 38/42

Secure Server Code import java.rmi.naming; public class server { public static void main(string[] args) { RMISecurityManager smanager = new RMISecurityManager(); System.setSecurityManager(sManager); try { secondimpl remote = new secondimpl(); naming.rebind ("dater", remote); system.out.println("object bound to name"); catch(exception e) { system.out.println("error occurred at server "+e.getmessage()); 39/42

Secure Client Code import java.rmi.*; public class TimeClient { public static void main(string[] args) { RMISecurityManager smanager = new RMISecurityManager(); System.setSecurityManager(sManager); try { Second sgen = (Second) Naming.lookup("rmi://localhost/Dater"); System.out.println("Milliseconds are "+sgen.getmilliseconds()); catch(exception e) { System.out.println("Problem encountered accessing remote object "+e); 40/42

Sample General Policy The following policy allows downloaded code, from any code base, to do two things: Connect to or accept connections on unprivileged ports (ports greater than 1024) on any host Connect to port 80 (the port for HTTP) grant { permission java.net.socketpermission "*:1024-65535", "connect,accept"; permission java.net.socketpermission "*:80", "connect"; ; From Oracle s tutorial on Java RMI 41/42

Java RMI Java RMI extends Java to provide support for distributed objects in the JAVA language It allows objects to invoke methods on remote objects using the same syntax as for local invocations A good tutorial at https://docs.oracle.com/javase/tutorial/rmi/ 42/42