RMI Example RMI. CmpE 473 Internet Programming RMI

Similar documents
JAVA RMI. Remote Method Invocation

Remote Method Invocation

RMI Case Study. A Typical RMI Application

Generic architecture

JAVA RMI Java, summer semester

Remote Method Invocation in Java

RMI. (Remote Method Invocation)

RMI. Remote Method Invocation. 16-Dec-16

Written by: Dave Matuszek

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

5.4. Events and notifications

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

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

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

presentation DAD Distributed Applications Development Cristian Toma

Distributed Programming in Java. Distribution (2)

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

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

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

Remote Method Invocation

Last Class: Network Overview. Today: Distributed Systems

IBD Intergiciels et Bases de Données

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

Distributed Computing

A Typical RMI Application

A Typical RMI Application. Case Study

Remote Method Invocation

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

Distributed Systems COMP 212. Lecture 10 Othon Michail

Java Remote Method Invocation Specification

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

CS193k, Stanford Handout #12. Threads 4 / RMI

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

Reflection/RMI 4/28/2009

Remote Procedure Call

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

Activation of remote objects

Distributed Objects SPL/ SPL 201 / 0 1

EDA095 Remote Method Invocation

EDA095 Remote Method Invocation

Distributed Software Systems

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

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

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

Component-Based Software Engineering

Lecture 18 Inside Java RMI

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

Distributed object component middleware I - Java RMI

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

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

Distributed object component middleware I - Java RMI

Modulo II Socket, RMI e Corba

Are Sockets a Good Programming Paradigm? EDA095 Remote Method Invocation. The Remote Procedure Call Model. The Remote Procedure Call Architecture

Activation of remote objects

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

Remote Objects and RMI

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

Verteilte Systeme (Distributed Systems)

Are Sockets a Good Programming Paradigm? EDA095 Remote Method Invocation. The Remote Procedure Call Model. The Remote Procedure Call Architecture

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

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

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

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

THE RMI PROXY USER GUIDE

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

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Question1 (10 points) : Patron Aggregator

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Middleware Labs: Java RMI

CS 5523 Operating Systems: Remote Objects and RMI

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

Distributed Applications Programming. Lab 4

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

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

Course Snapshot. The Next Few Classes

IJESRT. http: //

Remote Method Invocation Java RMI & Web-Services

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

Middleware Labs: Java RMI

Distributed Objects. Remote Method Invokation

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Java Remote Method Invocation Specification

Chapter 4: Processes. Process Concept. Process State

5 Distributed Objects: The Java Approach

Remote Method Invocation Benoît Garbinato

BEA WebLogic. Server. Programming WebLogic RMI

Chapter 5 Distributed Objects and Remote Invocation

Remote Method Invocation R.M.I.

Chapter 4 Remote Procedure Calls and Distributed Transactions

Oracle WebLogic Server

Communication and Distributed Processing

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

RPC and RMI. 2501ICT Nathan

Distributed Systems. 5. Remote Method Invocation

Remote Method Invocation. Benoît Garbinato

Communication and Distributed Processing

BEA WebLogic Server. Programming WebLogic RMI

COMP 6231: Distributed System Design

OBJECTSPACE VOYAGER CORE TECHNOLOGY

Transcription:

CmpE 473 Internet Programming Pınar Yolum pinar.yolum@boun.edu.tr Department of Computer Engineering Boğaziçi University RMI Examples from Advanced Java: Internet Applications, Art Gittleman Remote Method Invocation Allows an object to call methods of a remote object Both objects should run in JVM Uses sockets-based transport for communication by default Three steps Locate the object Communicate with the object Load bytecodes of transferred objects RMI RMI Example Get fortunes from a fortune server Fortune server registers a fortune object with registry Client accesses the registry and finds a fortune object Client calls the method that returns fortune Client must know which methods are available 3 4 1

RMI Remote Object Remote interface Contains methods that can be called remotely by the client Remote objects Whose methods can be called by objects on other machines Implement remote interface Extends java.rmi.remote All methods in the interface must throw java.rmi.remoteexception + other specific exceptions 5 6 Passing Objects Local object Passed by value The object must be serializable Default serialization Copies all fields (except static or transients) Can be overridden Remote object Passed by reference Stub: Representative (or proxy) for the remote object Stub implements the same set of remote interfaces as the remote object Stub can be cast to any of the remote interfaces implemented by the remote object Sketch of the RMI Server (1) Client Fortune Server Because clients import java.rmi.remote; will call its methods import java.rmi.remoteexception; public interface Fortune extends Remote { public Object getfortune (String when) throws RemoteException; 7 8 2

Sketch of the RMI Server (2) Fortune Server implements Fortune interface Only methods specified in the interface can be called by the client Extends UnicastRemoteObject UnicastRemoteObject java.rmi.server.unicastremoteobject Implements Remote and Serializable Implementations for equals, tostring, hashcode exportobject(remote obj, int port) Make RMI runtime aware of the object Supports point-to-point remote communication Load a stub class Construct an instance of the stub 9 RMI Server (1) import java.rmi.*; import java.rmi.server.unicastremoteobject; import java.util.vector; public class FortuneServer extends UnicastRemoteObject implements Fortune { public static final int SIZE = 3; private Vector now = new Vector(SIZE); private Vector later = new Vector(SIZE); public FortuneServer()throws RemoteException { now.addelement("a friend is near"); now.addelement("expect a call"); now.addelement("someone misses you"); later.addelement("wealth awaits -- if you desire it."); later.addelement("climb the hill of effort for high grades."); later.addelement("the door to success is open to you."); private Vector find(string when) { if (when.equals(fortune.now)) return now; else return later; 10 public synchronized String getfortune(string when) throws RemoteException { int number = (int)(3*math.random()); Vector fortunes = find(when); return (String)fortunes.elementAt(number); RMI Server (2) public static void main(string[] args) { System.setSecurityManager(new RMISecurityManager()); try { Fortune fortune = new FortuneServer(); String url = "rmi://" + args[0] + "/Seer"; Naming.rebind(url,fortune); System.out.println("Starting Fortune server"); catch(exception e) { e.printstacktrace(); RMI Client import java.rmi.*; public class FortuneClient { public static void main(string[] args) { System.setSecurityManager(new RMISecurityManager()); try { String url = "rmi://" + args[0] + "/Seer"; Fortune fortuneteller = (Fortune)Naming.lookup(url); String fortune = fortuneteller.getfortune(fortune.now); System.out.println("Today's fortune is: " + fortune); fortune=fortuneteller.getfortune(fortune.later); System.out.println("Future fortune is: " + fortune); catch(exception e) { e.printstacktrace(); 11 12 3

Stub-to-Remote When the client calls a method on the stub Stub connects the remote JVM Writes (marshals) parameters to the remote JVM Reads (unmarshals) the result (return value, warning, exception) Gives the result to the client Security Managers Checks accesses to System resources (e.g., local file system) Privileged operations Based on policy implemented Methods Are of type checkxxx; (checkaccess; checkconnect) Ex: checkwrite(string filename) Ex: checkconnect(string host, int port) Throw an exception if there is a problem All RMI programs must install one java.rmi.rmisecuritymanager Extends java.lang.securitymanager 13 14 Permissions Registry Granted to codes for access Create a permission perm = new java.io.filepermission("/tmp/abc", "read"); Grant a permission grant codebase "file:/home/sysadmin/" { permission java.io.filepermission "/tmp/abc", "read"; ; Stored in a.policy file Difficult to construct by hand (policytool) Check out the default policy $JAVA_HOME/lib/security/java.policy java -Djava.security.policy=policy-file MyClass Naming.rebind(name, engine); Adds it to the registry (association between name and object) Name: String formatted as a URL Default port: 1099 Clients can talk to the server only over the registry Keeps track of registered servers Wakes up the server if there is an incoming request 15 16 4

Compiling Build a jar file of the interfaces Build the server side files (And Make them accessible over a Web server) Compile rmic -d FortuneServer Build the client side files Compile Copy FortuneServer_Stub.class to the client directory Running Unset CLASSPATH (no java classes should be reachable) Run RMI registry first start rmiregistry (optional port number) Set classpath It should see both Fortune.jar and remote object implementation Start the server start java -Djava.rmi.server.hostname=localhost -Djava.security.policy=java.policy FortuneServer localhost 17 18 Running Constructing a Stub Start the client Set CLASSPATH to include Fortuna.jar java -Djava.security.policy=java.policy FortuneClient localhost Naming creates a stub and stores it in the registry Identify the root class (getclass()) If the remote object implements an interface that extends Remote, then root class is remote object s class Otherwise, the highest superclass that implements an interface that extends Remote is the root class Name of stub=concat(binary_name_root_class, _Stub ) Classloader of root class will load the stub to JVM Stub must extend RemoteStub and must have a constructor whose one parameter is a RemoteRef RemoteRef ref=engine.getref(); Construct the class with RemoteRef ComputeEngine_Stub stub=new ComputeEngine_Stub(ref); 19 20 5