Remote Method Invocation

Similar documents
JAVA RMI. Remote Method Invocation

Generic architecture

Remote Method Invocation

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

Remote Method Invocation

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

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

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

IBD Intergiciels et Bases de Données

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

DISTRIBUTED OBJECTS AND REMOTE INVOCATION

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

presentation DAD Distributed Applications Development Cristian Toma

RMI. Remote Method Invocation. 16-Dec-16

Written by: Dave Matuszek

Remote Procedure Call

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

Remote Method Invocation in Java

CS 5523 Operating Systems: Remote Objects and RMI

Distributed Computing

Introduction & RMI Basics. CS3524 Distributed Systems Lecture 01

RMI. (Remote Method Invocation)

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

DISTRIBUTED COMPUTING

Remote Objects and RMI

RMI Example RMI. CmpE 473 Internet Programming RMI

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

RMI Case Study. A Typical RMI Application

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

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

5.4. Events and notifications

Distributed Objects SPL/ SPL 201 / 0 1

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

Distributed Systems. 6. Remote Method Invocation. Werner Nutt

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

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

Last Class: Network Overview. Today: Distributed Systems

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

Distributed Systems. 5. Remote Method Invocation

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

Lecture VI: Distributed Objects. Remote Method Invocation

JAVA RMI Java, summer semester

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

Component-Based Software Engineering

Verteilte Systeme (Distributed Systems)

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

COMP 6231: Distributed System Design

CC755: Distributed and Parallel Systems

Remote Invocation Vladimir Vlassov and Johan Montelius

CSci Introduction to Distributed Systems. Communication: RPC In Practice

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


Developing RMI Based Server (ChatServer)

SUMMARY INTRODUCTION REMOTE METHOD INVOCATION

Programming with RMI Reminder

A Typical RMI Application

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

Distributed object component middleware I - Java RMI

Distributed Software Systems

Distributed Systems COMP 212. Lecture 10 Othon Michail

CS193k, Stanford Handout #12. Threads 4 / RMI

Distributed object component middleware I - Java RMI

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

Chapter 4 Remote Procedure Calls and Distributed Transactions

Communication and Distributed Processing

Remote Method Invocation. Benoît Garbinato

Remote Method Invocation Benoît Garbinato

A Typical RMI Application. Case Study

Communication and Distributed Processing

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

EAST WEST UNIVERSITY

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

Course Snapshot. The Next Few Classes

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

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

BEA WebLogic. Server. Programming WebLogic RMI

THE RMI PROXY USER GUIDE

Activation of remote objects

COMMUNICATION PROTOCOLS: REMOTE PROCEDURE CALL (RPC)

BEA WebLogic Server. Programming WebLogic RMI

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

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

Bharati Vidyapeeth s Institute of Computer Applications and Management A-4, Paschim Vihar, New Delhi-63.

Reflection (in fact, Java introspection)

Remote Method Invocation R.M.I.

Modulo II Socket, RMI e Corba

Distributed Programming in Java. Distribution (2)

Reflection/RMI 4/28/2009

IJESRT. http: //

Lecture 18 Inside Java 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

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

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

A Report on RMI and RPC Submitted by Sudharshan Reddy B

Chapter 5 Distributed Objects and Remote Invocation

Lecture 17 Java Remote Method Invoca/on

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

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

5 Distributed Objects: The Java Approach

Transcription:

Non-101samples available here: https://github.com/101companies/101repo/tree/master/languages/aspectj/javarmisamples Remote Method Invocation Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team http://101companies.org/wiki/ Contribution:javaRmi

Elevator speech What if the objects of interests are no longer located on the same computer, i.e., the objects are distributed instead? How to communicate between different computers in an OOP-friendly manner? Basically, we want to continue to hold references to objects (perhaps remote objects), and send them messages (i.e., perform method calls) as before. We will be looking into Java RMI as a technology of choice. Alternative options include Corba, WebServices, and SOA.

Non-distributed programming Caller and callee are on the same machine. Object1 (Client) MyMachine Method Invocation - Arguments are evaluated. - Caller location is pushed onto stack. - Callee method is executed. - Result is returned. - Caller location resumes. Object2 (Server) MyMachine

Distributed programming Caller and callee are on different machines. Object1 (Client) Remote Method Invocation Client holds on a server proxy. Args + result go over the network. Object2 (Server) Host mymac.foo.edu Host myserver.bar.edu In demo code, client and server may be on the same machine, perhaps even on the same JVM, but the invocation is handled (conceptually) over the network.

A first look at the hello world of RMI DEMO See package helloworld of javarmisamples (see 1st slide). Start the server as described in Makefile. Start the client by running the Client class. Observe how 42 was remotely incremented.

A more interesting scenario: a banking application to access account data remotely at a teller (ATM). Customer Teller Bank Account Host koblenz1.db.de Host server.db.de

Communication between different Java runtimes on the same machine or different machines, eventually involves the network layer of the OS. JRE JRE Host OS Network layer JRE JRE Host OS Network layer network cable

Stubs and skeletons Client invokes a remote method on stub object. The stub sends the call to the server-side skeleton. That is, the stub: opens a socket to the remote server, marshals the method parameters, forwards the data stream to the skeleton, awaits and unmarshals result data stream from skeleton. The skeleton contains a method that: receives the remote calls, unmarshals the method parameters, invokes the actual remote (by now, local) implementation, and marshals the result and delivers it back to the stub.

Remote-method invocation Same interface as remote object Serialized method name, parameters and return value Object1 (Client) Remote Remote odd(3) Object Object Stub: 01101 Skeleton serves as odd(3) Remote true Reference 10010 true Object2 (Server) Host mymac.foo.edu Host myserver.bar.edu

Parameters and return values Remote objects by reference Serializable objects by copy Others cannot be passed (exception)

How to refer to / look up remote objects? We need a naming service! A server-side directory that associates remote objects with names (URLs) Naming X Y Z Host myserver.bar.edu Remote Object A Remote Object B Remote Object C

Naming service cont d lookup( Y ) Remote reference to server Naming X Y Z ObjectY Host mymac.foo.edu Host myserver.bar.edu

Designing a client/server app (Summary) Server Bind 1+ service objects via registry Client Looks up and interacts with service objects For example (see helloworld demo): Service: increment operation

Designing a client/server app (Detailed steps) 1. Design an interface for service (remote object). 2. Implement the service. 3. (Generate stub and skeleton classes.) 4. Implement a server to contact for binding. Done automatically. 5. Implement a client to invoke service. 6. Start the server. 7. Run the client.

Step 1: Design an interface for service (remote object). import java.rmi.remote; import java.rmi.remoteexception; public interface Service extends Remote { } public long inc(long x) throws RemoteException; This is a regular interface except for the special base interface and the special throws declaration.

Step 2: Implement the service. import java.rmi.server.unicastremoteobject; import java.rmi.remoteexception; public class ServiceImpl extends UnicastRemoteObject implements Service { // Needed for serialization private static final long serialversionuid = 6102178242852627613L; // Needed because of exception public ServiceImpl() throws RemoteException { super(); } } public long inc(long x) throws RemoteException { return ++x; }

Step 4: Implement a server to contact for binding. import java.rmi.naming; public class Server { public Server() { try { Service s = new ServiceImpl(); Naming.rebind("rmi://localhost/Service", s); } catch (Exception e) { System.out.println("Trouble: " + e); } } Remote object Register with naming service } public static void main(string args[]) { new Server(); }

Name format for binding rmi://<host_name> [:<name_service_port>] /<service_name> Thus, URLs of a specific form are used for addressing remote objects.

Availability of registry Binding requires that the registry is locally running. Registry can be started programmatically as follows: import java.rmi.registry.locateregistry; import java.rmi.registry.registry; LocateRegistry.createRegistry(Registry.REGISTRY_PORT); Default TCP/IP port: 1099

Usage of localhost localhost may fail to work in binding. This depends on the network configuration. Alternatively, one can use the following idiom: InetAddress addr = InetAddress.getLocalHost(); String hostname = addr.gethostname(); Naming.rebind("rmi://"+hostname+"/Service", s);

Step 5: Implement a client to invoke service. import java.rmi.naming; public class Client { } public static void main(string[] args) { try { Service s = (Service) Naming.lookup("rmi://localhost/Service"); System.out.println(s.inc(41)); } catch (Exception e) {... } }

Step 6: Start the server. If you are using Eclipse, you cannot (easily) run both server and client simultaneously from within Eclipse. One of the two would be started from the command line. JavaRmi> java helloworld.server One may want to run the server (and the client) with a security policy. Server must be killed, e.g., with CTRL-C

Step 7: Run the client. JavaRmi> java helloworld.client 42

Components of an RMI-based application Services of remote objects (interfaces) Implementation of services (classes) Proxies for client-side (classes, generated) A server that binds services (class) A client that looks up services (class) The RMI registry (component of RMI layer) Security policies for client and server (optional)

Security of RMI Useful constrains: Service provision ( May an app provide services? ) Naming lookups ( May an IP address look up services? ) Remote invocations ( May an IP address invoke...? ) Use a non-default security manager: System.setSecurityManager(new SecurityManager()); Assign a security policy to an application: java -Djava.security.policy=mySecurity.policy Server

An RMI-based banking app DEMO A non-c/s-based version as a reference: package banking.local. The C/S-based version: package banking.remote. Think of a refactoring to derive the latter from the former.

http://101companies.org/wiki/ Contribution:javaRmi DEMO This implementation is interesting in so far that it readies all data objects for RMI. Further, the operation total is provided as a service, but cut is not. Thus, the client must implement cut, which essentially means that all company, department, and employee objects end up as proxies on the client.

Summary RMI easily blends with OOP. A simple form of distributed programming is enabled this way. Client/Server applications are enabled this way. RMI semantics and concepts: Use local proxy objects for access to remote objects. Un-/marshal arguments and results for messages on the wire. Bind objects to names (URLs) that can be used for lookup. RMI programming idioms: Remote objects are looked up from server-side registry. Remote objects may also be returned by RMI calls. Remote objects may be created by factory methods. Omissions: Multiplicity of clients Other distribution technologies: Corba, WebServices, SOA, HTTP,...