Lect 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Lecture 5

Communication:
• RPC
• RMI
• Message Oriented Middleware
• Streams

By: Dr. Aymen J. Salman


2019-2020
Background
Basis for Comparison Call By Value Call By Reference
Basic A copy of the variable is passed. A variable itself is passed.

Change in a copy of variable doesn't


Change in the variable affect the value of variable
Effect modify the original value of variable out
outside the function also.
side the function.

function_name (&variable_name1,
function_name (variable_name1, &variable_name2, . . . .);
Calling Parameters
variable_name2, . . . .); //in case of object
object.func_name( object);

type function_name ( type *variable_name1, type


*variable_name2, . . . .)
type function_name (type
{..}
variable_name1, type variable_name2, . . .
Receiving Parameters //in case of object
.)
type function_name(class_type object_name)
{..}
{..}

Primitive type are passed using "call by Objects are implicitly passed using "call by
Default calling
value". reference".
Conventional Procedure Call
Parameter passing in a local
procedure call:

(a) the stack before the call to


read.
(b) The stack while the called
procedure is active.

3
Remote Procedure Call (RPC)

Java
Basic RPC Parameter Remote
operation passing Variations Method
Invocation
(RMI)

4
Remote Procedure Call (RPC)
q An RPC is analogous to a function call.
Like a function call, when an RPC is
made, the calling arguments are
passed to the remote procedure and
the caller waits for a response to be
returned from the remote procedure.
The client makes a procedure call that
sends a request to the server and
waits.

q A stub in distributed computing is a


piece of code that converts parameters
passed between client and server
during a remote procedure call (RPC).
The main idea of an RPC is to allow a
local computer (client) to remotely call
procedures on a different computer
(server). The stub on the server side
called Skeleton
Basic RPC Operation (1/3)
Observations:
• Application developers are familiar with simple procedure model
• Well-engineered procedures operate in isolation (black box)
• There is no fundamental reason not to execute
procedures on separate machine
Conclusion: communication between caller & callee can be
hidden by using procedure-call mechanism.

6
Basic RPC Operation (2/3)

7
Basic RPC Operation (3/3)
1. Client procedure calls client stub as 6. Server does work and returns
usual. result to the stub.
2. Client stub builds message and 7. Server stub packs it in message
calls local OS. and calls OS.
3. Client’s OS sends message to 8. Server’s OS sends message to
remote OS. client’s OS.
4. Remote OS gives message to 9. Client’s OS gives message to
server stub. client stub.
5. Server stub unpacks parameters 10. Client stub unpacks result and
and calls server. returns to the client.

8
RPC: Parameter Passing (1/2)
q Parameters marshaling is one of the main tasks in
parameter passing. That should be done to prepare
parameters for passing

v Parameter marshalling means wrapping parameters into a


message
v Wrapping a parameter means transforming a value into a
sequence of bytes. Wrapping should take care of:

v Client and server machines may have different data


representations (think of byte ordering). They have to agree on
the same encoding:
v Client and server need to properly interpret messages,
transforming them into machine-dependent representations.

9
RPC: Parameter Passing (2/2)
RPC parameter passing:
• RPC assumes copy in/copy out semantics: while
procedure is executed, nothing can be assumed about
parameter values.
• RPC assumes all data that is to be operated on is passed
by parameters (not by value). Excludes passing
references to (global) data.

Conclusion: full access transparency cannot be realized.

Observation: If we introduce a remote reference mechanism,


access transparency can be enhanced:
– Remote reference offers unified access to remote data
– Remote references can be passed as parameter in RPCs
10
Asynchronous RPCs
Essence: Try to get rid of the strict request-reply behavior,
but let the client continue without waiting for an answer
from the server.

Variation: deferred synchronous RPC:

11
Client-to-Server Binding (DCE)
Issues: (1) Client must locate server machine, and (2) locate
the server.
Example: DCE uses a separate daemon for each server
machine.

13
Remote Method Invocation (RMI)
RMI

q RMI just like RPC is used as a mechanism which enable a client to invoke the
procedure or method from the server through establishing communication
between client and server.
q The common difference between RPC and RMI is that RPC only supports
procedural programming whereas RMI supports object-oriented
programming.
Remote Method Invocation (RMI) Basics
Assume client stub and server skeleton are in place
Client
RemoteObj obj = lookup(10.10.10.10:2020)
int result = obj.remoteMethod(var1, var2);
7 1

RemoteObj Stub

TCP packet: result 2 TCP Packet: obj, var1, var2


3

Server
RemoteObj Skeleton
result
6
call 4
obj
int remoteMethod(type1, type2) 5

16
Remote Method Invocation Basics
1. Client invokes method at stub

2. Stub marshals request and sends it to server

3. Server ensures referenced object is active:


1. Create separate process to hold object
2. Load the object into server process

4. Request is unmarshaled by object’s skeleton, and referenced


method is invoked

5. If request contained an object reference, invocation is applied


recursively (i.e., server acts as client)

6. Result is marshaled and passed back to client

7. Client stub unmarshals reply and passes result to client application

17
RMI Parameter Passing
Object-by-value: A client may also pass a complete object
as parameter value:
• An object has to be marshaled:
– Marshall its state
– Marshall its methods, or give a reference to where an
implementation can be found

• Server unmarshals object. Note that we have now created


a copy of the original object.

• Object-by-value passing tends to introduce nasty


problems

18
RMI

v RMI was built based on Java.

v In Java the parameters are passed to methods and returned in the form of
reference. So, RMI uses call by reference for objects passing. But, this is
problematic for an RMI facility, because not all objects can be remote
objects?.

v Not all JVMs are willing to expose any of their objects. So, it must
determine which could be passed as reference and which could not.

v For objects that cannot be passed as reference Java uses process named
serialization where the objects are passed as value.
RPC vs RMI

RPC RMI
Procedural Object-oriented
Programming Type
programming programming
Parameters Ordinary data passed to remote Objects are passed to
structures are procedures remote methods.
Efficiency Low High
Overheads High Less
In-out parameters are
Yes Not necessarily
mandatory
Provision of ease of
High Low
programming
Others: CORBA

• https://corba.org
• Multi-language support (COBOL, Ada, Lisp, Java, Python,
etc.)
• Legacy technology, but still works

22

You might also like