Distributed Systems: Concepts and Design

clumpsmackoverSoftware and s/w Development

Dec 2, 2013 (3 years and 6 months ago)

73 views

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

1



Interprocess Communication
and Middleware

Yih
-
Kuen Tsay

Dept. of Information Management

National Taiwan University

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

2

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Node 1

Node 2

Sockets and Ports

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

3

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Sockets and Ports

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

4


Higher
-
level abstractions (RPC, RMI, …)


Location transparency


Independent of communication protocols


Independent of hardware/operating systems


Use of several programming languages


Purposes of Middleware

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

5

Local vs. Remote Modules


Variables


Variables of a remote module cannot be
directly

accessed.


Parameter
-
passing Mechanisms


Call by reference, for input parameters, is not feasible
for a remote procedure/method.


Pointers


Pointers of a remote module are not very useful for the
local module.


* For a module in some process, any other module in a
different
process
, not necessarily a different
computer
,
is a
remote module
.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

6

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

* The operating system includes common network protocols (TCP/IP, …).

The Middleware layer

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

7

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Marshalling (Serialization) in
CORBA CDR

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

8

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Request
-
Reply Communication

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

9


What causes a timeout for
doOperation
?


What should
doOperation
do after a timeout?


How should duplicate request messages be
handled?


What should the server do if a reply message has
been lost?


Idempotent operation


History


Some of the above problems still exist even if one
uses TCP.

Dealing with Communication
Failures

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

10

Source of figures: G. Coulouris et al.,
Distributed Systems: Concepts and Design

An HTTP
request
message:

An HTTP
reply
message:

HTTP is not only a request
-
reply protocol but also has been

used as the transport of other request
-
reply protocols.

Request
-
Reply Communication
Using HTTP

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

11

The Distributed Object Model


Client/Server: two
-
tier, three
-
tier, etc.


Interfaces and Interface Definition
Languages (IDLs)


Object References (or Identifiers)


Remote Method Invocation (RMI)


Garbage Collection


Exceptions (in particular, timeouts)

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

12

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Interactions among Distributed
Objects

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

13

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Interactions among Distributed
Objects (cont.)

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

14

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

A client proxy is also known as a client stub and server skeleton as server stub.

The remote reference module is mainly for translating between local and remote

object references.

A Remote Object and Its
Interface

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

15

The RMI Software


Proxy
: the local representative of the
remote object.


Dispatcher
: relays a request to the
appropriate skeleton method.


Skeleton
: unmarshals the request and
invokes the corresponding method in the
remote object.


These RMI components are generated
automatically by an interface compiler.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

16

Source of the table: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Remote invocations may be made syntactically identical to local

invocations, but they have far more implications that both the client and

the server designers have to deal with.

RMI/RPC Semantics and
Transparency

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

17

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

A CORBA IDL Example

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

18

Issues for RMI


Object Activations


Active vs. passive objects


Persistent Objects


Passivation, permanent deletion, …


Object Location


Garbage Collection


Cooperation between a local proxy and its server


Leases


Synchronization, Replication, Migration, …

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

19

Events


An
event

is an action performed that may
cause changes to the state of an object.


For instance, pushing a button or entering a
piece of text is an event.


The state change of an object may trigger
state changes of other objects.


Objects responsible for state changes are

notified

of the event.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

20

Event
-
Based Systems


The
publish
-
subscribe

paradigm


An object that generates events
publishes

the type of
events.


Other objects
subscribe

to the type of events of interest.


A publisher sends subscribers a
notification

----

an
object representing a subscribed event, when the
represented event occurs.


Two main characteristics:


Heterogeneous: with suitable RMI interfaces for
receiving notifications


Asynchronous: decoupling publishers and subscribers

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

21

Dealer’s computer

Information

provider

Dealer

External

source

External

source

Information

provider

Dealer

Dealer

Dealer

Notification

Notification

Notification

Notification

Notification

Notification

Notification

Notification

Dealer’s computer

Dealer’s computer

Dealer’s computer

Notification

Notification

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

A Dealing Room System

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

22

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

subscriber

observer

object of interest

Event service

object of interest

object of interest

observer

subscriber

subscriber

3.

1.

2.

notification

notification

notification

notification

An Architecture for Event Notification

NNote: Java
-
based event system (specification) Jini has a similar architecture.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

23

The Roles for Observers/Agents


An
observer

decouples an object of interest
from its subscribers. The roles it plays
include:


Forwarding


Filtering


Allowing patterns of events to be subscribed


Notification mailboxes: a subscriber may
check notifications intended for it later.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

24

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Java Remote Interfaces

NNote:
GraphicalObject

must implement the
Serializable

interface.











IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

25

Parameter Passing in Java


By reference (passed as remote object references)


For parameters whose type is defined as a
remote

interface, one that extends
Remote


By value (new objects created at local site)


For parameters of
serializable

types, including primitive
types and classes that implement the
serializable

interface


Classes for arguments and results are
downloaded automatically to the recipient.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

26

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

The
Naming

Class of RMIRegistry

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

27

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

A Java Server


Note: The server acts like a shared whiteboard.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

28

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

A Java Server (cont.)

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

29

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

A Java Client

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

30

CORBA


Defined by OMG to facilitate the development of
distributed object
-
oriented systems.


Language
-
independency is achieved through the
use of a standard interface definition language
---
the CORBA IDL.


An ORB (Object Request Broker) receives
invocations from a client and deliver them to a
target object.


The main communication protocol is GIOP
(General Inter
-
ORB Protocol), known as IIOP
when implemented over the Internet.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

31

Source of the figure: G. Coulouris et al.,
Distributed Systems: Concepts and Design


* The implementation repository allows server objects to be activated on


demand.

** The interface repository gives run
-
time type information, mainly for

dynamic invocations.

**

*

The CORBA Architecture

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

32

The Object Adapter


Creates remote object references for
CORBA objects


Maps the names of CORBA objects to their
servants


Dispatches each remote invocation via a
skeleton to the appropriate server object


Activate objects

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

33

CORBA Object Interfaces


Each object has an interface defined in IDL.


An interface defines the operations that can
be called by the clients.


An interface can be implemented in one
language and called from by another.


The CORBA IDL includes features such as
inheritance of interfaces, exceptions, and
compound data types.


IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

34


Define the interfaces using IDL and compile
them into Java interfaces.


Implement the interfaces with Java classes.


Write a server main function that creates
instances of these classes and then inform the
underlying CORBA implementation.


Register the server.


Write a client main function to connect to the
server and to use server’s objects.

CORBA Programming with Java

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

35

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Shape

and
Shapelist

in CORBA IDL

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

36

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Java Interface Generated from
ShapeList

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

37

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Java Implementation of
Shapelist

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

38

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Java Implementation of
ShapeList

(cont.)

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

39

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

Java Implementation of
ShapeList

(cont.)

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

40

CORBA Services


Naming Service


locate objects by their names


Trading Service


locate objects by their attributes


Event Service and Notification Service


Security Service


Transaction Service and Concurrency
Control Service


Persistent Object Service

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

41

The CORBA Naming Service


Allows (1) a name to be bound to an object and (2)
that object to be found subsequently by resolving
that name.


A name is a sequence of name
components

and is
resolved within a given naming
context
.


The IDL interface
NamingContext

defines the
core of the naming service.


A
NamingContext

object acts much like a
directory in a filing system.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

42

CORBA Naming Graph

initial naming context

ShapeList

C

D

E

B

initial naming context

P

R

S

T

V

Q

U

initial naming context

XX

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

43

struct NameComponent { string id; string kind; };


typedef sequence <NameComponent> Name;


interface NamingContext {

void bind (in Name n, in Object obj);

binds the given name and remote object reference in my context.

void unbind (in Name n);

removes an existing binding with the given name.

void bind_new_context(in Name n);

creates a new naming context and binds it to a given name in my context.

Object resolve (in Name n);


looks up the name in my context and returns its remote object reference.

void list (in unsigned long how_many, out BindingList bl, out BindingIterator bi);

returns the names in the bindings in my context.

};

Source: G. Coulouris et al.,
Distributed Systems: Concepts and Design

The NamingContext Interface (partial)

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

44

COM/DCOM


COM stands for Component Object Model. Its
distributed version is referred to as DCOM.


It is a programming model for binary components
reuse and a foundation of OLE (Object Linking
and Embedding) and ActiveX controls.


COM interfaces are defined in the interface
definition language IDL and compiled by
MIDL.EXE.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

45

COM Objects


All COM objects implement the
IUnknown

interface (defined in
unknwn.idl
) or one of its
extended interfaces.


Methods of
IUnknown
:


QueryInterface: checks if the named interface is
supported and, if so, returns the corresponding interface
reference


AddRef


Release


A COM object may implement multiple interfaces.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

46

How a COM Interface Works

pointer
Interface Function Table
Interface Pointer
Pointer to Function1
Function1(...)
{
...
}
Pointer to Function2
Pointer to Function3
...
Function2(...)
{
...
}
Function3(...)
{
...
}
...
Source: Microsoft,
The COM Specification.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

47

Creation of a COM Object

Source: Microsoft,
The COM Specification.

Class Factory
Object
Server
Client
(1) “Create
an Object”
(2) Manufacture
Object
(3) Return new
interface pointer
to client
IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

48

Source: Microsoft,
The COM Specification.

In-Process
Object
Client
Application
Local
Object
Proxy
Remote
Object
Proxy
In-Process Server
COM
Client Process
RPC
RPC
Local
Object
Local Server
Stub
COM
Local Server Process
Remote
Object
Remote Server
Stub
COM
Remote Server Process
Remote Machine
Location Transparency in COM

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

49

GUIDS


To eliminate name collisions, all COM
interfaces are assigned a unique binary
name at design time that is the physical
name of the interface.


These physical names are called
Globally
Unique Identifiers

(GUIDs).


GUIDs are 128
-
bit extremely large numbers
that are guaranteed to be unique in both
time and space.

IM NTU

Distributed Information Systems 2004

Interprocess Communication and Middleware
--

50

[


object,


uuid(00000000
-
0000
-
0000
-
C000
-
000000000046),


pointer_default(unique)

]

interface
IUnknown

{


HRESULT

QueryInterface
([in] REFIID iid, [out] void **ppv) ;


ULONG


AddRef
(void) ;


ULONG

Release
(void);

}

The
IUnknown

Interface