Vous êtes sur la page 1sur 47

CORBA

Common Object Request Broker Architecture


Christophe Bouthier LORIA
Daprs le cours de Karim Baina

Plan
Architecture CORBA Le langage IDL CORBA en Java : JavaIDL Le service de nommage CORBA en C++ : Mico
2

Corba - Christophe Bouthier - Karim Baina - LORIA

CORBA

Architecture

Corba - Christophe Bouthier - Karim Baina - LORIA

Contexte
Applications distribues Objets rpartis Autres technos :

- RPC - COM+ - RMI - .NET

Corba - Christophe Bouthier - Karim Baina - LORIA

Principe simplifi
Client Serveur

Objet

Objet

Middleware
Corba - Christophe Bouthier - Karim Baina - LORIA 5

Object Management Group (OMG)


Cre en 1989 But non lucratif Plus de 850 membres (Sun, IBM, Microsoft, ...) Cre et maintient les spcifications

- CORBA - UML

http://www.omg.org
Corba - Christophe Bouthier - Karim Baina - LORIA 6

Architecture de CORBA
Client Serveur Objet Java Objet C++ Skeleton Stub IIOP Object Adapter

ORB
Corba - Christophe Bouthier - Karim Baina - LORIA

ORB
7

Composants
Stub : partie cliente Skeleton : partie serveur gnrs automatiquement

Object Adapter : enregistrement des objets ORB : passage de message IIOP : Internet Inter-ORB Protocol
Corba - Christophe Bouthier - Karim Baina - LORIA 8

Objet CORBA

Serveur Objet CORBA Interoperable Object Reference Interface IDL Implmentation C++/Java Servant

Corba - Christophe Bouthier - Karim Baina - LORIA

Exemple dIOR
IOR:000000000000001049444c3a5472697669616c3 a312e300000000001000000000000007c00010200 0000000d3135322e38312e342e313130000004800 0000025abacab3131303033383632313336005f526 f6f74504f410000cafebabe3bd5b878000000000000 0000000001000000010000002c0000000000010001 00000004000100200001010900010100050100010 0010109000000020001010005010001

Corba - Christophe Bouthier - Karim Baina - LORIA

10

Interface Definition Langage (IDL)


Description des interfaces Indpendant du langage dimplmentation Indpendant de la plate-forme client Indpendant de la plate-forme serveur

Ressemble beaucoup au C++


Corba - Christophe Bouthier - Karim Baina - LORIA 11

Exemple
module example { interface monExample { void methode1(); long methode2(); void methode3(in long param, out long result); }; };
Corba - Christophe Bouthier - Karim Baina - LORIA 12

Stub (souche)
Code client Interface entre objet et ORB Traduit les invocations sur lobjet serveur

- > marshalling

Traduit les messages en valeurs de retour

- unmarshalling

Corba - Christophe Bouthier - Karim Baina - LORIA

13

Skeleton (squelette)
Code serveur Interface entre implmentation et ORB Traduit les invocations client vers limplmentation

- > unmarshalling - > marshalling

Traduit la valeur de retour en message vers client

Corba - Christophe Bouthier - Karim Baina - LORIA

14

Object Request Broker (ORB)


Transporte les messages entre les objets Relie les stubs aux skeletons correspondants et vice-versa Bus objets Communications inter-ORBs :

- GIOP (General Inter-ORB Protocol) - IIOP (Internet Inter-ORB Protocol) (GIOP on TCP/IP)
15

Corba - Christophe Bouthier - Karim Baina - LORIA

Object Adapter (OA)


Enregistre et gre les implmentations Activation et dsactivation des objets Invocation des mthodes Authentification du client / contrle daccs Diffrents types :

- BOA Basic Object Adapter - POA Portable Object Adapter

Corba - Christophe Bouthier - Karim Baina - LORIA

16

Architecture de CORBA
Client Objet C++ IDL Serveur Objet Java

Skeleton Stub IIOP Object Adapter

ORB
Corba - Christophe Bouthier - Karim Baina - LORIA

ORB
17

Cration dune application CORBA


1 Dfinir linterface IDL 2 Compiler linterface IDL 3 Crer limplmentation de linterface IDL 4 Crer le serveur :

- > publication de lobjet CORBA


5 Crer le client :

- > appel de lobjet CORBA


18

Corba - Christophe Bouthier - Karim Baina - LORIA

CORBA

IDL

Corba - Christophe Bouthier - Karim Baina - LORIA

19

Exemple
module example { interface monExample { void methode1(); long methode2(); void methode3(in long param, out long result); }; };
Corba - Christophe Bouthier - Karim Baina - LORIA 20

Module
module monModule { }; espace de nom

- C++ : namespace - Java : package


21

Corba - Christophe Bouthier - Karim Baina - LORIA

Interface
interface monInterface { }; Classe

- C++ : class - Java : interface


22

Corba - Christophe Bouthier - Karim Baina - LORIA

Mthode
void methode(in long param, out long result); Mthodes : comme en C++ et Java, sauf

- in - out - inout

: paramtre utilis en entre (lu, non modifi) : paramtre utilis en sortie (non lu, modifi) : paramtre utilis en entre et en sortie (lu et modifi)
23

Corba - Christophe Bouthier - Karim Baina - LORIA

Syntaxe
Commentaire : comme C++ et Java

- // : jusqu la fin de la ligne - /* */ : bloc de commentaire

Prprocesseurs : #define, #include, #ifdef, #endif Alias : typedef Possibilit de dfinir des attributs Constantes : const
24

Corba - Christophe Bouthier - Karim Baina - LORIA

Types primitifs
void short long long long float double boolean
25

Corba - Christophe Bouthier - Karim Baina - LORIA

Types complexes
string struct enum union any
Corba - Christophe Bouthier - Karim Baina - LORIA 26

Hritage
Hritage multiple Surcharge et redfinition interdites interface A { }; interface B : A { }; interface C : A { }; interface D : B, C { };

A B D
27

Corba - Christophe Bouthier - Karim Baina - LORIA

CORBA

JavaIDL

Corba - Christophe Bouthier - Karim Baina - LORIA

28

JavaIDL
ORB CORBA en Java de Sun Inclu au JDK idlj : compilateur idl vers java

- Syntaxe : idlj -fall <fichier.idl> - Syntaxe :

orbd : ORB et serveur de nom indpendant orbd -ORBInitialPort <port> -ORBInitialHost localhost
Corba - Christophe Bouthier - Karim Baina - LORIA 29

Implmentation
Fichier MonObject.IDL : interface MonObjet { }; Classe qui implmente le contrat IDL Lancement client ou serveur :

- Doit driver de MonObjetPOA - MonObjetPOA est gnr par le compilateur IDL - java
<serveur/client> -ORBInitialPort <port> -ORBInitialHost localhost

Corba - Christophe Bouthier - Karim Baina - LORIA

30

Serveur / 1
Initialiser lORB : Objet CORBA :

- Mthode statique init(args, null) de la classe ORB - retourne un objet ORB - org.omg.CORBA.Object - Ne pas confondre avec java.lang.Object - Retourn par diffrentes mthodes - Cast avec mthode statique narrow de la classe MonTypeHelper
31

Corba - Christophe Bouthier - Karim Baina - LORIA

Serveur / 2
Utilisation dun POA :

- Mthode resolve_initial_references("RootPOA") de lobjet ORB - Retourne un objet CORBA caster en objet POA - Puis mthode the_POAManager().activate() de lobjet POA - Mthode servant_to_reference(servant) de lobjet POA - retourne un objet CORBA - Mthode run de lobjet ORB

Enregistrer le servant :

Lancement de lORB ( la fin) :


Corba - Christophe Bouthier - Karim Baina - LORIA 32

Client
Initialiser lORB :

- Mthode statique init(args, null) de la classe ORB - retourne un objet ORB - Mthode string_to_object(IOR) de lobjet ORB - Retourne un objet CORBA - Cast dans son vrai type avec la mthode statique narrow de la classe MonObjetHelper MonObjetHelper est gnr par le compilateur IDL
33

Rcuperer un objet CORBA depuis son IOR :

Corba - Christophe Bouthier - Karim Baina - LORIA

CORBA

Service de nommage

Corba - Christophe Bouthier - Karim Baina - LORIA

34

Services CORBA
Service de cycle de vie Service dvnements Service de concurrence Service de transaction Service de persistance Service dinterrogation Service de collection
35

Corba - Christophe Bouthier - Karim Baina - LORIA

Services de recherche dobjets


Service de nommage (Naming)

- Recherche dobjet par nom - pages blanches

Service vendeur (Trader)

- Recherche dobjet par proprit - pages jaunes


36

Corba - Christophe Bouthier - Karim Baina - LORIA

Besoin du Naming
Rfrence dun objet : IOR

- Fichier partag,

Service la DNS :

- Service accessible par le bus ORB - Service standard entre ORBs - Un nom spcifique <-> un objet corba - Gre les contextes de nom
37

Corba - Christophe Bouthier - Karim Baina - LORIA

Utilisation du Naming
Module CosNaming Interface NamingContext Nouvelle interface NamingContextExt

- Cration dune association : bind, rebind - Rsoudre une association : resolve - Dtruire une association : unbind

Programme indpendant lancer avant : orbd


Corba - Christophe Bouthier - Karim Baina - LORIA 38

Obtenir le Naming
Naming = objet CORBA

Racine de larbre de rfrence :

- Dfini en IDL - Associ au nom NameService

Possibilit de spcifier o chercher les initial_references


Corba - Christophe Bouthier - Karim Baina - LORIA

- Mthode resolve_initial_references de lORB - Conversion en NamingContext ou NamingContextExt

39

Naming dans JavaIDL : cot serveur


Lancer orbd avant Rcuprer le Naming :

- orb.resolve_initial_references("NameService") retourne un objet CORBA Puis cast avec NamingContextExtHelper.narrow(obj)

Crer une association (objet NamingContextExt) :

- to_name("NOM") retourne un cheming sous forme de


NameComponent[] Puis enregistrement avec rebind(chemin, obj)

Corba - Christophe Bouthier - Karim Baina - LORIA

40

Naming dans JavaIDL : cot client


Mme initialisation/rcupration :

- orb.resolve_initial_references("NameService") retourne un objet CORBA Puis cast avec NamingContextExtHelper.narrow(obj)

Rcupration de lobjet CORBA partir du nom :

- ns.resolve(ns.to_name("NOM")) retourne un objet CORBA Puis cast avec MonObjetHelper.narrow(obj)

Corba - Christophe Bouthier - Karim Baina - LORIA

41

CORBA

Mico

Corba - Christophe Bouthier - Karim Baina - LORIA

42

Mico Is COrba
ORB CORBA en C++ Open-source et libre (GPL) Multi-plateforme :

- Linux/Unix - Windows

- MacOS X - Pocket PC

Visual C++ Cygwin

Corba - Christophe Bouthier - Karim Baina - LORIA

43

Client
idl : compilateur idl vers C++ Compilation :

- Syntaxe : idl <fichier.idl> - Gnre monObjet.cc

Indiquer o trouver le Naming :


Corba - Christophe Bouthier - Karim Baina - LORIA

- Compiler monObjet.cc en monObjet.o - Lier avec monObjet.o, mico2.3.5, micocoss2.3.5, dl, m


<client> -ORBDefaultInitRef corbaloc::localhost:<port>
44

Code client / 1
Initialisation ORB :
objet ORB_var

- Namespace CORBA - Fonction ORB_init(argc, argv, "mico-local-orb") retourne un - Namespace CosNaming - resolve_initial_references("NameService") de lobjet ORB - retourne un objet CORBA (CORBA::Object_var) - Cast avec mthode de classe _narrow(obj) de la classe
NamingContextExt
45

Name Service :

Corba - Christophe Bouthier - Karim Baina - LORIA

Code client / 2
Naming (suite)

- Cast retourne un objet NamingContextExt_var - Mthode resolve_str("Nom") de lobjet NamingContextExt_var - Retourne un objet CORBA - Cast avec la mthode de classe _narrow(obj) de la classe MonObjet Retourne un objet MonObjet_var

Rcuperation dun objet par le Naming :

Corba - Christophe Bouthier - Karim Baina - LORIA

46

Conclusion
Solution non propritaire Standard Libre choix de limplmentation et du langage Solution fonctionnelle dinteroprabilit Plusieurs implmentations libres et open-source

Mais : un peu usine gaz


Corba - Christophe Bouthier - Karim Baina - LORIA 47

Vous aimerez peut-être aussi