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

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

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

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

Generic architecture

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

JAVA RMI. Remote Method Invocation

Distributed Objects SPL/ SPL 201 / 0 1

Distributed Systems. 5. Remote Method Invocation

Verteilte Systeme (Distributed Systems)

5.4. Events and notifications

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

Remote Method Invocation

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

Last Class: Network Overview. Today: Distributed Systems

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

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

Distributed Systems COMP 212. Lecture 10 Othon Michail

Remote Objects and RMI

RMI. (Remote Method Invocation)

Remote Procedure Call

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

IBD Intergiciels et Bases de Données

Written by: Dave Matuszek

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

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

Distributed Computing

Remote Method Invocation

RMI. Remote Method Invocation. 16-Dec-16

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

CS 5523 Operating Systems: Remote Objects and RMI

RMI Case Study. A Typical RMI Application

presentation DAD Distributed Applications Development Cristian Toma

Remote Method Invocation

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

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

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

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

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

Programming with RMI Reminder

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

RPC and RMI. 2501ICT Nathan

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

Remote Method Invocation Benoît Garbinato

Remote Method Invocation. Benoît Garbinato

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

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

Chapter 4 Remote Procedure Calls and Distributed Transactions

Distributed Software Systems

Communication and Distributed Processing

RMI: Design & Implementation

Lecture 06: Distributed Object

Component-Based Software Engineering

Course Snapshot. The Next Few Classes

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

CSci Introduction to Distributed Systems. Communication: RPC In Practice

Lecture VI: Distributed Objects. Remote Method Invocation

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

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

Distributed object component middleware I - Java RMI

Communication and Distributed Processing

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

Distributed object component middleware I - Java RMI

DISTRIBUTED COMPUTING

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

Lecture 5: RMI etc. Servant. Java Remote Method Invocation Invocation Semantics Distributed Events CDK: Chapter 5 TVS: Section 8.3

Chapter 5 Distributed Objects and Remote Invocation

5 Distributed Objects: The Java Approach

Distributed Objects. Chapter Distributing Objects Overview

Distributed Information Systems

Lecture 5: Object Interaction: RMI and RPC

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 Objects and Remote Invocation. Programming Models for Distributed Applications

RMI Example RMI. CmpE 473 Internet Programming RMI

JAVA RMI Java, summer semester

Remote Method Invocation in Java

CS193k, Stanford Handout #12. Threads 4 / RMI

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

A Typical RMI Application

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

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

Architecture of So-ware Systems RMI and Distributed Components. Mar<n Rehák

Distributed Systems Lecture 2 1. External Data Representation and Marshalling (Sec. 4.3) Request reply protocol (failure modes) (Sec. 4.

CC755: Distributed and Parallel Systems

Modulo II Socket, RMI e Corba

Remote Invocation Vladimir Vlassov and Johan Montelius

Distributed Systems. Communication (2) Schedule of Today. Distributed Objects. Distributed Objects and RMI. Corba IDL Example

Interprocess Communication

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

A Typical RMI Application. Case Study

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

Distributed Programming in Java. Distribution (2)

Distributed Systems. Communication (2) Lecture Universität Karlsruhe, System Architecture Group

Remote Method Invocation Java RMI & Web-Services

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

CSC 634: Networks Programming

BEA WebLogic. Server. Programming WebLogic RMI

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

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

Transcription:

Introduction Objective To support interoperability and portability of distributed OO applications by provision of enabling technology Object interaction vs RPC Java Remote Method Invocation (RMI) RMI Registry Security Manager References Latest Java documentation from http://java.sun.com/ Java Remote Method Invocation Specification JDK 1.4 Tutorials: http://java.sun.com/docs/books/tutorial/rmi/index.html http://developer.java.sun.com/developer/onlinetraining/rmi/rmi.html Couloris ch. 5, Boger ch. 4, Tanenbaum 2.3 1 vs. RPCs Encapsulation via fine to medium grained objects (e.g. threads or C++ objects) Data and state only accessible via defined interface operations RPC based systems encapsulation via OS processes Portability of objects between platforms RPC clients and servers are not usually portable Typed interfaces Object references typed by interface bind time checking RPC interfaces often used in languages which do not support type checking Object can support multiple interfaces (depending on platform) RPC components have single interface Support for inheritance of interfaces Use inheritance to extend, evolve, specialise behaviour. New server objects with extended functionality (subtypes) can replace existing object and still be compatible with clients. RPC replacements must have identical interface usually no inheritance. 2 vs. RPCs (2) Interaction Types Two-way synchronous invocation c.f. RPC Java Pass objects as invocation parameters (Java only) Parameterised invocation exceptions Simpler error handling Location transparency Service use orthogonal to service location Access transparency Remote and co-located services accessed by same method invocation. RPC only used for remote access. Use invocations to create/destroy objects RPC systems (often) use OS calls to create/destroy processes 3

Java RMI Architecture Transparent Invocation Marshall & unmarshall parameters serialisation Translate local reference to stub into remote reference to object on local or remote server, e.g. unicast or multicasts to replicas Send and receive messages Client Program Stub Remote Reference Transport Logical Interaction TCP/IP Internet See http://java.sun.com/docs/books/tutorial/rmi/index.html Program Skeleton Remote Reference Transport Host Client Pass objects by reference or by value as parameters Download code required for remote invocation dynamic stub Invocation Interface Invocation Host Interface Local Remote 4 5 Java Interfaces Java is a class-based OO programming language Supports single inheritance A Java interface is essentially an abstract class and defines a new type a collection of methods (and constant definitions) methods and constants declared in an interface are implicitly public An interface may be derived from one or more further interfaces A class can implement one or more interfaces as well as being derived from at most one other class 6 Remote Interface 1 A type whose interfaces may be invoked remotely is defined as a remote interface A remote interface extends the java.rmi.remote and must be public The methods of a remote interface must be defined to throw the exception java.rmi.remoteexception for comms failures import java.rmi.* public interface Calculator extends Remote { public long add(long a, long b) public long sub(long a, long b) public long mul(long a, long b) public long div(long a, long b) 7

Client Interaction Remote Objects Client calc Client Stub Lookup( rmi://../calculator ) Stub address Get stub Stub Invoke method calc Response Registry calcstub. class Skeleton Remote objects are instances of classes that implement remote interfaces eg. CalculatorImpl implements Calculator Coulouris calls them servants A remote object class simply implements the methods defined in the remote interface Remote objects execute within a server which may contain multiple remote objects An object is implicitly exported if its class derives from java.rmi.server.unicastremoteobject Note operations invoked on remote objects, not on server containing them. calcimpl.class Note: skeleton not needed in later versions of Java 8 9 Remote Object Implementation import javarmi.* public class CalculatorImpl extends UnicastRemoteObject implements Calculator { public CalculatorImpl() throws RemoteException { super(); Call to super activates code in UnicastRemoteObject for RMI linking & object initialisation public long add(long a, long b) throws RemoteException { return a + b; public long sub(long a, long b) throws RemoteException { return a - b;... 10 UnicastRemoteObject constructor exports the object as single server not replicated Implementation A server program creates one or more remote objects as part of mainline code. For simple single object applications it is possible to combine server and object implementation. A server may advertise references to objects it hosts via the local RMI registry Registry allows a binding between a URL and an object reference to be made and subsequently queried by potential clients The server listens for incoming invocation requests which are dispatched to appropriate object. Note: there may be multiple servers and multiple clients within an application Client is not created within a server. 11

Mainline code import java.rmi.naming; public class Calculator { public static void main(string args[]) { if System.getSecurityManager() == null { System.setSecurityManager (new RMIsecurityManager ()); Create security manager try { Calculator c = new CalculatorImpl(); Create server object Naming.rebind("rmi://localhost/CalcService", c); Register it with the local registry: URL-reference binding catch (Exception e) { System.out.println("Trouble: " + e); 12 Calculator Client Implementation import java.rmi.*; import Calculator; public class CalculatorClient { public static void main(string[] args) { try { if System.getSecurityManager() == null { System.setSecurityManager (new RMIsecurityManager ()); Calculator c = (Calculator) Naming.lookup( "rmi://remotehost/calcservice"); Get ref to Calc stub from remote registry System.out.println( c.sub(4, 3) ); Invoke sub operation on remote calculator... other calls ; catch (RemoteException e) { System.out.println( Exception: + e); 13 RMIRegistry Must run on every server computer hosting remote objects Advertises availability of s remote objects name is a URL formatted string of form //host:port/name Both host and port are optional lookup (String name) called by a remote client. Returns remote object bound to name bind(string name Remote obj) Called by a server binds name to remote object obj Exception if name exists rebind(string name Remote obj) binds name to object obj discards previous binding of name (safer than bind) String [] list() returns an array of strings of names in registry unbind(string name) removes a name from the registry Using Registry remote object making itself available Registry r = Locateregistry.getRegistry(); r.rebind ( myname, this) Remote client locating the remote object Registry r = LocateRegistry.getRegistry( thehost.site.ac.uk ); RemObjInterface remobj = (RemObjInterface) r.lookup ( myname ); remobj.invokemethod (); 14 15

RMI Security Manager Parameter Passing Single constructor with no arguments System.setSecurityManager(new RMISecurityManager()); Needed in server and in client if stub is loaded from server Checks various operations performed by a stub to see whether they are allowed eg Access to communications, files, link to dynamic libraries, control virtual machine, manipulate threads etc. In RMI applications, if no security manager is set, stubs and classes can only be loaded from local classpath protect application from downloaded code Clients always refer to remote object via remote interface type not implementation class type A reference to a remote object can be passed as a parameter or returned as a result of any method invocation Remote objects passed by reference stub for remote object is passed Given two references, r1 and r2, to a remote object ( transmitted in different invocations): r1 == r2 is false different stubs r1.equals (r2) is true stubs for same remote object Parameters can be of any Java type that is serializable primitive types, remote objects or objects implementing java.io.serializable Non-remote objects can also be passed and returned by value i.e. a copy of the object is passed new object created for each invocation 16 17 Garbage Collection of Remote Objects RMI runtime system automatically deletes objects no longer referenced by a client When live reference enters Java VM, its reference count is incremented First reference sends referenced message to server After last reference discarded in client unreferenced message sent to server. Remote object removed when no more local or remote references exist. Network partition may result in server discarding object when still referenced by client, as it thinks client crashed Single method interface Dynamic Invocation Invocation identifies method to be called + parameters User programs marshalls/demarshalls parameters Optional invocation primitive for object environments such as CORBA and for Web services. public byte[] dooperation (RemoteObjectRef o, int methodid, byte[] arguments) Sends a request message to the remote object and returns the reply. The arguments specify the remote object, the method to be invoked and the arguments of that method. has to decode request and call method 18 19

Summary RMI provides access transparency, object oriented concepts for IDL specification, object invocations and portability. Inheritance supports reuse high level programming concepts High implementation overheads due to Byte code interpretation in Java Marshalling/Demarshalling of parameters Data copying Memory management for buffers etc. Demultiplexing and operation dispatching 20