Cours Ñ Corba - Laboratoire d’Analyse et d...

35
1 Introduction à CORBA Jean-Charles Fabre LAAS-CNRS 7, Avenue du Colonel Roche 31077 Toulouse cedex 4 [email protected] Tel: 05-61-33-62-36 2 Sommaire ! Different views of CORBA ! CORBA: présentation et exemple ! ORBACUS Un ORB en Java et C++ Deux BE: Installation, développement et fonctionnement d’une application Gestion des modes de concurrence et mesures de performance

Transcript of Cours Ñ Corba - Laboratoire d’Analyse et d...

1

Intro

du

ction

à CO

RB

A

Jean-C

harles F

abre

LA

AS

-CN

RS

7, Aven

ue d

u C

olo

nel R

och

e31077 T

ou

lou

se cedex 4

Jean-C

harles.F

abre@

laas.frT

el: 05-61-33-62-36

2

So

mm

aire

!D

ifferent views of C

OR

BA

!C

OR

BA

: présen

tation

et exemp

le

!O

RB

AC

US

•U

n OR

B en Java et C

++

•D

eux BE

:–

Installation, développement et fonctionnem

ent d’une application–

Gestion des m

odes de concurrence et mesures de perform

ance

3

Different view

s of CO

RB

A

4

CO

RB

A an

d o

ther m

idd

leware

!O

bjectives

•A

bstract the network - distribution

•P

rovide a uniform program

ming m

odels (RP

C like)

!S

oftw

are com

po

nen

ts pro

vidin

g services to

app

lication

s•

Libraries and services on top of an OS

•E

xtension of OS

services•

A set of developm

ent toolsA

pplications

Middlew

are

Operating System

!D

ifferent typ

es of m

idd

leware

•G

eneric➪

CO

RB

A : distributed objects &

multi-language support

➪ JIN

I & others vendors’ m

iddleware …

like DC

OM

, etc.

•S

pecific➪

dedicated services for specific applications

5

Co

mp

ositio

n

!O

bjective

•P

rovision of a generic support for distributed applications•

Interoperability: executive support, programm

ing languages

!B

asic services of stan

dard

mid

dlew

are… like C

OR

BA

•T

ransparent interactions between application objects

•D

ynamic localisation of services (related servers and refs.)

•S

tatic and dynamic linking (D

II/DS

I)•

Abstract definition of services (ID

L)•

Database of interfaces and im

plementations (repositories)

•V

arious concurrency models m

apped on OS

threads/schedulers(thread_per_request, thread_per_client, thread_pool,…

)

6

Differen

t views o

f CO

RB

A:

glo

bal (C

EO

)

CO

RB

A

OS1

OS2

OS3

OS4

C+

+Java

C

HW

1H

W2

HW

3H

W4

Netw

ork

•T

he global view (i.e. the C

EO

viewpoint)

7

Differen

t views o

f CO

RB

A:

com

po

nen

t

request

Dyn

amic

Invo

cation

IDL

stu

bs

OR

B

interface

IDL

Skeleto

nP

ortab

leO

bject

Ad

apter

OR

B C

ore

Clien

tO

bject Im

plem

entatio

n

callu

p-call

IIOP

+ nam

ing

+ rep

osito

ries+ o

thers

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)

OS

Services

8

Differen

t views o

f CO

RB

A:

develo

pm

ent

IDL

Interface

Rep

osito

rystu

bs

stub

sstu

bs

stub

sstu

bs

skeleton

serverclien

t

Imp

lemen

tation

Rep

osito

ry

AP

I(lib

raries)

- Packin

g- M

arshallin

g- U

nm

arshallin

g

Invo

cation

messag

esd

ispatch

er!

IIOP

/ TC

P-IP

IDL

com

pilers

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)

•T

he development view

(i.e. the programm

er’s viewpoint)

9

Differen

t views o

f CO

RB

A:

op

eration

al

Op

erating

system kern

el S1

Sn

Wh

at you

write

Wh

at you

get

Co

mp

ilation

and

lin

k pro

cess••••

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)

•T

he development view

(i.e. the programm

er’s viewpoint)

•T

he operational view (i.e. the runtim

e viewpoint!)

CORBA

libraries

Pro

gram

sou

rce cod

eID

L in

terfaces

CORBA

services

10

Differen

t views o

f CO

RB

A:

dep

end

ability

⇧⇧

Op

erating

system kern

el

Pro

gram

sou

rce cod

eID

L in

terfaces

••••

Faults

Error detection and recovery

CORBA

librariesCO

RBA services

S1

Sn

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)•

The developm

ent view (i.e. the program

mer’s view

point)•

The operational view

(i.e. the runtime view

point!)

•T

he dependability view (i.e. the fault tolerance view

point)–

Failure m

odes analysis (OR

B com

ponents, OS

, services)–

Protection using w

rapping and fault tolerance techniques

11

Differen

t views o

f CO

RB

A:

map

pin

g

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)•

The developm

ent view (i.e. the program

mer’s view

point)•

The operational view

(i.e. the runtime view

point!)

•T

he dependability view (i.e. the fault tolerance view

point)•

Zoom

on the mapping view

(i.e. the physical viewpoint)

Op

erating

system kern

el

Client code

Stub codeLocal data

Global (shared) dataORB shared code

Server code

Skeleton code

ORB/PO

A

12

Differen

t views o

f CO

RB

A:

map

pin

g

Op

erating

system kern

el

Client code

Stub codeLocal data

Global (shared) dataORB shared code

Server code

Skeleton code

ORB/PO

A

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)•

The developm

ent view (i.e. the program

mer’s view

point)•

The operational view

(i.e. the runtime view

point!)

•T

he dependability view (i.e. the fault tolerance view

point)•

Zoom

on the mapping view

(i.e. the physical viewpoint)

13

Differen

t views o

f CO

RB

A:

pro

toco

l

OS

IPC

/ Netw

ork

Client code

Stub code

Server code

Skeleton code

ORB/PO

A✉

✉IIO

P(IO

R)

TCP/IP

•T

he global view (i.e. the C

EO

viewpoint)

•T

he component view

(i.e. the system designer’s view

point)•

The developm

ent view (i.e. the program

mer’s view

point)•

The operational view

(i.e. the runtime view

point!)

•T

he dependability view (i.e. the fault tolerance view

point)•

Zoom

on the mapping view

(i.e. the physical viewpoint)

•T

he protocol view (i.e. the com

munication view

point)

14

Co

mm

ents

!M

ain co

mp

on

ents

•M

ost of basic services are provided as shared libraries(shared code/data segm

ents, data space for individual objects)•

General services are provided as « system

processes », i.e. Unix

deamons and the like (e.g. N

aming S

ervice).

!P

rog

ramm

ing

app

lication

s•

Applications are organized as a set of m

iddleware com

municating

objects•

Initialisation, handshaking, selection of concurrency models, etc…

are actions performed by the m

iddleware

•M

iddleware objets are not alw

ays mapped onto O

S entities

•A

pplications invoke directly the OS

AP

I for services likesynchronisation, m

emory m

anagement, file m

gt.

15

CO

RB

A

Présen

tation

et exemp

le

16

CO

RB

A

!C

om

mo

n O

bject R

equ

est Bro

ker Arch

itecture

!O

rigin

e: l’OM

G•

consortium de sociétés de logiciel et d’utilisateurs

!O

bjectif:

•fournir un support pour l’exécution répartie d’objets

•client ➱

invocation transparente ➱ serveur

•notion d’O

RB

(Object R

equest Broker)

•interopérabilité: applications, m

achines, langages

17

!D

éfinitio

n d

’un

système à o

bjets

•collection d’objets (client et/ou serveurs)

•notion de service et d’interface

!E

lémen

ts du

mo

dèle —

défin

ition

s•

objet = entité encapsulée identifiable +

services•

création, destruction et désignation d’objets (référence)•

requête (invocation) et opération (méthode)

•types (langage de définiton d’interface —

IDL)

•signatures (interface des m

éthodes)•

notion d’interface et d’implém

entation•

message (object, operation, [param

ètre]*) ➱ activation

•notion d’exception renvoyée en cas de problèm

e

Mo

dèle et im

plém

entatio

n

18

Param

ètres et sign

atures

!In

, Ou

t, InO

ut

!T

ypes

!S

ign

ature

[oneway] <

op_type_spec> <

identifier> (p1,...,pN

)

[raise (e1, ... , eNn)][context (n1, ... , nN

)]

Value

Reference

Basic

Constructed

Short

LongU

shortU

longF

loatD

oubleC

harS

tringB

ooleanO

ctetE

numA

ny

Sequence

Union A

rrayS

truct

19

Mo

dèle o

bjet (su

ite)

!S

éman

tiqu

e d’ap

pel d

e méth

od

e•

appel bloquant ➱ résultat, exception

•appel non bloquant ➱

synchronisation si retour

!A

ttribu

ts•

déclarer des attributs ➱ déclarer les fonctions d’accès (r,w

)

!E

xceptio

ns

•indication d’erreur +

informations com

plémentaires

!Im

plem

entatio

n d

’ob

jet•

définition de l’état des objets•

définition du corps des méthodes

20

Co

mm

on

Ob

ject Req

uest

Bro

ker Arch

itecture

request

Dynam

icInvocation

IDL

stub

s

OR

B

interface

IDL

Skeleto

nO

bject

Ad

apter

ORB

Core

Client

Ob

ject Imp

lemen

tation

Interface identique pour toutes les implém

entations de l'OR

B

Il peut exister de multiples im

plémentations O

A

stub

s et skeleton pour tout type d'objet

callup

-call

21

Invo

cation

!D

ynam

iqu

e•

interface indépendante de l’objet cible

•recherche de la signature d’une m

éthode d’un service!

Statiq

ue

•stubs spécifiques dépendant de l’objet cible

•l’objet appelé reçoit l’invocation par un up-call au travers duskeleton généré à partir de l’interface ID

L.•

les interfaces d’objets peuvent être archivées dans un InterfaceR

epository!

Fo

nctio

nn

emen

t•

l’OR

B localise l’objet, transm

et les paramètres de la requête et

transfère le contrôle au Skeleton qui active l’objet.

•lorsque la requête se term

ine, contrôle et résultats sont renvoyésau client

22

Gén

ération

IDL

InterfaceR

epositorystubs

stubsstubs

stubsstubs

skeleton

serveurclient

Implem

entationInstallation

Implem

entationR

epository

23

Clien

t-Serveu

r

!C

lient

•un client identifie un objet par une référence

•invocation (ref_object, m

ethod, parameter*)

•c’est l’O

RB

qui effectue le transfert de la requête et le retour de laréponse

•lorsque l’invocation ne peut pas se term

iner correctement, une

exception est retournée à l’appelant par l’OR

B

!S

erveur

•l’im

plémentation correspond à l’état et au com

portement de l’objet

•création, accés au service de stockage, traitem

ent, réponse auclient

24

Ob

ject adap

ter

!R

ôle

•propose une interface aux services de l’O

RB

•exporte une interface publique pour l’im

plémentation

•propose une interface privée à destination du skeleton

!F

on

ction

s•

invocation de méthodes à travers le skeleton

•sécurité des interactions

•activation et désactivation des im

plémentations d’objets

•m

apping entre les références d’objets et les implém

entations•

enregistrement des im

plémentations

•gère le référentiel d’interfaces

•O

A de base, O

A librairie, O

A base de donnée O

O

25

Héritag

e!

No

tion

de d

érivation

d’in

terface•

interface A {•••}

•interface B

: A {•••}

•interface C

: A {•••}

•interface D

: B,C

{•••}

!R

edéfin

iton

s•

types, constantes, nom<

scope>, exceptions

•exem

ple:

AD

CB

const Long L=3;

interface A {

void f ( in float[L])}

interface B {

const Long L=4;

}interface C: B

,A {}

Signature de f dans C

: void f(in float [3]); // early binding

26

Ad

équ

ation

à un

lang

age

!T

radu

ction

des typ

es, etc. : IDL

-> lang

age

•types de base, construits, constantes

•objets :

objet=program

me, m

éthode=program

me,

passage d’arguments, invocation, références

!E

xemp

les (en C

)

interface X1 {

long op1 (in long a);}

typedef Object X

1;extern long X

1_op1(X

1 o; Environm

ent *ev; long a);

interface X3: X

1 {long op3 (in long b

out long c);}

typedef Object X

3;extern long X

3_op1(X

1 o; Environm

ent *ev; long a);extern long X

3_op3 (X

3 o; Environm

ent *ev; long blong *c);

C, C

++

, S

mallT

alkJava*, A

da*

27

Invo

cation

dyn

amiq

ue

!P

rincipe : requête (object, opération, arguments*)

!T

ypes de base : Nam

eValue, N

VList

!C

réation et manipulation de liste: O

RB

create_list,!

Requêtes O

RB

: OR

BS

tatus add_arg, OR

BS

tatus Invoke,O

RB

Status delete, O

RB

Status get_response, O

RB

Status send

OR

BC

reateRequest

(in: Context, Identifier, N

VList, F

lags;inout R

esult; out Request)

typedef unsigned long Flags;

struct Nam

edValue {

Identifier name;

// nom argum

entany

argument; // argum

entlong

len; // longueur

Flags

arg_modes; // in, out, inout

}

28

Dép

ositaire d

’interfaces

!3 m

anières d

e retrou

ver un

e interface

•récupération d’un InterfaceD

ef directement de l’O

RB

–get_interface (object_reference)

•recherche dans un espace de nom

s hiérarchisé•

retrouver InterfaceDef dans un dépositaire identifié

!In

terface du

dép

ositaire: q

uelq

ues asp

ects...•

RepositoryId: identifieur utilisé par l’O

RB

pour identifier de façonunique m

odule, interface, constantes, définitions de type,exceptions, attributs et opérations.

•InterfaceN

ame est une chaîne identifiant un élém

ent

•les objets qui contiennent d’autres objets sonts des C

ontainers(héritage et com

position)•

les objets contenus dans d’autres objets sont des Contained

29

Exem

ple: In

terface de C

on

tainer

container {- contents()

==

> liste des objets contenus

- look_up_name()

==

> recherche d’un objet particulier

- describe_content()=

=>

description des objets contenus}description =

InterfaceDesc +

AttributeD

esc + O

perationDesc +

Param

eterDesc...

OperationD

esc {nomrepositoryIdrepositoryId (container)return typem

ode (A/S

)séquence de contextesséquence de param

ètresséquence d’exception

}

Param

eterDesc {

nomrepositoryIdrepositoryId (container)typem

ode (in, out, inout)}

30

Interface O

RB

!C

onversion références d’objets en chaines:•

object_to_string (object) , string_to_object (string)

!C

réation des listes de paramètres :

•create_list (in long count, out N

VList new

_list)!

Création de listes d’opérations :

•create_operation_list(in O

perationDef oper, out N

VList new

_list)!

Recherche d’une im

plémentation d’un objet donné :

•Im

plementationD

ef get_implem

entation ()

!R

echerche d’une interface d’un objet donné :•

InterfaceDef get_interface ()

!D

upliquer un objet :

•O

bject duplicate ()!

Destruction d’une référence sur un objet:

•void release ()

31

Ad

aptateu

r d’o

bjet d

e base

!R

ôle:–

génération et interprétation des références–

authentification de l’objet qui effectue l’appel

–activation et désactivation des im

plémentations

–activation et désactivation des objets

–invocation des m

éthodes au travers du skeleton

!L

e BO

A est dépendant O

S et lan

gag

e (po

rtabilité

➠ P

OA

)!

Exem

ple d

e mise en

œu

vre:–

un serveur par classe d’objets

–notification de term

inaison d’initialisation au BO

A–

requête init==

> activation de l’im

plémentation (activation d’un objet)

–autres requêtes =

=>

activation de la méthode correspondante

–l’im

plémentation peut appeler le B

OA

n’importe quand.

32

Exem

ple d

’interface B

OA

!O

bject create (in ReferenceD

ata id, in InterfaceDef intf, in Im

plementationD

ef)!

void dispose (in Object obj)

!void change_im

plementation (in O

bject obj, in Implem

entationDef im

pl)!

Principal get_principal (in O

bject, in Environm

ent)!

void set_exception (in exception_type, in string userid, in void *param)

!void im

pl_is_ready (in Implem

entationDef im

pl)!

void desactivate_impl (in Im

plementationD

ef impl)

!void obj_is_ready (in O

bject obj, in Implem

entationDef im

pl)

!void desactivate_obj (in O

bject obj)!

Les req

uêtes vis-à-vis d

u B

OA

son

t de tro

is ord

res–

opération de creation ou de destruction de référence d’objets

–opérations associées à une requête particulière

–opérations pour m

aintenir les tables d’objets actifs et implém

entations

33

Un

exemp

le sur C

OO

L-O

RB

!U

n p

etit exemp

le: “hello

wo

rld” d

istribu

é!

Etap

es–définir l’interface

–définir le serveur

•im

plémentation dans une classe C

++

•initialisations O

RB

, BO

A, etc.

•déclaration de nom

et de service•

compilation

–définir le client

•im

plémentation : un program

me C

++

•initialisations O

RB

, etc.•

importer la référence de l’objet serveur

•com

pilation–

utilisation•

invocation directe des méthodes du serveur distant

•affichage du m

essage dans le cas de “hello world”

refinvocation

implém

entation de l’objet

hello clientC

onsole serveur34

Le serveu

r

!G

énéralités–

implém

enter les opérations définies dans l’interfacei.e. m

ontrer comm

ent l’interface console peut être implém

entéeà l’aide d’une classe C

++

appelée ConsoleIm

pl.

–une opération m

ain qui effecue l’initialisation de l’OR

B et du

BO

A i.e. l’initialisation du serveur

–exporter la référence du serveur de façon à ce que les clientspuissent la retrouver, l’im

porter et l’utiliser ultérieurement

–m

ise en attente (boucle run du boa) pour réception ettraitem

ent des requêtes

35

Dém

arche

–définir l’interface

–com

pilation =>

stub headerstub im

plementation

–définition de l’im

plémentation: classe C

onsoleImpl

interface console {void print (in string m

sg);}

console.Hconsole.C

class ConsoleIm

pl {public:

void print(const char *msg, C

OR

BA

_Environm

ent& env)

}

36

Réalisatio

n d

e l’imp

lémen

tation

–réalisation de l’im

plémentation en C

++

–génération du skeleton header

implém

entation

–inclusion de sk_console.C

dans le serveur pour utilisation

–génération:

chic --skeleton-impl --binding C

onsole ConsoleIm

pl console.idl

#include <api/api.H

>#include <

stdio.h>•••void C

onsoleImpl::print(const char *m

sg, CO

RB

A_E

nvironment&

) {printf (“%

s”, msg);

}

sk_console.Hsk_console.C

37

Lien

entre im

plém

entatio

n et référen

ce

#include <api/api.H

>#include <

stdio.h>#include “consoleIm

pl.H”

#include “sk_console.H”

#include “sk_console.C”

•••int m

ain (int argc, char* argv[]) {•••ptr_console console;C

onsoleImpl C

onsoleImpl;

CO

OL_bind(consoleIm

pl, console, env);if (env.exception()) {

fprintf (stderr, “Impossible de créer la référence d’objet\n”);

return 1;}

•••}

38

Initialisatio

n d

u serveu

r#include <

api/api.H>

#include <stdio.h>

•••int m

ain (int argc, char* argv[]) {•••C

OR

BA

_Environm

ent env;C

OR

BA

_OR

B_ptr orb =

CO

RB

A_O

RB

_init (argc, argv[]);if (env.exception()) {

fprintf (stderr, “Impossible d’initialiser l’O

RB

\n”);return 1;}

•••C

OR

BA

_BO

A_ptr boa =

OR

B_O

A_init (argc, argv, 0, env)

if (env.exception()) {fprintf (stderr, “Im

possible d’initialiser l’object adapter \n”);return 1;}

•••}

39

Exp

orter la référen

ce d’u

n o

bjet

#include <api/api.H

>#include <

stdio.h>•••int m

ain (int argc, char* argv[]) {•••C

onsole_ptr console;•••C

OO

L_Nam

ingService_var nam

ing = thisC

apsule->nam

ing_service(env);nam

ing->export (“consoleS

ervice”, console, env);if (env.exception()) {

fprintf (stderr, “Impossible d’exporter la référence de l’objet console\n”);

return 1;}

•••}

40

Activatio

n d

u traitem

ent d

esreq

uêtes

#include <api/api.H

>•••int m

ain (int argc, char* argv[]) {•••C

OR

BA

_BO

A_ptr boa =

•••;•••boa->

run();return 0;}

–le serveur est m

is en attente de requêtes distantes–

ceci est effectué par la méthode run du boa

–elle effectue aussi les appels à l’im

plémentation de l’objet

–appel de print sur une référence de C

onsoleService entraîne

automatiquem

ent l’appel de la méthode C

onsoleImpl::print.

41

Le clien

t

!G

énéralités–

main qui initialise l’O

RB

–im

porter une référence sur l’objet serveur pour pouvoirinvoquer des opérations

–écrire le code du client qui utilise le service console

–com

pilation

!In

itialisation

du

client

#include <api/api.H

>#include <

stdio.h>•••int m

ain (int argc, char* argv[]) {C

OR

BA

_Environm

ent env;C

OR

BA

_OR

B_ptr orb =

C

OR

BA

_OR

B_init (argc, argv[], 0, env);

if (env.exception()) {fprintf (stderr, “Im

possible d’initialiser l’OR

B \n”);

return 1;}

••• }

42

Imp

ortatio

n d

e la référence

#include <api/api.H

>#include <

stdio.h>#include “console.H

”•••int m

ain (int argc, char* argv[]) {•••C

OO

L_Nam

ingService_var nam

ing = thisC

apsule->nam

ing_service(env);nam

ing->im

port (“consoleService”, obj, env);

if (env.exception()) {fprintf (stderr, “Im

possible d’exporter la référence de l’objet console\n”);return 1;}

Console_ptr console =

Console::_narrow

(obj) // casting

CO

RB

A_release(obj);

•••}

43

Invo

cation

du

serveur

#include <api/api.H

>#include “console.H

”•••int m

ain (int argc, char* argv[]) {•••C

onsole_ptr console = •••

•••console->

print(“Hello W

orld\n”, env);if (env.exception()) {

fprintf (stderr, “Impossible invoquer le service console\n”);

return 1;}

return 0;}

44

Co

mp

ilation

des exem

ples

!C

lient–

CC

-c -I$CO

OLD

IR/include console.C

–C

C -c -I$C

OO

LDIR

/include hello.C–

CC

-o hello hello.o console.o $CO

OLD

IR/lib/libO

rb.a!

Serveu

r–

CC

-c -I$CO

OLD

IR/include console.C

–C

C -c -I$C

OO

LDIR

/include consServer.C

–C

C -o consS

erver consServer.o console.o $C

OO

LDIR

/libOrb.a

!A

ctivation

$ consServer &

Hello W

orld$ hello

machine A

: clientm

achine B : serveur

45

Co

nclu

sion

s

!C

OR

BA

fournit un cadre opérationnel pour réaliser des applicationsréparties dans un langage objet.

!A

bstraction des aspects comm

unications (messages) et gestion des

invocations (nomm

age, paramètres).

!Im

plémentation libre à la discrétion de l’industrie du logiciel (avec

soucis d’intéropérabilité).!

Nécessite un support de l’O

S pour réaliser la représentation,

l’activation, l’exécution, la gestion et le stockage des objets.

!Im

plémentation sur U

NIX

et sur micronoyau.

!P

eut apparaître lourd à utiliser... mais les propriétés ont un coût!

!N

écessite une période de rodage au niveau de la programm

ation pourse fam

iliariser avec l’interface, le style et les conventions deprogram

mation.

!D

es versions réduites de l’implém

entation peuvent être envisagéespour des contextes opérationnels particuliers.

46

OR

BA

CU

S:

Un

OR

B p

ou

r C++ et Java

Elém

ents p

ratiqu

eset exem

ples

47

Exem

ples

!O

bjectifs

•réaliser un application répartie sim

ple et illustrative

•dém

ontrer l’interopérabilité multi-langages

•illustrer différents m

odèles de concurrence

!L

es interven

ants

•les clients ém

ettent des messages à destination de serveurs

•un serveur traite les m

essages reçus de façon séquentielle

•un serveur traite des m

essage avec attente et sans attentesim

ultanément

48

Les o

bjets

Clien

t

Serveu

r relais S

erveur fin

al

Clien

t C

lient

49

Le lan

gag

e

Java C

++ C

++

Java C

++

Clien

t

Serveu

r relaisS

erveur fin

al

Clien

t C

lient

50

Les in

terfaces et les app

els

Java C

++ C

++

Java C

++

Clien

t

Serveu

r relais S

erveur fin

al

Clien

t C

lient

• printf• printf_and_sleep

printf printf_and_sleep

printf

51

Le m

od

èle d’exécu

tion

Clien

t

Serveu

r relais S

erveur fin

al

Clien

t C

lient

• printf• printf_and_sleep

printf printf_and_sleep

printf

52

Les fich

iers

!L

a descrip

tion

du

service :•

hello.idl

!L

e serveur relais (im

plém

entatio

n d

e hello

.idl):

•helloIm

pl.java

!L

e serveur fin

al (imp

lémen

tation

de h

ello.id

l):•

helloThread.cpp

!L

e client Java

•client.java

!L

e client C

++•

client.cpp

53

La p

rod

uctio

n

!G

eneratio

n d

es stub

s et des skeleto

ns

•idl hello.idl ➱

pour les objets C+

+–

make idltocpp

•jidl hello.idl ➱

pour les objets Java–

make idltojava

!G

eneratio

n d

es ob

jets clients

•m

ake clientjava (appel de la m

éthode print)

•m

ake clientcpp (appel de la m

éthode print)

•m

ake clientcppsleep (appel de la méthode print_and_sleep)54

La p

rod

uctio

n... p

uis l’exécu

tion

!G

eneratio

n d

es ob

jets serveurs

•m

ake servercpp

•m

ake serveurjava

•m

ake servercppT

!L

’exécutio

n•

lancer le server C+

+ :

ServerC

T *** m

ultithread ***

•lancer le server Java :

java defaultpkg.ServerJ

•lancer le client C

++

:clientC

texte

•lancer le client Java :

java defaultpkg.Client texte

55

/************************************//* 19/04/99 O

rbacus Lesson 1 */

/* Hello W

orld *//************************************/interface H

ello {

void printf(in string s); void printf_and_sleep(in string s);

};

L’ID

L

56

pu

blic class S

erverJ extend

s _Hello

Imp

lBase {

// Défin

ition

du

serveur

private

org

.om

g.C

OR

BA

.OR

B _o

rb;

Hello

real_s;

pu

blic

ServerJ(o

rg.o

mg

.CO

RB

A.O

RB

orb

){// C

on

structeu

r du

serveur

_orb

=orb

;// R

écup

ération

de la référen

ce sur l’O

RB

Strin

g ref = n

ull;

try { S

tring

reffile= "hello

.ref"; // D

éfinitio

n statiq

ue d

’un

no

m d

e fichier

java.io.B

uffered

Read

er in =n

ew java.io

.Bu

fferedR

eader(n

ew java.io

.FileR

eader(reffile));

ref = in.read

Lin

e(); // L

ecture d

e la référence

} catch

(java.io.IO

Excep

tion

i) { S

ystem.err.p

rintln

("Can

no

t op

en h

ello.ref");

System

.exit(-1); }

ServerJ.java

57

ServerJ.java (su

ite)

org

.om

g.C

OR

BA

.Ob

ject ob

j = orb

.string

_to_o

bject(ref);

// Tran

sform

ation

en // référen

ce CO

RB

A real_s=

Hello

Help

er.narro

w(o

bj);

// Castin

g } p

ub

lic void

prin

tf( Strin

g s) {

// Défin

ition

de la m

étho

de p

rintf

Strin

g to

prin

t=s+" from

Server JA

VA

prin

tf "; S

ystem.o

ut.p

rintln

("Received

: "+s); real_s.p

rintf(to

prin

t); } p

ub

lic void

prin

tf_and

_sleep( S

tring

s) { // D

éfinitio

n d

e la méth

od

e prin

tf_and

_sleep S

tring

top

rint=s+" fro

m S

erver JAV

A p

rintf_an

d_sleep

"; S

ystem.o

ut.p

rintln

("Received

: "+s); real_s.p

rintf_an

d_sleep

(top

rint);

}

58

ServerJ.java (su

ite)p

ub

lic static void

main

(Strin

g arg

s[]) thro

ws java.n

et.Un

kno

wn

Ho

stExcep

tion

{

// Initialisatio

n O

RB

et BO

A (l’O

RB

initialise le B

OA

du

serveur)

org

.om

g.C

OR

BA

.OR

B o

rb = o

rg.o

mg

.CO

RB

A.O

RB

.init(arg

s, new

java.util.P

rop

erties()) ; o

rg.o

mg

.CO

RB

A.B

OA

bo

a = o

rb.B

OA

_init(arg

s,new

java.util.P

rop

erties()) ;

ServerJ server = n

ew S

erverJ(orb

); // C

réation

du

serveur

Strin

g ref = o

rb.o

bject_to

_string

(server); try { S

tring

reffile= "hello

java.ref";// n

om

de fich

ier java.io

.Prin

tWriter o

ut = n

ew java.io

.Prin

tWriter(n

ew java.io

.FileO

utp

utS

tream(reffile));

ou

t.prin

tln(ref);

// Imp

ression

de la référen

ce dan

s fichier

ou

t.flush

(); } catch

(java.io.IO

Excep

tion

i) { S

ystem.err.p

rintln

("Can

no

t op

en h

ello.ref");

System

.exit(-1); }

59

ServerJ.java (su

ite)

// Dire B

on

jou

r S

tring

ho

st=java.net.In

etAd

dress.g

etLo

calHo

st().getH

ostN

ame();

System

.ou

t.prin

tln("H

i, I am a S

erver in Java ru

nn

ing

on

"+ho

st); S

ystem.o

ut.p

rintln

("*** I forw

ard w

hat yo

u tell m

e and

I add

..."); S

ystem.o

ut.p

rintln

("*** ... from

Server JA

VA

prin

tf ..."); S

ystem.o

ut.p

rintln

("*** ... from

Server JA

VA

prin

tf_and

_sleep ...");

System

.ou

t.prin

tln("*** d

epen

din

g o

n w

hat yo

u called

!");

bo

a.imp

l_is_ready(n

ull);

// Activatio

n d

u serveu

r }};

60

Server C

++/* H

elloIm

pl.cp

p */

#inclu

de <O

B/C

OR

BA

.h>

#inclu

de "h

ello_skel.h

"#in

clud

e <iostream

.h>

#inclu

de <fstream

.h>

class Hello

Imp

l : pu

blic H

ello_skel {

pu

blic:

// IDL

void

prin

tf(con

st char* s);

void

prin

tf_and

_sleep(co

nst ch

ar* s);

// C++

Hello

Imp

l() {}; ~H

elloIm

pl() {};

};

61

Server C

++ (suite)

// Défin

ition

de la m

étho

de p

rintf_an

d_sleep

void

Hello

Imp

l::prin

tf_and

_sleep(co

nst ch

ar* s) { co

ut << s <<en

dl;

cou

t << "***** Ou

uu

h I'm

tired, I'm

sleepin

g n

ow

"<<end

l; sleep

(20); co

ut << "***** T

ime to

wake u

p ....."<<

end

l;}// D

éfinitio

n d

e la méth

od

e prin

tfvo

id H

elloIm

pl::p

rintf(co

nst ch

ar* s) { co

ut << s <<en

dl;

}

62

Server C

++ (suite)

int m

ain(in

t argc, ch

ar **argv) {

char h

ost[30]; // n

om

de la m

achin

e ho

te

// Dire B

on

jou

r g

etho

stnam

e(ho

st, 30); co

ut << "H

i, I am a M

ultith

readed

Server in

C++ ru

nn

ing

on

" << ho

st << en

dl ;

cou

t << "*** you

call prin

tf: I say straigh

t wh

at you

tell me" <<

end

l ; co

ut << "*** yo

u call p

rintf_an

d_sleep

: I sleep, th

en I say straig

ht w

hat yo

utell m

e" << en

dl <<en

dl;

// 1.1 : Init C

OR

BA

: OR

B et B

OA

CO

RB

A_O

RB

_var orb

=CO

RB

A_O

RB

_init(arg

c,argv);

CO

RB

A_B

OA

_var bo

a=o

rb->B

OA

_init(arg

c,argv);

// 1.2 : Ch

oix d

u m

od

èle de co

ncu

rrence

orb

->con

c_mo

del(C

OR

BA

_OR

B::C

on

cMo

delT

hread

ed);

bo

a->co

nc_m

od

el(CO

RB

A_B

OA

::Co

ncM

od

elTh

readP

erClien

t);

63

Server C

++ (suite)

// 2 : Creer im

plem

entatio

n et o

bten

ir un

e reference

Hello

_var server=new

Hello

Imp

l();

// 3 : Ob

tenir u

ne referen

ce sou

s form

e de strin

g C

OR

BA

_Strin

g_var ref = o

rb->o

bject_to

_string

(server);

// 4: Ecrire ref d

ans fich

ier ch

ar* file="hello

.ref"; o

fstream o

ut(file);

ou

t << ref <<en

dl;

ou

t.close();

// 5: Lan

cer le BO

A b

oa ->

imp

l_is_ready(C

OR

BA

_Imp

lemen

tation

Def::_n

il());}

64

Clien

t Javap

ub

lic class Clien

t { p

ub

lic static void

main

(Strin

g arg

s[]) { // D

ire bo

njo

ur

S

ystem.o

ut.p

rintln

("I'm a C

lient in

JAV

A\n

"); // In

it OR

B

org

.om

g.C

OR

BA

.OR

B o

rb =

o

rg.o

mg

.CO

RB

A.O

RB

.init(arg

s, new

java.util.P

rop

erties()) ; // O

bten

ir reference a p

artir du

fichier

S

tring

ref = nu

ll;

try {

Strin

g reffile= "h

ellojava.ref";

java.io

.Bu

fferedR

eader in

=

new

java.io.B

uffered

Read

er(new

java.io.F

ileRead

er(reffile));

ref = in.read

Lin

e();

}

catch(java.io

.IOE

xceptio

n i) {

S

ystem.err.p

rintln

("Can

no

t op

en h

ello.ref");

S

ystem.exit(-1);

}

65

Clien

t Java (suite)

// Ob

tenir C

OR

BA

_Ob

ject

org

.om

g.C

OR

BA

.Ob

ject ob

j = orb

.string

_to_o

bject(ref);

// Ob

tenir S

tub

a partir d

e CO

RB

A_O

bject

Hello

server=Hello

Help

er.narro

w(o

bj);

//Utiliser

server.prin

tf("Java client m

essage");

}};

66

Clien

t C++

/* client.cp

p */

#inclu

de <O

B/C

OR

BA

.h>

#inclu

de "h

ello.h

"#in

clud

e <iostream

.h>

#inclu

de <fstream

.h>

int m

ain(in

t argc, ch

ar **argv) {

// 1 : Init C

OR

BA

: OR

B C

OR

BA

_OR

B_var o

rb=C

OR

BA

_OR

B_in

it(argc,arg

v);

// 2 : Ob

tenir u

ne referen

ce sou

s form

e de strin

g ch

ar ref[1000] ;#ifd

ef DIR

EC

T ch

ar* file="hello

.ref";#else ch

ar* file="hello

java.ref";#en

dif

67

Clien

t C++ (su

ite)

ifstream in

(file); in

>> ref;

in.clo

se();

// 3: Creer u

n stu

b d

e cette reference

CO

RB

A_O

bject_var o

bj= o

rb -> strin

g_to

_ob

ject(ref); H

ello_var server = H

ello::_n

arrow

(ob

j);

// 4: Utiliser le stu

b p

ou

r acceder au

service#ifd

ef SL

EE

P server->p

rintf_an

d_sleep

(argv[1]);

#else server->p

rintf(arg

v[1]);#en

dif

}

68

Mo

dèles d

e con

curren

ce

!m

od

èles simp

les•

Modèle séquentiel: une seule requête active à la fois

•M

odèle réactif: accepte simultaném

ent les retoursd’invocations et les nouvelles requêtes (callbacks)

!m

od

èles con

curren

ts•

Modèle “thread_per_client”: un thread est associé à chaque

client au sein du serveur

•M

odèle “thread_per_request”: un thread est associé àchaque requête quelque soit le client

•M

odèle “thread_pool”: un nombre T

pré-défini de thread estcréé; la requête T

+1 attendra qu’un thread se libère.

Com

ment l’O

RB

gère l’exécution des requêtes à un serveur

69

Deu

x BE

!B

E_1

•installer l’ensem

ble du système et de l’application

•com

prendre les différents modes de fonctionnem

ent

•résoudre les problèm

es d’interblocages en jouant sur lem

ode de concurrence

!B

E_2

•rendre plus flexible l’im

plementation en sélectionnant

dynamiquem

ent le mode de concurrence des serveurs

•ajouter des fonctionnalités de m

esure de performance

70

Go

od

luck!