remote object invocation

22
Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology

Upload: woody

Post on 23-Feb-2016

45 views

Category:

Documents


0 download

DESCRIPTION

Remote Object Invocation. Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology. Outline. Distributed objects Binding client to object Static vs Dynamic Parameter passing Examples Java RMI. Why object-oriented ?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Remote Object Invocation

Remote Object Invocation

Tran, Van HoaiDepartment of Systems & Networking

Faculty of Computer Science & EngineeringHCMC University of Technology

Page 2: Remote Object Invocation

2009-2010 2

Outline

• Distributed objects– Binding client to object– Static vs Dynamic– Parameter passing

• Examples– Java RMI

Page 3: Remote Object Invocation

2009-2010 3

Why object-oriented ?

OO has strong features information hidingdata abstractionencapsulationmodularitypolymorphismand inheritance

OOP software engineering• Modelling• Design• Language• Database• Scripting• …

Page 4: Remote Object Invocation

Enhancement of RPC

• RPC– simple– effective– standard for communication in distributed system

development

Object Oriented + Remote Procedure Call = Remote Object Invocation

Page 5: Remote Object Invocation

Distributed object model (1)

Client OS

Client

ServerOS

Server

Clientinvokes a method

Skeleton invokes same method at object

Client machine Server machine

Proxy

Network

Proxysame interface as object

Marshalled invocation passed across network

Skeleton

interface

object

state

method

Page 6: Remote Object Invocation

Distributed object model (2)

• When a client binds to a distributed object, load the interface (“proxy”) into client address space– Proxy analogous to stubs

• Server stub is referred to as a skeleton

Page 7: Remote Object Invocation

Characteristics for distributed objects (1)

• Compile time vs runtime objects– compile time objects: related to language-level

objects• Object = instance of a class• Interfaces compiled into client, server’s stubs• Drawback: depend strongly on particular programming

language– runtime objects: how object implemented left

open• need an adapter to bind dynamically invocation to

implementation

Page 8: Remote Object Invocation

Characteristics for distributed objects (2)

• Persistent vs transient objects– persistent objects: not depend on server process• object can be stored in secondary storage if server exits• and restored when new server started

– transient objects: exists as long as server managing it

Page 9: Remote Object Invocation

Binding client to object

• Distributed object model provides systemwide reference– can be passed as parameters

• Binding needed before invoking methods– In practice, binding temporarily creates proxy– 2 approaches• Implicit binding• Explicit binding

Page 10: Remote Object Invocation

Implicit vs Explicit bindings

Implicit

Distr_object *obj_ref;obj_ref = ...;obj_ref->do_something();

Explicit

Distr_object *obj_ref;Local_object *obj_ptr;obj_ref = ...;obj_ptr = bind( obj_ref );obj_ptr->do_something();Explicit bind and get a pointer to proxy

Invoke a method on local proxy

Page 11: Remote Object Invocation

Object reference implementation issuses (1)

• Goal: to allow client binding to an object• Simple approach– reference = (network address, server ID, object ID)– server ID = port (in practice)

• Drawbacks– what happens if server machine crashes, and the

server has a new server ID ?• Client can contact with a service to provide mapping

between server ID and server• The server must register with the service

Page 12: Remote Object Invocation

Object reference implementation issuses (2)

• Drawbacks– what happens if the server moved to other

machine ?• a server to provide a mapping, called location server• reference = (location server address, systemwide server

ID)

Page 13: Remote Object Invocation

Remote Method Invocation

• Similar to RPC, but has an advantages of systemwide object reference

• static invocation:– predefined interface definition– interface known when client being developedfobject.append(int)

• dynamic invocation:– select at runtime which method to be invoked at remote

objectinvoke( fobject, id(append), int)

Page 14: Remote Object Invocation

Passing object references(local & remote)

local object O1 remote object O2

copy of O1 copy of R1 to O2

server code(method implementation)

remote reference R1

new local reference

remote invocation with L1 and R1 as parameters

client code with RMI to server at C

local reference L1

machine A machine B

machine C

Page 15: Remote Object Invocation

DCE Distributed object model

Dynamic (private) object

Dynamic (private) object

Dynamic (private) object

client #1 client #2 client #3

named (shared) object

remote reference

server machine server machine

Distributed dynamic objects Distributed named objects

• object created for individual client• a function “create()” to new an object

• object not for a single client• client looks up named object at directory service

Page 16: Remote Object Invocation

Java RMI

• Java RMI allows programmer to execute remote function class using the same semantics as local functions calls

Local Machine (Client)

SampleServer remoteObject;int s;…

s = remoteObject.sum(1,2);

System.out.println(s);

Remote Machine (Server)

public int sum(int a,int b) { return a + b;}

1,2

3

Page 17: Remote Object Invocation

Java RMI architecture• The server must first bind its

name to the registry• The client lookup the server

name in the registry to establish remote references.

• The Stub serializing the parameters to skeleton, the skeleton invoking the remote method and serializing the result back to the stub.

RMI Server

skeleton

stub

RMI Client

Registry

bind

lookupreturn call

Local Machine

Remote Machine

Page 18: Remote Object Invocation

Naming service (1)

• Directory that associates names to remote objects (bind)

server machine

RemoteObject

C

RemoteObject

A

RemoteObject

B

Naming

“X”

“Y”

“Z”

Page 19: Remote Object Invocation

Naming service (2)

• Client use Naming Service to find a particular Server object (lookup)

client machine server machine

ObjectClient

RemoteObjectServer

Naming

“X”

“Y”

“Z”

lookup(“Y”)

Remote reference to Server

Page 20: Remote Object Invocation

Steps for Developing an RMI System

1. Define the remote interface2. Develop the remote object by implementing the

remote interface.3. Develop the client program.4. Compile the Java source files.5. Generate the client stubs and server skeletons.6. Start the RMI registry.7. Start the remote server objects.8. Run the client

Page 21: Remote Object Invocation

Server/* SampleServerImpl.java */ public static void main(String args[]) { try { System.setSecurityManager(new RMISecurityManager()); //set the security manager

//create a local instance of the object SampleServerImpl Server = new SampleServerImpl();

//put the local instance in the registry Naming.rebind("SAMPLE-SERVER" , Server);

System.out.println("Server waiting....."); } catch (java.net.MalformedURLException me) { System.out.println("Malformed URL: " + me.toString()); } catch (RemoteException re) { System.out.println("Remote exception: " + re.toString()); } }

Page 22: Remote Object Invocation

Clientimport java.rmi.*;import java.rmi.server.*;public class SampleClient { public static void main(String[] args) { // set the security manager for the client System.setSecurityManager(new RMISecurityManager()); //get the remote object from the registry try { System.out.println("Security Manager loaded"); String url = "//localhost/SAMPLE-SERVER"; SampleServer remoteObject = (SampleServer)Naming.lookup(url); System.out.println("Got remote object"); System.out.println(" 1 + 2 = " + remoteObject.sum(1,2) ); } catch (RemoteException exc) { System.out.println("Error in lookup: " + exc.toString()); } catch (java.net.MalformedURLException exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); } }}