Intro duction to Distributed Objects with CORBA Douglas C. Schmidt W ashington Universit y, St. Louis http://www.cs.wustl.edu/
schmidt/ [email protected]
1Motivation
Typical state of aairs to da yis the \Dis- tribution Crisis"
{Computers and net wo rks get faster and cheap er
{Communication soft wa re gets slo wer, buggier, mo re exp ensive
Accidental complexit yis one source of prob- lems, e.g. ,
{Incompatible soft wa re infrastructures
{Continuous rediscovery and reinvention of co re concepts and comp onents
Inherent complexit y is another source of problems
{e.g. ,latency ,pa rtial failures, pa rtitioning, causal ordering, etc.
2Candidate Solution: CORBA
DII ORB
INTERFACE
CORE ORB operation()
IDL
STUBS OBJECT
ADAPTER SKELETON
IDL DSI
in args out args + return value
CLIENT
GIOP / IIOP
SERVANT
STANDARD INTERFACE STANDARD LANGUAGE
MAPPING
ORB-
SPECIFIC INTERFACE STANDARD PROTOCOL
Goals
1. Simplify development of distributed applications 2. Provide exible foundation for higher-level ser-
vices
Distributed Medical Imaging
D
DIIAAGGNNOOSSTTIICC S
STTAATTIIOONNSS
A AT TM M M MA AN N
A ATTMM L LAANN
A ATTMM
L LAANN
M
MOODDAALLIITTIIEESS
((
CCTT,,
MMRR,,
CCRR))
CCEIIMENMANTAGTRGERAEALL S STTOORREEC
CLLUUSSTTEERR IIMMAAGGEE S STTOORREE D
DXX IIMMAAGGEE S STTOORREE
4
Distributed Objects in Medical Imaging
:: BLOB BLOB DISPLAY DISPLAY
:: NAME NAME SERVER
SERVER :: BLOB BLOB
ROUTER ROUTER
:: BLOB BLOB PROCESSOR PROCESSOR
SOFTWARE BUS SOFTWARE BUS
:: NETWORK NETWORK TIME TIME
:: IMAGE IMAGE
LOCATOR LOCATOR
:: IMAGE IMAGE
SERVER SERVER
:: IMAGE IMAGE
PRINTER
PRINTER :: IMAGE IMAGE SERVER SERVER:: BLOB BLOB
SERVER SERVER
:: BLOB BLOB LOCATOR LOCATOR
\Blob" == Binary Large OBject
Real-time Avionics
OBJECT
OBJECT REQUEST REQUEST BROKER BROKER 2:
PUSH(
EVENTS)
Frame Air
Sensor proxy
HUD Nav
EVENT CHANNEL
Sensor proxy Sensor
proxy
3:
PUSH(
DEMARSHALED DATA)
1:
SENSORS GENERATEDATA
6
Telecommunications
WIDE AREA NETWORK
SATELLITES
SATELLITES TRACKING TRACKING STATION STATION PEERS PEERS
STATUS INFO
COMMANDS BULK DATA
TRANSFER
LOCAL AREA NETWORK
GROUND STATION PEERS
GATEWAY
Outline
Motivation
Example CORBA Applications
Coping with Changing Requirements
Overview of CORBA Architecture
Evaluations and Recommendations
Motivation
Developing distributed applications whose
components collaborate eciently, reliably, transparently, and scalably is hard
To help address this challenge, the Object Management Group (OMG) is specifying the Common Object Request Broker Ar- chitecture (CORBA)
{
OMG is a consortium of computer companies
e.g., Sun, HP, DEC, IBM, IONA, Visigenic,
etc.
Version 2.1 of the CORBA spec is now available
{
http://www.omg.org/corba/corbiiop.htm
Stand-alone vs. Distributed Application Architectures
PRINTER
SYSTEMFILE
PRINTER FILE SYSTEM
COMPUTER COMPUTER
(1)
(1)
STAND-ALONE STAND-ALONE
APPLICATION APPLICATION
ARCHITECTURE ARCHITECTURE
(2)
(2)
DISTRIBUTED DISTRIBUTED
APPLICATION APPLICATION
ARCHITECTURE ARCHITECTURE
CD ROM
CD ROM
NETWORK SERVICEFI LE CYCLE SERVICE DISPLAY
SERVICE
PRINT SERVICE
NAME SERVICE
TIME SERVICE
10
Sources of Complexit y Distributed application development exhibits both inherent and accidental complexit y Inherent complexit y results from funda- mental challenges in the distributed ap- plication domain, e.g. , {Addressing the impact of latency
{Detecting and recovering from pa rtial failures of net wo rks and hosts
{Load balancing and service pa rtitioning
{Consistent ordering of distributed events
11
Sources of Complexit y(cont'd)
Accidental complexit yresults from limita- tions with to ols and techniques used to develop distributed applications, e.g. ,
{Lack of typ e-safe, po rtable, re-entrant, and ex- tensible system call interfaces and comp onent lib raries
{Inadequate debugging supp ort
{Widesp read use of algo rithmic decomp osition
Fine for explaining net wo rk programming con- cepts and algo rithms but inadequate for de- veloping large-scale distributed applications
{Continuous rediscovery and reinvention of co re concepts and comp onents
12Motivation for CORBA Simplies application interw orking {CORBA provides higher level integration than traditional \unt yp ed TCP bytestreams" Provides afoundation for higher-level dis- tributed object collab oration
{e.g. ,Windo ws OLE and the OMG Common Object Service Sp ecication (COSS) Benets for distributed programming sim- ila rto OO languages for non-distributed programming
{e.g. ,encapsulation, interface inheritance, and object-based exception handling
13
CORBA Contributions
CORBA addresses tw o challenges of de- veloping distributed systems: 1. Making distributed application development no mo re dicult than developing centralized pro- grams
{Easier said than done due to:
Pa rtial failures
Impact of latency
Load balancing
Event ordering 2. Providing an infrastructure to integrate appli- cation comp onents into adistributed system
{i.e. ,CORBA is an \enabling technology"
14CORBA Quoter Example Ideally ,to use a distributed service, we'd lik eit to look much lik ea non-distributed service: int main(void) { //Useafactorytobindtoanyquoter. Quoter_varquoter=bind_quoter_service(); constchar*stock_name="ACMEORBInc."; CORBA::Longvalue=quoter->get_quote(stock_name); cout<<stock_name<<"="<<value<<endl; return0; } Unfo rtunately ,life is ha rder when erro rs occur
::: 15
CORBA Quoter Interface
W eneed to write an OMG IDL interface for our Quoter object
{This interface isused by both clients and servers
//IDLinterfaceislikeaC++class //orJavainterface. interfaceQuoter { exceptionInvalid_Stock{}; longget_quote(instringstock_name) raises(Invalid_Stock); };The use of OMG IDL promotes language indep endence, location transpa rency ,mo d- ula rit y, and robustness
16OMG IDL Compiler
CLIENT CLIENT STUB BODY STUB BODY
CLIENT CLIENT STUB HEADER STUB HEADER
SERVER SERVER SKELETON SKELETON HEADER HEADER
SERVER SERVER SKELETON SKELETON
BODY BODY IDL COMPILER
IDL FILE
COMPILER C++
COMPILER JAVA
CLIENT SOURCE CODE
CLIENT SOURCE CODE
CLIENT SOURCE CODE CLIENT
PROGRAM
SERVER SOURCE CODE SERVER SOURCE CODE SERVER SOURCE CODE
SERVER PROGRAM CORBA
RUN-TIME LIBRARIES
interface Quoter interface Quoter
{{ long get_quote (in string name);
long get_quote (in string name);
};
};
A OMG IDL compiler generates client stubs
and server skeletons
Software Bus
:: NETWORK NETWORK TIME TIME
:: LOCATION LOCATION BROKER BROKER
:: TRADING TRADING RULES RULES
:: HEARTBEAT HEARTBEAT MONITOR MONITOR
: STOCK QUOTER
: PRINTER
: AUTHEN-
TICATOR
: STOCK TRADER
: STOCK QUOTER
SOFTWARE BUS :: STOCK STOCK
QUOTER QUOTER
CORBA provides a communication infras-
tructure for a heterogeneous, distributed collection of collaborating objects
Analogy to \hardware bus"
CORBA Object Collaboration
::
NAME NAMESERVICE SERVICE
::
QUOTE QUOTESERVICE SERVICE
::
AUTHEN AUTHEN--
TICATION TICATION 1: resolve ("Quoter")
1: resolve ("Quoter")
::
BROKER BROKER2: authenticate (broker) 2: authenticate (broker) 3: timestamp()
3: timestamp() 4: get_quote ("ACME ORB, Inc.")
4: get_quote ("ACME ORB, Inc.")
::
NETWORK NETWORK TIME TIME
In theory, collaborating objects may be
either local (co-located) or remote (dis- tributed)
In practice, beware of traps and pitfalls
:::Communication Features
Communication features of standard CORBA:
{
Supports both synchronous and \quasi-asynchronous"
communication styles
i.e., oneway, twoway, and deferred synchronous
{
Supports best-eort, uni-cast communication
Note that all of these features may be ex-
tended depending on vendor \quality of ser- vice"
CORBA objects may collaborate in a client/server, peer-to-peer, or publish/subscribe manner
{
client/server and peer-to-peer are built into the
standard library
{
e.g., COSS Event Services denes a publish/subscribe
communication paradigm
Related W ork Traditional RPC (e.g. ,DCE) {Provides \p ro cedural" integration of applica- tion services
{Do esn't provide object abstractions or message passing
{Do esn't address inheritance of interfaces Windo ws OLE/COM
{Traditionally limited to desktop applications
{Do es not address heterogeneous distributed com- puting (yet)
Distributed COM (DCOM) is no w app ea ring on multiple platfo rms
21
Related W ork (cont'd)
Java RMI
{Limited to Java only
{Can be extended into other languages (e.g. ,C or C++) by using ab ridge across JNI
{W ell-suited for all-Java applications because of its tight integration with the Java virtual ma- chine
22CORBA Application Example
FDDI
OS/2 - PowerPC SunOS - SPARC HP/UX - HPPA Windows NT - Alpha Gateway/Router MVS - IBM
WIDE AREA WIDE AREA NETWORK NETWORK
ETHERNET ETHERNET ATM
ATMLANLAN
BROKERS BROKERS
BROKERS BROKERS
QUOTE QUOTE SERVERS SERVERS
Windows- Pentium
Stock quoter/trader application
Stock Quoter/Trader Application
The quote server(s) maintains the current
stock prices
Brokers access the quote server(s) via CORBA
interfaces and the CORBA run-time
Since the server(s) and the brokers are dis-
tributed, the solution must work across
LAN and WAN environments
Initial OMG IDL Quoter Specication
A module is a high-level grouping construct
module Stock {
// An exception is a combination of a struct // and an event.
exception Invalid_Stock {};
exception Invalid_Quoter {};
// Interface is similar to a C++ class.
interface Quoter {
long get_quote (in string stock_name) raises (Invalid_Stock);
};
// Manage the lifecycle of a Quoter object.
interface Quoter_Factory {
// Returns a new Quoter selected by name // e.g., "Dow Jones," "Reuters,", etc.
Quoter create_quoter (in string name) raises (Invalid_Quoter);
void destroy_quoter (in Quoter quoter);
};
};
RPC-style vs. Object-style Communication
QUOTE QUOTE SERVER SERVER : Reuters
: Reuters Quoter Quoter
: DowJones Quoter
: Quoter : Quoter Factory Factory QUOTE
CLIENT
: DowJones : DowJones
Quoter Quoter Proxy Proxy : Quoter
: Quoter Factory Factory Proxy Proxy
get_quote() get_quote() destroy() destroy()
create_quoter() create_quoter()
name name value value name name
Quoter Quoter : Reuters
: Reuters Quoter Quoter Proxy Proxy QUOTE CLIENT QUOTE CLIENT
QUOTE SERVER : Quoter
: Quoter Proxy Proxy
: Quoter : Quoter get_quote()
get_quote() name name value value
RPCRPC --- STYLESTYLE OBJECTOBJECT --- STYLESTYLE
: Quoter : Quoter Proxy Proxy
26
Compiling the Interface Denition
Running the the IDL compiler generates client stubs and server skeletons Stock module denition through
{
The client stub is a proxy that handles param-
eter marshalling from requestor
{
The server skeleton handles parameter demar-
shalling to the target
CORBA associates a servant to a gener- ated IDL skeleton as follows:
1. The Class form of the Adapter pattern (inher- itance)
POA Stock::Quoter
2. The Object form of the Adapter pattern (ob- ject composition, i.e., TIE)
template
<class Impl
>class POA Stock::Quoter tie
Using the Class Form of the Adapter Pattern with POA Stock::Quoter Factory
client client
Quoter Quoter Factory Factory
create_quoter() = 0 A
My Quoter My Quoter Factory Factory
create_quoter()
1: create_quoter ()
A Servant based on Inheritance
Note inheritance from POA Stock::Quoter Factory
class My_Quoter_Factory
: public virtual POA_Stock::Quoter_Factory
{public:
My_Quoter_Factory (void);
// Factory method for creation.
virtual Stock::Quoter_ptr create_quoter (const char *name);
// Factory method for destruction.
virtual void destroy_quoter (Stock::Quoter_ptr quoter);
// ...
};
The drawback is that implementations in- herit from generated skeletons
{
Can create a \brittle" hierarchy
{
Hard to integrate with legacy code (i.e., dis-
tributing an all-local application)
Using the Object Form of the Adapter Pattern with TIE
client
client Quoter Quoter
Factory Factory
A
Quoter Quoter Factory_tie Factory_tie
create_quoter() = 0
create_quoter()
My Quoter My Quoter Factory Factory
create_quoter() 1: create_quoter ()
2: create_quoter()
My_Quoter My_Quoter Factory Factory
30
A Servant based on Object Comp osition Allo ws the distribution of classes that were devel- op ed without prio rkno wledge of CORBA //Note,thereisnouseofinheritanceand //methodsneednotbevirtual! classMy_Quoter_Factory
{ public: My_Quoter_Factory(void); //Factorymethodforcreation. Stock::Quoter_ptrcreate_quoter(constchar*name); //Factorymethodfordestruction. voiddestroy_quoter(Stock::Quoter_ptrquoter); private: //... }; 31
TIE-based Implementations
IDL compiler generates TIE adapter class
classPOA_Stock //Note:POA_Stockisreallyanamespace { template<classImpl> classQuoter_Factory_tie:publicQuoter_Factory { //...}; //
...
}; POA_Stock::Quoter_Factory_tie
<My_Quoter_Factory> factory(newMy_Quoter_Factory);
This scheme places an implementation pointer object within the TIE class
All metho dcalls via the interface class are then delegated to the implementation ob- ject
{i.e. ,the \object form" of the Adapter pattern!
32Implementing the Metho ds A develop er then writes C++ denitions for the metho ds in class My Quoter Facto ry: {This solution uses the inheritance app roach
Stock::Quoter_ptr My_Quoter_Factory::create_quoter
(constchar*name) { POA_Stock::Quoter*quoter; //PerformFactoryMethodselectionof //thesubclassofQuoter. if(strcmp(name,"DowJones")==0) quoter=newDow_Jones_Quoter; //... elseif(strcmp(name,"MyQuoter")==0) //DynamicallyallocateanewMy_Quoterobject. quoter=newMy_Quoter; else throwStock::Invalid_Quoter;//Raiseexception. //ThiswillcreateaStock::Quoter_ptrandregister //theservantwiththedefault_POA. returnquoter->_this(); }; 33
The Main Server Program
This example uses \sha red activation" mo de
void main
(intargc,char*argv[]) { CORBA::ORB_varorb=CORBA::ORB_init(argc,argv,0); CORBA::Object_ptrpfobj= orb->resolve_initial_references("RootPOA"); PortableServer::POA_varrootPOA; rootPOA=PortableServer::POA::_narrow(pfobj); My_Quoter_Factoryfactory; //CouldalsousetheTIEapproach: //POA_Stock::Quoter_Factory_tie<My_Quoter_Factory> //factory(newMy_Quoter_Factory); //RegisterservantwithPOA //Couldalsousefactory._this()here rootPOA->activate_object(&factory); //Willblockindefinitelywaitingforincoming //invocationsanddispatchingmethodcallbacks. orb->run(); //Afterrun()returns,theORBhasshutdown. } 34
Client-side Stubs Generated by an OMG IDL compiler, e.g. , classStock //Note:Stockisreallyanamespace { classQuoter//QuoterIS-ACORBA::Object. :publicvirtualCORBA::Object
{ public: //Proxyinterface. CORBA::Longget_quote(constchar*stock_name); }; .classQuoter_Factory//Quoter_FactoryIS-ACORBA::Object :publicvirtualCORBA::Object
{ public: //ProxyFactorymethodforcreation. Quoter_ptrcreate_quoter(constchar*name); //ProxyFactorymethodfordestruction. voiddestroy_quoter(Quoter_ptrquoter); }; //... }; 35
OMG IDL Mapping Rules
The CORBA sp ecication denes map- pings from CORBA IDL to va rious pro- gramming languages
{e.g. ,C++, C, Smalltalk, Java (p rop osed)
Mapping OMG IDL to C++
{Each module is mapp ed to a class or names- pace
{Each interface within a module is mapp ed to anested C++ class
{Each op eration is mapp ed to aC++ metho d with app rop riate pa rameters
{Each read/write attribute is mapp ed to apair of get/set metho ds
A read-only attribute is only mapp ed to a single get metho d
{An Environment is dened to ca rry exceptions in languages lacking exceptions
36Binding aClient to aT arget Object Typically tw osteps: 1. A CORBA client (requesto r) obtains an \ob- ject reference" from aserver {e.g. ,Ma yuse anaming service or alo cato r service 2. The client ma y then invok e metho ds on its pro xy Recall that object references ma ybe passed as pa rameters to other remote objects
37
Binding aClient to aT arget Object (cont'd)
Object references are rep resented by dif- ferent generated typ es
{ptr require programmer management of ref- erence ownership
Pointer to object reference
{var internally manages reference ownership
Auto pointer to object reference
{out eases passing out pa rameters be tw een client and server
Never used directly by user
38A Client Program Client binds to object and invok es metho d intmain(intargc,char*argv[]) { //Useafactorytobindtoanyquoter. Stock::Quoter_Factory_varqf= bind_service<Stock::Quoter_Factory> ("My_Quoter_Factory",argc,argv); if(CORBA::is_nil(qf))return-1; Stock::Quoter_varquoter;//Managesrefcounts. constchar*stock_name="ACMEORBInc."; try{//Bindtoaquoterandmakecall. quoter=qf->create_quoter("My_Quoter"); CORBA::Longvalue=quoter->get_quote(stock_name); cout<<stock_name<<"="<<value<<endl; }catch(Stock::Invalid_Stock&){ cerr<<stock_name<<"notavalidstock"<<endl; }catch(...){/*Handleexception...*/} qf->destroy_quoter(quoter); //Destructorsof*_varproxiesreleasememory. } 39
Obtaining an Object Reference
e.g. ,using the COS Naming Service
staticCosNaming::NamingContext_ptrname_context=0; template<classT>T* bind_service(constchar*name, intargc,char*argv[]){ CORBA::Object_varobj; if(name_context==0){//"Firsttimein"check. //Getreferencetonameservice. CORBA::ORB_varorb=CORBA::ORB_init(argc,argv,0); obj=orb->resolve_initial_references("NameService"); name_context= CosNaming::NamingContext::_narrow(obj); if(CORBA::is_nil(name_context))return0;} CosNaming::Name
svc_name; svc_name.length(1);svc_name[0].id=name; //Findobjectreferenceinthenameservice. obj=name_context->resolve(svc_name); //NarrowtotheTinterfaceandawaywego! returnT::_narrow(obj); } 40
Server Activation If the server isn't running when a client invok es a metho d on an object it man- ages, the ORB will automatically sta rt the server Servers must be registered with the ORB in the \Implementation Rep osito ry" {e.g. ,in Orbix
%putit Quoter Facto ry /usr/svcs/Quoter/quoter.exe Server(s) ma ybe installed on any machine Clients ma ybind to an object in aserver by using the Naming Service or by explic- itly identifying the server
41
Server Activation Mo des
An idle server will be automatically launched when one of its objects is invok ed
There are four server activation mo des 1. Sha red
!one pro cess per-object pe r-host 2. Unsha red
!each individual object gets its own pro cess 3. Per-metho d call
!each metho d call gets its own pro cess 4. Persistent
!launched \manually"
42Coping with Changing Requirements New features {Fo rmat changes to extend functionalit y
{New interfaces and op erations Imp roving existing features
{Server location indep endence (requires sma rt ORB)
{Batch requests
43
New Fo rmats
e.g. ,p ercentage that sto ck increased or decreased since sta rt of trading da y, vol- ume of trades, etc.
moduleStock { //... interfaceQuoter { longget_quote(instringstock_name, outdoublepercent_change, outlongtrading_volume) raises(Invalid_Stock); }; };Note that even making this simple change would involve a great deal of wo rk for a so ck ets-based solution
::: 44Adding Features Unobtrusively
Interface inheritance allo ws new features to be added without breaking existing in- terfaces
moduleStock { //... interfaceQuoter{/*...*/}; interfaceStat_Quoter :Quoter//aStat_QuoterIS-AQuoter { voidget_stats(instringstock_name, outdoublepercent_change, outlongtrading_volume) raises(Invalid_Stock); }; };Note that there are no changes to the ex- isting Quoter interface
45New Interfaces and Op erations
e.g. ,adding atrading interface
moduleStock{ //interfaceQuoter_FactoryandQuoter //Sameasbefore. interfaceTrader{ voidbuy(instringname, inoutlongnum_shares, inlongmax_value) raises(Invalid_Stock); voidsell(instringname, inoutlongnum_shares, inlongmin_value) raises(Invalid_Stock); }; interfaceTrader_Factory{/*...*/}; };Multiple inheritance isalso useful to dene afull service brok er:
interfaceBroker:Stat_Quoter,Trader{}; 46Batch Requests
Improve performance for multiple queries
or trades
interface Batch_Quoter
: Stat_Quoter // A Batch_Quoter IS-A Stat_Quoter
{ typedef sequence<string> Names;
struct Stock_Info { string name;
long value;
double change;
long volume;
};typedef sequence<Stock_Info> Info;
exception No_Such_Stock {
Names stock; // List of invalid stock names };
void batch_quote (in Names stock_names, out Info stock_info) raises (No_Such_Stock);
};
CORBA ORB Architecture
NETWORK NETWORK DII
DII ORBORB
INTERFACE INTERFACE
ORB CORE ORB CORE op()
op()
IDL
STUBSIDL
STUBS OBJECTOBJECT
ADAPTER ADAPTER
IDL IDL
SKELETON SKELETON DSIDSI
in args out args + return value
CLIENT
OS KERNEL
OS I/O SUBSYSTEM NETWORK ADAPTERS
OS KERNEL
OS I/O SUBSYSTEM NETWORK ADAPTERS
INTERFACE REPOSITORY
IMPLEMENTATION REPOSITORY COMPILERIDL
NAMING SERVICE
GIOP
/
IIOPSERVANT
48
CORBA Components
The CORBA specication is comprised of several parts:
1. An Object Request Broker (ORB) Core 2. An Interoperability Spec (GIOP and IIOP) 3. An Interface Denition Language (IDL) 4. Programming language mappings for IDL 5. A Static Invocation Interface (SII)
6. A Dynamic Invocation Interface (DII) 7. A Dynamic Skeleton Interface (DSI) 8. Portable Object Adapter (POA)
9. Interface and implementation repositories
Other documents from OMG describe com- mon object services built upon CORBA (CORBAservices)
{
e.g., Event services, Name services, Lifecycle
services
OMA Reference Model Interface Categories
OBJECT REQUEST BROKER OBJECT REQUEST BROKER
OBJECT OBJECT SERVICES SERVICES APPLICATION
APPLICATION INTERFACES
INTERFACES DOMAINDOMAIN INTERFACES
INTERFACES COMMONCOMMON FACILITIES FACILITIES
The Object Management Architecture (OMA)
Reference Model describes the interactions between various CORBA components and layers
50
ORB Core
OBJECT ADAPTER
I/O SUBSYSTEM ORB CORE
GIOP TRANSPORT PROTOCOLS
IIOP/TCP/IP ATM RTP ISIS
ENDPOINT DEMULTIPLEXER
Provides basic concurrency and communi-
cation mechanisms
CORBA Interoperability Protocols
General Inter-ORB Protocol (GIOP)
{
Species request format and transmission pro-
tocol that enables ORB-to-ORB interoperabil- ity
Internet Inter-ORB Protocol (IIOP)
{
Species a standardized interoperability proto-
col for the Internet
{
Works directly over TCP/IP, no RPC necessary
Environment-specic inter-ORB protocols (ESIOPs)
{
e.g., DCE
GIOP Overview Common Data Rep resentation (CDR) {Transfer syntax mapping OMG-IDL data typ es into abi-canonical low-level rep resentation
Supp orts va riable byte ordering and aligned primitive typ es Message transfer
{Request multiplexing
i.e. ,multiple clients can sha re aconnection to an ORB
{Ordering constraints are minimal
i.e. ,can be asynchronous Message formats
{Client: Request , CancelRequest , LocateRequest
{Server: Reply , LocateReply , CloseConnection
{Both: MessageError
53
GIOP Overview (cont'd)
GIOP mo dule
moduleGIOP{ enumMsgType{ Request,Reply,CancelRequest,LocateRequest, LocateReply,CloseConnection,MessageError }; structMessageHeader{ charmagic[4]; VersionGIOP_version; booleanbyte_order; octetmessage_type; unsignedlongmessage_size; }; structrequestHeader{ IOP::ServiceContextListservice_context; unsignedlongrequest_id; booleanresponse_requested; sequence<octet>object_key; stringoperation; Principalrequesting_principal; }; //...
IIOP Overview
IIOP Adds to GIOP semantics for TCP/IP
connection management
IIOP bundled with Netscape 4.0
Inter-ORB Engine available from SunSoft
{
ftp://ftp.omg.org/pub/interop/iiop.tar.Z
TAO is originally based on SunSoft IIOP
{
However, TAO adds many enhancements and
optimizations
Design of TAO's IIOP Protocol Engine
DII
DII ORBORB
INTERFACE INTERFACE
operation() operation()
OBJECT OBJECT ADAPTER ADAPTER
DSI DSI
in args in args out args + return value out args + return value
CLIENT CLIENT
ORB CORE ORB CORE
TYPECODE INTERPRETER TypeCode::traverse()
CDR::
encoder()
visit()
deep_free()
CDR::
decoder() deep_copy()
deep_free()
visit()
CDR::
decoder()
deep_copy() CDR::
encoder() REQUEST
REQUEST
RESPONSE RESPONSE
TYPECODE INTERPRETER TypeCode::traverse()
RECEIVER RECEIVER SENDER
SENDER
IDL
STUBSIDL
STUBS
IDL
SKELETONIDL
SKELETON
SERVANT SERVANT
56
TypeCode Layout for BinStruct Sequence
TK TK__SEQUENCESEQUENCE TCK
TCKIND IND __KINDKIND UL
ULONG LENGTHONG LENGTH 128128 OCTET
OCTET *_*_BUFFERBUFFER
BYTE ORDER
BYTE ORDER 00
ELEMENT
ELEMENT TTYPEYPECCODE KINDODE KIND TKTK__STRUCTSTRUCT ENCAPSULATION LENGTH
ENCAPSULATION LENGTH 112112 ENCAPSULATION ENCAPSULATION BOUNDS OF THE SEQUENCE BOUNDS OF THE SEQUENCE 00
ENCAPSULATION ENCAPSULATION FOR ARRAY FOR ARRAY MEMBER
0 0 0 1 1
BYTE ORDER OF ENCAPSULATION
6
ACTUAL NAME OF STRUCT LENGTH OF STRING STRUCT NAME ACTUAL STRING ID LENGTH OF STRING ID
ACTUAL NAME OF MEMBER OF TYPE SHORT
LENGTH OF STRING NAME FOR STRUCT MEMBER OF TYPE SHORT NUMBER OF MEMBERS IN STRUCT
1 0
TK_SHORT TYPECODE KIND FOR MEMBER OF T YPE SHORT
LENGTH OF STRING NAME FOR STRUCT MEMBER OF ARRAY TYPE ACTUAL NAME OF MEMBER OF ARRAY TYPE
TYPECODE KIND FOR MEMBER OF TYPE ARRAY ENCAPSULATION LENGTH FOR ARRAY MEMBER
1 0
TK_ARRAY
12
0 BYTE ORDER FOR ENCAPSULATION SIZE OF ARRAY
TYPECODE KIND FOR ELEMENT OF ARRAY
8
TK_OCTET
TypeCode Interpreter Structure
_ttcp_sequence_
sendStructSeq_skel() CREATE NVLIST AND POPULATE IT WITH PARAMETER TYPECODES for each parameter
get the typecode, tc CDR::decoder(tc,val,0,
strm,env) ServerRequest::params() PARSING PARAMETERS
PARSING PARAMETERS TypeCode::traverse(value1,TypeCode::traverse(value1,
value2,visit,strm,env) value2,visit,strm,env)
if (primitive typecode) return visit(this,val1,val2,
strm,env);
switch(_kind){
//complex typecodes case tk_sequence:
OctetSeq *seq = (OctetSeq *)val1;
bounds = seq->length;
value1 = seq->buffer;
goto shared_array_code;
case tk_array:
bounds=ulong_param(1, env);
shared_array_code:
TypeCode_ptr tc2 = typecode_param(0, env);
size = tc2->size(env);
while(bounds--){
visit(tc2,val1,val2,strm,env);
value1=size + (char*)val1;
value2=size + (char *)val2;
case tk_struct:} create an encapsulation CDR stream for our params struct_traverse(&encap,val1,
val2,visit, strm,env);
}
struct_traverse(encap, struct_traverse(encap, val1, val2,visit,strm, val1, val2,visit,strm, env)
env) switch(tc->kind(env) {
case tk_char:
case tk_octet:
strm->get_char (*(char *)data);
break;
case tk_short:
strm->get_short (*(short *)data);
break;
case tk_long:
strm->get_long (*(long *)data);
break;
case tk_double:
strm->get_longlong (*(longlong *)data);
break;
case tk_sequence:
OctetSequence* seq = (OctetSeq *)data;
strm->get_ulong (seq->length);
seq->max=seq->length;
seq->buffer=0;
// get typecode of elem tc2=typecode_param(0);
size = tc2->size(env);
//allocate buffer seq->buffer=new uchar [ size*seq->max];
//Fall thru these cases case tk_struct:
case tk_array:
return tc->traverse (data, 0, decoder,
strm, env);
}
CDR::decoder(tc, data, CDR::decoder(tc, data, parent, strm, env) parent, strm, env)
RECEIVER
T
YPEC
ODE INTERPRETERskip_string; // repository id;
skip_string; // struct name;
get number of members;
for each member { skip_string; //member name size =
calc_nested_size_
and_align(&tc,align);
visit(tc,val1,val2,strm,env);
val1 = size + (char*)val1;
val2 = size + (char *)val2;
}
Interface Denition Language (IDL)
Developing exible distributed applications on heterogeneous platfo rms requires astrict sepa ration of interface from implementa- tion(s)
Benets of using an IDL
{Ensure platfo rm indep endence
e.g. ,Windo ws NT to UNIX
{Enfo rce mo dula rit y
e.g. ,must sepa rate concerns
{Increase robustness
e.g. ,reduce opp ortunities for net wo rk pro- gramming erro rs
{Enable language indep endence
e.g. ,COBOL to C++
59Related IDLs
Many IDLs are currently available, e.g. ,
{OSI ASN.1
{OSI GDMO
{SNMP SMI
{DCE IDL
{Microsoft's IDL (MIDL)
{OMG IDL
{ONC's XDR
Ho wever, many of these are pro cedural (rather than object-based or object-o riented ) IDLs
{Pro cedural IDLs are mo re complicated to ex- tend and reuse since they don't supp ort inher- itance
60CORBA Interface Denition Language (IDL) OMG IDL is an object-o riented interface denition language {Used to sp ecify interfaces containing op era- tions and attributes
{OMG IDL supp ort interface inheritance (b oth single and multiple inheritance) OMG IDL is designed to map onto multi- ple programming languages
{e.g. ,C, C++, Smalltalk, COBOL, Mo dula 3, DCE, Java, etc. OMG IDL is simila rto Java interfaces and C++ \abstract classes"
61
Application Interfaces
Interfaces describ ed using OMG IDL ma y be application-sp ecic, e.g. ,
{Databases
{Sp readsheets
{Sp ell check er
{Net wo rk manager
{Air trac control
{Do cuments
{Medical imaging systems
Objects ma y be dened at any level of granula rit y
{e.g. ,from ne-grained GUI objects to multi- megab yte multimedia \Blobs"
62OMG IDL Features OMG IDL is simila rto Java interfaces or C++ abstract base classes {Note, it is not a complete programming lan- guage, it only denes interfaces OMG IDL supp orts the follo wing features: * modules * interfaces *Op erations *A ttributes
*Inheritance *Basic
typ es (e.g. ,
double,
long,
char,etc). *Arra ys * sequence * struct, enum, union, typedef * consts * exceptions
63OMG IDL vs. C++
Dierences from C++ *No data memb ers *No pointers *No constructo rs or destructo rs *No overloaded metho ds *No
intdata typ e *Contains pa rameter passing mo des *Unions require atag *Dierent String typ e *Dierent Sequence typ e *Dierent exception interface *No templates *No control constructs *
onewaycall semantics *
readonlykeyw ord *Can pass \contexts" in op erations
Static Invocation Interface (SII)
The most common way of using OMG
IDL involves the \Static Invocation Inter- face" (SII)
In this case, all the methods are specied in advance and are known to the client and the server via proxies
{
Proxies are also known as surrogates
The primary advantage of the SII is its
simplicity, typesafety, and eciency
Proxy Pattern
NETWORK NETWORK
CLIENT
SERVER :: BROKER BROKER
1:
1: METHOD METHOD CALL CALL
4:
4: METHOD METHOD RETURN RETURN
:: QUOTER QUOTER
2:
2: FORWARD FORWARD REQUEST REQUEST
3:
3: RESPONSE RESPONSE
:: QUOTER QUOTER PROXY PROXY
Intent: provide a surrogate for another
object that controls access to it
66
Dynamic Invo cation Interface (DI I) A less common programming API is the \Dynamic Invo cation Interface" (DI I) {Enables clients to invok emetho ds on objects that aren't kno wn until run-time
e.g. ,MIB bro wsers
{Allo ws clients to \push" arguments onto are- quest stack and identify op erations via ASCI I name
{Typ e-checking via meta-info in \Interface Rep os- ito ry" The DI Iis mo re
exible than the SII
{e.g. ,it supp orts deferred synchronous invo ca- tion Ho wever, the DI Iis also mo re complicated, less typ esafe, and inecient
67
Dynamic Sk eleton Interface (DSI)
The \Dynamic Sk eleton Interface" (DSI) provides analogous functionalit y for the server-side that the DI Ip rovides on the client-side
It is dened in CORBA 2.x prima rily for using building ORB \Bridges"
The DSI lets server co de handle arbitra ry invo cations on CORBA objects
68Object References An \object reference" is an opaque handle to an object Object references ma ybe passed among pro cesses on sepa rate hosts {The underlying CORBA ORB will co rrectly con- vert object references into afo rm that can be transmitted over the net wo rk
{The ORB passes the receiver's implementation ap ointer to ap roxy in its own address space
This pro xy refers to the object's implemen- tation Object references are a po werful feature of CORBA
{e.g. ,supp orts peer-to-p eer interactions and dis- tributed callbacks
69
Using Object References
: Notifier: Notifier NETWORKCONSUMERCONSUMER AA CONSUMERCONSUMER BB
ConCon ObjRefObjRefBB
ConCon ObjRefObjRefAA1: subscribe (ObjRef1: subscribe (ObjRefAA)) B :B : ConsumerConsumer
4: push (event)4: push (event)
2: subscribe (ObjRef 2: subscribe (ObjRef B B))
4: push (event) 4: push (event)
NOTIFIERNOTIFIER
NotifierNotifier ObjRefObjRef 3: push (event) 3: push (event)
NotifierNotifier ObjRefObjRef A :A : ConsumerConsumer
NotifierNotifier ObjRefObjRef
SUPPLIERSUPPLIER
Passing object references is useful to im- plement a distributed event notication mechanism
70Event Receiver Interface An Consumer is called back by the Notifier {Note that all op erations are oneway to avoid blo cking
structEvent{ stringtag_;//Usedforfiltering. anyvalue_;//Eventcontents. }; interfaceConsumer { //InformtheConsumer //eventhasoccurred. onewayvoidpush(inEventevent); //DisconnecttheConsumerfromthe //Notifier,givingitthe<reason>. onewayvoiddisconnect(instringreason); }; 71
Notier Interface
A Notifier publishes Events
interfaceNotifier { //SubscribetheConsumerto //receiveeventsthatmatchfiltering_criteria //appliedbytheNotifier. onewayvoidsubscribe(inConsumerconsumer, instringfiltering_criteria); //UnsubscribetheConsumer. onewayvoidunsubscribe(inConsumerconsumer); //PushtheEventtoalltheconsumers //whohavesubscribedandwhomatchthe //filteringcriteria. onewayvoidpush(inEventevent); };Notier Implementation
The Notifier maintains a table of object
references to Consumers
class My_Notifier // C++ pseudo-code {
public:
void subscribe (Consumer *consumer, const char *fc) {
insert <consumer> into <consumer_set_> with <fc>.
}
void unsubscribe (Consumer *consumer) { remove <consumer> from <consumer_set_>.
}
void push (const Event &event) {
foreach <consumer> in <consumer_set_> loop
if (event.tag_ matches <consumer>.filter_criteria)
<consumer>.push (event);
end loop;
} private:
// e.g., use an STL set.
set <Consumer *> consumer_set_;
};
Object Adapter
REQUEST REQUEST QUEUES QUEUES
OBJECT
OBJECT ADAPTER ADAPTER II//O O SUBSYSTEM SUBSYSTEM
ORB C ORB CORE ORE
REQUEST
REQUEST DEMUXER DEMUXER ACTIVE
ACTIVE OBJECT OBJECT MAP MAP
SERVANTS
SERVANTS SERVANTS SERVANTS SERVANTS SERVANTS
Provide services that map object refer-
ences and requests to servants
74
Po rtable Object Adapter (cont'd)
Design goals
{Object implementations are po rtable be tw een ORBs
{Objects with persistent identities
Object implementations span multiple server lifetimes
{Transpa rent activation of objects
{Single servant can supp ort multiple object iden- tities
{Multiple instances of the PO A in aserver
{Transient objects with minimal programming eo rt and overhead
{Implicit activation of servants with PO A-allo cated Object Ids
{PO A behavio ris dictated by creation policies
{Object implementations can inherit from static skeleton classes, or aDSI implementation
75PO A Architecture
PO A Comp onents Client :Mak es requests on an object through one of its references Server :Computational context for an ob- ject implementation {Generally ,a server co rresp onds to ap ro cess
{Client and server are roles
,ap rogram ma yb e be both Object : A programming entit y with an identit y, an interface, and an implemen- tation Servant :A programming language entit y that implements requests on one or mo re objects
77
PO A Comp onents (cont'd)
Object Id: A value that is used by the PO A and by the implementation to iden- tify apa rticula rCORBA object
{Object Id values ma ybe assigned by the PO A, or by the implementation
{Object Id values are hidden from clients, en- capsulated by references
{Object Ids have no standa rd form; they are managed by the PO A as uninterp reted octet sequences
Object Reference : Encapsulates an Ob- ject Id and aPO A identit y
PO A: A namespace for Object Ids and a namespace for child PO As
{Nested PO As form a hiera rchical name space for objects within aserver
78PO A Comp onents (cont'd) Policy :Sp ecics the cha racteristics of the PO A PO A Manager :Encapsulates the pro cess- ing state of asso ciated PO As. {Used to queue or disca rd requests for the as- so ciated PO As
{Also used to deactivate the PO As Servant Manager : Callback object used to activate and deactivate servants on de- mand
{Tw okinds: ServantActivator and ServantLocator Adapter Activato r: Callback object used when arequest is received for achild PO A that do es not currently exist
{The adapter activato rcan then create the re- quired PO A on demand
79
PO A Examples
Getting the ro ot PO A
CORBA::ORB_ptrorb=CORBA::ORB_init(argc,argv); CORBA::Object_ptrpfobj= orb->resolve_initial_references("RootPOA"); PortableServer::POA_varrootPOA; rootPOA=PortableServer::POA::_narrow(pfobj);Creating aPO A
CORBA::PolicyListpolicies(2); policies[0]=rootPOA->create_thread_policy (PortableServer::ThreadPolicy::ORB_CTRL_MODEL); policies[1]=rootPOA->create_lifespan_policy (PortableServer::LifespanPolicy::TRANSIENT); PortableServer::POA_ptrpoa= rootPOA->create_POA ("my_poa", PortableServer::POAManager::_nil(), policies); 80
PO A Examples (cont'd) Explicit activation with PO A-assigned Ob- ject Ids //IDL interfaceFoo { longdoit(); }; classPOA_Foo:publicServantBase { virtualCORBA::Longdoit(void)=0; }; classMy_Foo_Servant:publicPOA_Foo { virtualLongdoit(void){return42;} }; My_Foo_Servant*afoo=newMy_Foo_Servant; PortableServer::ObjectId_varoid= poa->activate_object(afoo); poa->the_POAManager()->activate(); orb->run(); 81
PO A Examples (cont'd)
Explicit activation with user-assigned Ob- ject Ids
My_Foo_Servant*afoo=newMy_Foo_Servant; PortableServer::ObjectId_varoid= PortableServer::string_to_ObjectId("myFoo"); poa->activate_object_with_id(oid.in(),afoo);Creating references befo re activation
PortableServer::ObjectId_varoid= PortableServer::string_to_ObjectId("myFoo"); CORBA::Object_varobj= poa->create_reference_with_id(oid.in(), "IDL:Foo:1.0"); Foo_varfoo=Foo::_narrow(obj); //...later... My_Foo_Servant*afoo=newMy_Foo_Servant; poa->activate_object_with_id(oid.in(), afoo); 82Request Lifecycle for PO A
83Examples (cont'd)
Servant Manager Denition and Creation
//Skeletonclass namespacePOA_PortableServer { classServantActivator:publicvirtualServantManager { virtual~ServantActivator(); virtualServantincarnate(constObjectId&, POA_ptrpoa)=0; virtualvoidetherealize (constObjectId&, POA_ptrpoa, Servant, Booleanremaining_activations)=0; }; } 84