Vous êtes sur la page 1sur 15

Slides for Chapter 20:

CORBA Case Study

From Coulouris, Dollimore and Kindberg


Distributed Systems:
Concepts and Design
Edition 4, Addison-Wesley 2005
Figure 20.1
IDL interfaces Shape and ShapeList

structRectangle{ 1 structGraphicalObject{ 2
longwidth; stringtype;
longheight; Rectangleenclosing;
longx; booleanisFilled;
longy; };
};

interfaceShape{ 3
longgetVersion();
GraphicalObjectgetAllState(); //returnsstateoftheGraphicalObject
};

typedefsequence<Shape,100>All; 4
interfaceShapeList{ 5
exceptionFullException{}; 6
ShapenewShape(inGraphicalObjectg)raises(FullException); 7
AllallShapes();InstructorsGuideforCoulouris,Dollimore
//returnssequenceofremoteobjectreferences 8
longgetVersion();
};
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.2
Java interfaces generated by idlj from CORBA interface ShapeList

publicinterfaceShapeListOperations{
ShapenewShape(GraphicalObjectg)throwsShapeListPackage.FullException;
Shape[]allShapes();
intgetVersion();
}

publicinterfaceShapeListextendsShapeListOperations,org.omg.CORBA.Object,
org.omg.CORBA.portable.IDLEntity{}

InstructorsGuideforCoulouris,Dollimore
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.3
ShapeListServant class of the Java server program for CORBA interface ShapeList

importorg.omg.CORBA.*;
importorg.omg.PortableServer.POA;
classShapeListServantextendsShapeListPOA{
privatePOAtheRootpoa;
privateShapetheList[];
privateintversion;
privatestaticintn=0;
publicShapeListServant(POArootpoa){
theRootpoa=rootpoa;
//initializetheotherinstancevariables
} InstructorsGuideforCoulouris,Dollimore
//continuedonthenextslide
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.3 continued

publicShapenewShape(GraphicalObjectg)
throwsShapeListPackage.FullException{ 1
version++;
Shapes=null;
ShapeServantshapeRef=newShapeServant(g,version);
try{
org.omg.CORBA.Objectref=
theRoopoa.servant_to_reference(shapeRef); 2
s=ShapeHelper.narrow(ref);
}catch(Exceptione){}
if(n>=100)thrownewShapeListPackage.FullException();
theList[n++]=s;
InstructorsGuideforCoulouris,Dollimore
returns;
} andKindbergDistributedSystems:Concepts
publicShape[]allShapes(){...}
andDesignEdn.4
publicintgetVersion(){...}
PearsonEducation2005
}
Figure 20.4 Java class ShapeListServer

importorg.omg.CosNaming.*;importorg.omg.CosNaming.NamingContextPackage.*;
importorg.omg.CORBA.*;importorg.omg.PortableServer.*;
publicclassShapeListServer{
publicstaticvoidmain(Stringargs[]){
try{
ORBorb=ORB.init(args,null); 1

POArootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));2
rootpoa.the_POAManager().activate(); 3
ShapeListServantSLSRef=newShapeListServant(rootpoa); 4
org.omg.CORBA.Objectref=rootpoa.servant_to_reference(SLSRef); 5
ShapeListSLRef=ShapeListHelper.narrow(ref);
org.omg.CORBA.ObjectobjRef=orb.resolve_initial_references("NameService");

InstructorsGuideforCoulouris,Dollimore 6
NamingContextncRef=NamingContextHelper.narrow(objRef);
andKindbergDistributedSystems:Concepts 7
NameComponentnc=newNameComponent("ShapeList","");
andDesignEdn.4
NameComponentpath[]={nc}; 8
ncRef.rebind(path,SLRef);
PearsonEducation2005 9
orb.run(); 10
Figure 20.5
Java client program for CORBA interfaces Shape and ShapeList

importorg.omg.CosNaming.*;
importorg.omg.CosNaming.NamingContextPackage.*;
importorg.omg.CORBA.*;
publicclassShapeListClient{
publicstaticvoidmain(Stringargs[]){
try{
ORBorb=ORB.init(args,null); 1
org.omg.CORBA.ObjectobjRef=
orb.resolve_initial_references("NameService");
NamingContextncRef=NamingContextHelper.narrow(objRef);
NameComponentnc=newNameComponent("ShapeList","");
NameComponentpath[]={nc};
ShapeListshapeListRef=
ShapeListHelper.narrow(ncRef.resolve(path)); 2
InstructorsGuideforCoulouris,Dollimore
Shape[]sList=shapeListRef.allShapes(); 3
andKindbergDistributedSystems:Concepts4
GraphicalObjectg=sList[0].getAllState();
}catch(org.omg.CORBA.SystemExceptione){...}
andDesignEdn.4
}
PearsonEducation2005
Figure 20.6
The main components of the CORBA architecture

client server
implementation interface
repository repository object skeleton
adapter

client proxy Request ORB Servant


ORB
program for A core core A
Reply

or dynamic invocation or dynamic skeleton

InstructorsGuideforCoulouris,Dollimore
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.7
IDL module Whiteboard

moduleWhiteboard{
structRectangle{
...};
structGraphicalObject{
...};
interfaceShape{
...};
typedefsequence<Shape,100>All;
interfaceShapeList{
...};
}; InstructorsGuideforCoulouris,Dollimore
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.8
IDL constructed types 1

Type Examples Use


sequence typedefsequence<Shape,100>All; Definesatypeforavariablelength
typedefsequence<Shape>All sequenceofelementsofaspecified
boundedandunboundedsequences IDLtype.Anupperboundonthe
ofShapes lengthmaybespecified.

string Stringname; Definesasequencesofcharacters,


typedefstring<8>SmallString; terminatedbythenullcharacter.An
unboundedandbounded upperboundonthelengthmaybe
sequencesofcharacters specified.

array typedefoctetuniqueId[12]; Definesatypeforamultidimensional


typedefGraphicalObjectGO[10][8] fixedlengthsequenceofelementsofa
specifiedIDLtype.
InstructorsGuideforCoulouris,Dollimore
thisfigurecontinuesonthenextslide
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.8
IDL constructed types 2

Type Examples Use


record structGraphicalObject{ Definesatypeforarecordcontaininga
stringtype;
groupofrelatedentities.Structsare
Rectangleenclosing;
passedbyvalueinargumentsand
booleanisFilled;
results.
};

enumerated enumRand TheenumeratedtypeinIDLmapsa


(Exp,Number,Name); typenameontoasmallsetofinteger
values.
union unionExpswitch(Rand){ TheIDLdiscriminatedunionallows
caseExp:stringvote;
oneofagivensetoftypestobepassed
caseNumber:longn;
asanargument.Theheaderis
caseName:strings; parameterizedbyan enum,which
InstructorsGuideforCoulouris,Dollimore
}; specifieswhichmemberisinuse.
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Page 842
CORBA interoperable object references

IORformat

IDLinterfacetypename Protocolandaddressdetails Objectkey


interfacerepository IIOP hostdomain portnumber adaptername objectname
identifier name

InstructorsGuideforCoulouris,Dollimore
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.9
Naming graph in CORBA Naming Service

initial naming context initial naming context initial naming context

ShapeList B XX V
P
C
D E S T
R Q U

InstructorsGuideforCoulouris,Dollimore
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005
Figure 20.10
Part of the CORBA Naming Service NamingContext interface in IDL

structNameComponent{stringid;stringkind;};

typedefsequence<NameComponent>Name;

interfaceNamingContext{
voidbind(inNamen,inObjectobj);
bindsthegivennameandremoteobjectreferenceinmycontext.
voidunbind(inNamen);
removesanexistingbindingwiththegivenname.
voidbind_new_context(inNamen);
createsanewnamingcontextandbindsittoagivennameinmycontext.
Objectresolve(inNamen);
looksupthenameinmycontextandreturnsitsremoteobjectreference.
InstructorsGuideforCoulouris,Dollimore
voidlist(inunsignedlonghow_many,outBindingListbl,outBindingIteratorbi);
andKindbergDistributedSystems:Concepts
returnsthenamesinthebindingsinmycontext.
}; andDesignEdn.4
PearsonEducation2005
Figure 20.11
CORBA event channels

event channel
supplier consumer

notification notification notification


proxy consumer proxy supplier

InstructorsGuideforCoulouris,Dollimore
andKindbergDistributedSystems:Concepts
andDesignEdn.4
PearsonEducation2005

Vous aimerez peut-être aussi