Distributed Computing: Remote Method Invocation - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Distributed Computing: Remote Method Invocation

Description:

It is a framework that translates between high level application abstractions ... unpack the message, find out which procedure is called and the parameters ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 47
Provided by: henrikbrba
Category:

less

Transcript and Presenter's Notes

Title: Distributed Computing: Remote Method Invocation


1
Distributed ComputingRemote Method Invocation
  • Distributed Objects

2
Distributed Objects
  • What we want
  • listener.update( statusEvent )
  • What we have
  • Send(byte) recieve(byte)

Update(statusEvent)
listener
Update(statusEvent)
2
3
Remote Method Invocation
  • RMI is what Tanenbaum and Steen calls a middle
    layer (middleware).
  • It is a framework that translates between high
    level application abstractions method calls
    between distributed objects into transport
    protocol layer primitives send and receive.
  • There are several challenges in this.

3
4
Challenges
  • Complex data types
  • Little endian/big endian integers
  • Floating point many different representations
  • Strings \0 terminated, etc.
  • Moving between abstraction levels
  • update(statusEvent) -gt bit array -gt
    update(statusEvent)
  • Representing method identity on the wire
  • Coding that it is update I want to call
  • Method calls have blocking semantics
  • The caller stops until callee has ended processing

4
5
Challenges
  • Object references
  • How to a get a reference to an object in the
    first place?
  • References only have meaning on the local machine
  • Unreliable network
  • Is the machine in the other end dead? Or the
    network is down?

5
6
Remote Procedure Call
7
A suggestion
  • Birrell and Nelson, 1984
  • allow calling procedure on remote machines
  • A call procedure x on B means
  • A suspends, information on x is transmitted to B
  • B executes the x procedure
  • B sends the result back to A
  • A resumes
  • Example on machine A
  • int x foo(x)
  • foo(int) is located on machine B

8
Translation Client stub
  • Idea
  • replace the library containing foo with a foo
    stub
  • Actually a proxy pattern but the stub term is
    the traditional one (bad do not mix it with test
    stubs!)

void foo(int x) translate parameter and
method info into message format transmit it to
B block in a receive() call until answer is
returned return answer in return message
9
Translation Server stub
  • Server side
  • block in a receive
  • upon message received
  • Often these code fragments are called skeletons

unpack the message, find out which procedure is
called and the parameters call the resulting
procedure pack the return value into a
message send it back to the origin
10
ORBs
  • The middleware layer are often called ORBs in RMI
    systems Object Request Broker

server node
client node
client
serverObj
ORB
ORB
11
Parameter passing conventions
  • Basically languages have two types of parameter
    passing. Ex. in C
  • int x foo( x ) pass-by-value
  • int x foo( x ) pass-by-reference
  • Exercise What do you have in Java?

12
Pass by Value
  • Pass-by-value
  • easy one simply code value into byte stream
  • (you get the right semantics in case the receive
    changes it!)
  • But but...
  • encoding! What is an integer? 16-bit? 32-bit?
    little endian/big endian.
  • Morale You HAVE to decide on the encoding.

13
Ex. CORBA IIOP
  • CORBA Common Object Request Broker Architecture
  • IIOP Internet Inter-ORB Protocol
  • defines the on the wire encoding and protocol
  • CDR Common Data Representation
  • how many bits are an integer little endian?
  • Message Format
  • how to we pack the message with the information
  • Transport layer assumptions
  • do we use TCP/IP or UPD or ???

14
Terminology
  • Marshalling
  • Encoding parameters into the message format
  • Unmarshalling
  • Decoding

15
Pass by Reference
  • Tricky! My options are
  • A) forbid pointers and reference parameters!
  • what does memory address 0x00056 mean on another
    machine?
  • B) replace pass-by-reference with copy/restore
  • copy a memory area into the message
  • let Bs foo work on a copy of the memory area on
    B
  • ship a copy of the memory area back to A
  • copy the received memory area into that on A
  • C) pass references to remote objects
  • i.e. any method call is a remote call on a remote
    object
  • RMI uses option C)

16
RMI
  • ... getting the last pieces in place

17
Object References
  • Procedures are global whereas methods are local
    to an object.
  • Program to an interface comes to our rescue!
  • The caller only needs to know the interface of
    our object on the remote location.

18
Proxy
  • A proxy can inherit the same interface as the
    real object (i.e. implement the same methods)
    but simply pass the calls on and block just as
    in the RPC case.
  • Logical

foo(x)
19
What really happens
  • The client invokes a method on a proxy. The proxy
    marshals the message to the skeleton on the
    server side.

ltltinterfacegtgt Server foo()
Client
ServerProxy
ServerSkeleton
ServerImpl
20
Dynamics (CORBA)
21
Interfaces?
  • In Java interfaces are well known and found in
    the language. But what if we need a refernce to a
    remote object code in C, Cobol, or C?
  • IDL Interface Definition Language
  • OMG Standard for declaring interfaces
  • Works well with CORBA (also supported by Java)
  • Also part of MicroSoft DCOM.

22
IDL eksempel
module SalesChart interface Observer
void update() string uniqueIdentity()
interface SalesChart void addSale(
in string person, in long amount ) long
sumSales( ) long mySales( in string person
) void attach( in Observer obs ) void detach(
in Observer obs )
module er et heterogent navnerum!
23
Last bits of the puzzle
  • Summary
  • we can marshal and unmarshal
  • can translate in and out of bit streams
  • we have proxies and skeletons
  • can translate from OO methods to messages
  • but how do I get the reference to the server
    object?

24
Registry
  • We need a separate process that holds a mapping
    between abstract names (often strings) and remote
    references
  • Basically a dictionary/associate array/map
  • (key,value) (name, remote reference)
  • CORBA Naming Service
  • Java RMI Registry (part of JDK)
  • Tanenbaum Location server

25
Network Failures
  • All method calls may fail when distributed
  • Java exception handling mechanism comes in handy.
  • RemoteException!

26
Parameter types
  • Pass by reference ( object references in java)
  • proxy/skeleton pairs
  • Pass by value
  • do you have any idea?
  • Hint you need to translate object state into a
    streamable format. Java already supports this!

27
Example
  • Echo Server

28
Declaring the interface
  • Must import java.rmi.
  • Must extend Remote
  • Methods must throw RemoteException

29
Binding to the server
  • You need to
  • install a security manager
  • ask the registry for the remote reference using a
    name in URL form //localhost/EchoServer

30
The Server
  • Server object that exists first
  • extend UnicastRemoteObject
  • tell my name to registry
  • Alternative export it
  • UnicastRemoteObject.exportObject(obj,port)
  • and tell registry
  • Exercise
  • What is the advantage ofthe second form?

31
Object references from here on
  • Once two objects have established contact by
    rebind/bind over the registry they may exchange
    object references as they like
  • Either remote references or by-value references.
  • But note that the semantics is different from
    that of normal Java when pass by value! Tricky
    errors occur!

32
Running
  • Remember to start the registry first!
  • start rmiregistry
  • start ant runSesrver
  • start ant runClient

33
How to make it
  • We need to generate the proxy
  • rmic rmi compiler
  • We need to set the security settings...

ltltinterfacegtgt Server foo()
Client
ServerProxy
ServerSkeleton
Java 5 onwards Not necessary!
ServerImpl
34
Rmic compiler
  • rmic - The Java RMI Compiler
  • rmic generates stubs, skeletons, ties for remote
    objects using either the JRMP or IIOP protocols.
    Also generates OMG IDL.

35
RMIC
  • RMIC require a class file for generating the stub
    files.
  • Thus you must compile all files first
  • Next call the RMIC on the .class file that
    represents the implementation of the remote
    interface
  • Here EchoServer
  • Bit backwards ? - The clients proxy (stub) is
    generated by the final server implementation
  • Therefore EchoServer_stub

36
Peeking behind the curtain
  • -keep

37
Security
  • Tell which security policy to use
  • And define that policy a lenient one here ?

38
Codebases
39
Why hostname and codebase?
  • When the client is passed a reference of a remote
    object it must get hold of an implementation of
    the remote interface the stub class (i.e. the
    proxy ?)
  • Java use dynamic class loading and simply request
    the stub implementation from the server
  • give me the stub that allows me to talk to the
    remote object reference that you gave me
  • The hostnamecodebase tell the server the URL to
    feed to the client the client then dynamically
    loads the classes from that URL.
  • Quite cool but a bit tricky ?

40
Concurrency
41
?
  • Distributed programs are inherently concurrent
    systems.
  • Consider two echo clients that invoke echo on
    the server at the very same time.
  • Exercise what happens?

42
Critical Regions
  • Therefore we have to declare critical regions
    using the synchronized keyword.
  • The question is where?
  • On the proxy?
  • On the server?
  • What is the right answer here?

43
RMI Spec
  • From the RMI spec
  • A method dispatched by the RMI runtime to a
    remote object implementation may or may not
    execute in a separate thread. The RMI runtime
    makes no guarantees with respect to mapping
    remote object invocations to threads. Since
    remote method invocation on the same remote
    object may execute concurrently, a remote object
    implementation needs to make sure its
    implementation is thread-safe.

44
Summary
45
Problem Statement
  • Complex data types
  • Little endian/big endian integers
  • Floating point many different representations
  • Strings \0 terminated, etc.
  • Moving between abstraction levels
  • Update(statusEvent) -gt bit array -gt
    update(statusEvent)
  • Representing method identity on the wire
  • Coding that it is update I want to call
  • Method calls have blocking semantics
  • The caller stops until callee has ended processing

45
46
Problem Statement
  • Object references
  • How to a get a reference to an object in the
    first place
  • References only have meaning on the local machine
  • Unreliable network
  • Is the machine in the other end dead? Or the
    network is down?

46
Write a Comment
User Comments (0)
About PowerShow.com