1.59k likes | 1.79k Views
CORBA Outline. Introduction to CORBA Basic concepts IDL Simple Client/Server Example C++ Language Binding Other Issues IIOP Exception Handling CORBA Object Services Advanced Example. Introduction to CORBA. CORBA Goals and Philosophy Client/Server architecture
E N D
CORBA Outline • Introduction to CORBA • Basic concepts • IDL • Simple Client/Server Example • C++ Language Binding • Other Issues • IIOP • Exception Handling • CORBA Object Services • Advanced Example
Introduction to CORBA • CORBA Goals and Philosophy • Client/Server architecture • Intro to CORBA components • IDL • language constructs • examples
Object Management Group • Publish CORBA standard • Over 700 members: CORBA vendors, software vendors, users, academics • Meet every 6 to 8 weeks all over the world • Well-defined standardization process • fast, efficient, successful • Publishes interface standard • companies make compliant implementations
CORBA Key Concepts • Transparent Distribution • Objects • Client / Server model • Portable • across platforms, languages, networks • Standard
Distributed Application Architectures • Multiple computers on a network • Services can reside on any node • file service • name service • print service • CORBA transparently distributes applications
Object-Orientation • Objects - attributes and methods • Classes - clusters of objects with common behavior • Encapsulation - hide internal structure • Inheritance - define new class using existing class • Polymorphism - two or more classes respond to a method invocation differently
Client Server Model • Client makes method call of remote object • Call is forwarded by ORB to server • Object implementation receives the call and responds
CORBA Architecture Client Object Implementation IDL Skeleton Object Adapter Dyn. Inter- face IDL Stub ORB Interface Object Services: naming, events, life cycle, persistence, transactions, concurrency, relationships, externalization, object licensing, properties, object query. ORB OS Kernel OS Kernel Network
CORBA Components • Object Request Broker (ORB) core • Interoperability Spec. (GIOP and IIOP) • Interface Definition Language (IDL) • Programming Language Mappings • Static Invocation Interface (SII) • Dynamic Invocation Interface (DII) • Dynamic Skeleton Interface (DSI) • Portable Object Adaptor (POA) • Interface and implement repositories • Common Object Services (CORBAServices)
Lifecycle Naming Event Persistence Relationship Externalization Transaction Concurrency Security Time Licensing Query Trader Scheduling CORBA Services
Interface Definition Language (IDL) • IDL is object-oriented • specify interfaces containing operation and attributes • supports interface inheritance (single and multiple) • IDL designed to map to multiple programming languages • IDL similar to Java interfaces and C++ abstract classes
Application Interfaces • Interfaces defined using IDL can be application specific • databases, spreadsheets, spell checker, etc. • Objects may be defined at any level of granularity • fine-grained GUI objects • multi-megabyte multimedia “Blobs”
modules interfaces operations attributes inheritance basic types arrays sequence struct enum typedef const exceptions OMG IDL Features
C++ has - not IDL data members pointers constructors/destructors overloaded methods int data type templates control constructs Different in IDL string type sequence type exception interface unions require a tag New in IDL oneway call semantics readonly keyword pass “contexts” parameter passing modes IDL vs. C++
Modules • IDL module defines naming scope for a set of IDL definitions • Group interface and other IDL type definitions into logical name space • Avoid name clashes // IDL module finance interface account {. . .}; }; • Fully scoped name of interface account is finance::account
Interfaces • The basic unit is the interface • defining the interface to a type of object interface account { // operation and attribute definitions };
Operations • Look like C++/Java member functions • parameters must be named • parameter passing mode must be specified interface account { // operations void makeDeposit (in float amount); boolean makeWithdrawal (in float amount, out float balance);
Parameter Passing Modes • in passed from caller to called object • out passed from called object to caller • inout passed in both directions • CORBA must know the direction • to know how to pass the values
Raising Exceptions in IDL Operations • Operations can raise exceptions to indicate occurrence of an error • Two types of exceptions: • System exceptions - standard set defined by CORBA • User-defined exceptions // IDL module finance { interface account { exception WithdrawalFailure { string reason; }; void MakeWithdrawal(in float amount, out float newBalance) raises(WithdrawalFailure); . . . }; };
Attributes interface account { // attributes readonly attribute string dateLastModified; readonly attribute float balance; attribute string owner; } • Typically these map to two functions in the programming language • set the value • get the value • a readonly attribute maps only to a function to get the value
Attributes (cont) • Attributes do not necessarily represent state • e.g. • dateLastModified might be • stored as a member variable • as a string • as an integer value • calculated from the history of transactions
readonly Attributes • A readonly attribute is not necessarily a constant • an operation call can change it - e.g. • bad practice to modify a readonly attribute in the code that sets another attribute typedef string Date; interface file { readonly attribute Date dateLastModified; void write (…); void read (…); };
Inheritance • An IDL interface can inherit all elements of one or more other interfaces • All attributes and operations of account are valid on objects of interface checkingAccount interface checkingAccount : account { attribute float overdraftLimit; boolean orderCheckBook(); };
short (16 bit) long (32-bit) unsigned short (16-bit) unsigned long (32-bit) long long (64-bit) unsigned long long (64-bit) float double char (8-bit) wchar (16-bit) boolean (TRUE or FALSE) octet (8-bit - no conversion) any (arbitrary IDL type) string (can be bounded) Basic Types
IDL Constructed Types • Enum enum currency {pound, dollar, yen, franc}; • Struct struct customerDetails { string name; string age; }; • Union union Date switch (short) { case 1: string stringFormat; case 2: long digitalFormat; default: DateStructure structFormat; };
Other IDL Types • String - max can be specified attribute string sortCode<10>; • Sequence - 1D array- can be bounded or unbounded sequence<account, 50> accounts; • Array- can be multidimensional - always fixed-size account accounts[3]; • Constant const long MaxAccounts = 10000;
Mapping to a Programming Language • for each programming language supported by CORBA, a mapping must be given from IDL to that language • e.g. C++ client’s view class account : public virtual CORBA:Object { public: void makeDeposit (…); CORBA::Boolean makeWithdrawal (…); char * dateLastModified (…); CORBA::Float balance (…); char * owner (…); void owner (const char * …); };
Mapping to a Programming Language (cont.) • e.g. Java client’s view public interface account extends org.omg.CORBA.Object { public float balance(); public void MakeDeposit(float f); public void Withdraw(float f); } • call these methods to make a call to a CORBA object
Static Invocation Interface (SII) • Most common way of using IDL • All methods are specified in advance • known to client and server via proxies • also known as surrogates • Primary advantages of SII • simplicity • typesafety • efficiency
Dynamic Invocation Interface (DII) • Less common programming API • Enables clients to invoke methods on objects that aren’t known until run-time • Clients “push” arguments onto a request stack and identify operations via ASCII name • Type-checking via meta-info in “Interface Repository” • More flexible than SII • More complicated, less typesafe, inefficient
OMG IDL Compiler • IDL compiler generates client stubs and server skeletons in specific programming language • Programmer “fills-in” implementation • See example later
CORBA Programming Steps • Define IDL interface • Compile IDL interface • generate Java code • Implement the interface • represents a CORBA object • Write a server • that will contain the CORBA object defined in the interface • Initializes the ORB • Write a client to use the CORBA objects • Compile the client and server applications • Execute the server (and naming service if necessary) • Execute the client application
Example: Remote Quoter Object A Quoter provides stock quotes to clients Client Node Server Node IDL interface to quoter Client code calls an operation on remote quoter objects REDH$ MSFT$ Client Process Other CORBA Object C++ object Server Process
IDL Interface for Quoter interface Stock { double price (); readonly attribute string symbol; readonly attribute string full_name; }; interface Stock_Factory { Stock get_stock (in string stock_symbol) raises (Invalid_Stock_Symbol); };
TAO IDL Compilation Quoter.idl QuoterS.h, QuoterS.i, QuoterS.cpp QuoterS_T.h QuoterS_T.i, QuoterS_T.cpp IDL complier %tao_idl Quoter.idl QuoterC.h, QuoterC.i, QuoterC.cpp Generated Classes and Headers Stock_i.cpp, Stock_Factory_i.cpp C++ Compiler client.cpp server.cpp Quoter server executable Quoter client execuable
Write a Client • Client initializes access to ORB • Client gets a reference to the desired object • Calls methods to access the object
Client - Manage ORB In client.cpp: int main (int argc, char* argv[]) { try { // First initialize the ORB, that will remove some arguments... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "" /* the ORB name, it can be anything! */); // the real code goes here! orb->destroy (); } catch (CORBA::Exception &ex) { std::cerr << "CORBA exception raised!" << std::endl; } return 0; } Client.cpp
Client - Get Quoter Object Ref Client.cpp In client.cpp: #include "QuoterC.h” CORBA::Object_var factory_object = orb->string_to_object(argv[1]); Quoter::Stock_Factory_var factory = Quoter::Stock_Factory::_narrow (factory_object.in ()); for (int i = 2; i != argc; ++i) { try { // Get the stock object Quoter::Stock_var stock = factory->get_stock (argv[i]);
Implementing Stock Interface In stock_i.cpp class Quoter_Stock_i : public POA_Quoter::Stock { public: Quoter_Stock_i (const char *symbol, const char*full_name, CORBA::Double price); private: std::string symbol_; std::string full_name_; CORBA::Double price_; }; Stock_i.cpp
Stock Operations and Attributes Stock_i.cpp In stock_i.cpp: class Quoter_Stock_i : public POA_Quoter::Stock { public: // some details omitted char *symbol () throw (CORBA::SystemException); char *full_name () throw (CORBA::SystemException); CORBA::Double price () throw (CORBA::SystemException); }; // In the .cpp file: char * Quoter_Stock_i::symbol () throw (CORBA::SystemException) { return CORBA::string_dup (this->symbol_.c_str ()); }
Stock Operations and Attributes Stock_i.cpp In stock_i.cpp: class Quoter_Stock_i : public POA_Quoter::Stock { public: // some details omitted char *symbol () throw (CORBA::SystemException); char *full_name () throw (CORBA::SystemException); CORBA::Double price () throw (CORBA::SystemException); }; // In the .cpp file: char * Quoter_Stock_i::symbol () throw (CORBA::SystemException) { return CORBA::string_dup (this->symbol_.c_str ()); } Memory management: must copy string into return since CORBA run-time will free space of return value
POAs • Servants - program language entities that implement CORBA objects. • Object adapters - link servants to CORBA Objects • Portable Object Adapters (POA) is standard object adapter (CORBA 2.2) • POAs: • create CORBA objects and references • dispatching requests to servants • like “main” in our socket assignment • Servers may have many POAs, must have at least Root POA
Implement Stock Factory Stock_ Factory_i.cpp In stock_factory_I.cpp: class Quoter_Stock_Factory_i : public POA_Quoter::Stock_Factory { public: Quoter_Stock_Factory (); Quoter::Stock_ptr get_stock (const char *symbol) throw (Quoter::Invalid_Stock_Symbol); private: Quoter_Stock_i rhat_; Quoter_Stock_i msft_; }; Two stocks in factory: RHAT, MSFT
Implement Get_Stock Method Stock_ Factory_i.cpp In stock_factory_i.cpp Quoter::Stock_ptr Quoter_Stock_Factory_i::get_stock (const char *symbol) throw (Quoter::Invalid_Stock_Symbol) { if (strcmp (symbol, "RHAT") == 0) { return this->rhat_._this(); } else if (strcmp (symbol, "MSFT") == 0) { return this->msft_._this (); } throw Quoter::Invalid_Stock_Symbol (); }
Implement Get_Stock Method Stock_ Factory_i.cpp _this() is a method that comes to all CORBA classes from inheritance. It creates the object using the POA and returns the object reference. In stock_factory_i.cpp Quoter::Stock_ptr Quoter_Stock_Factory_i::get_stock (const char *symbol) throw (Quoter::Invalid_Stock_Symbol) { if (strcmp (symbol, "RHAT") == 0) { return this->rhat_._this(); } else if (strcmp (symbol, "MSFT") == 0) { return this->msft_._this (); } throw Quoter::Invalid_Stock_Symbol (); }
Implement Server Server.cpp int main (int argc, char* argv[]) { try { // First initialize the ORB, that will remove some arguments… CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "" /* the ORB name, it can be anything! */); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // The application code goes here! // Destroy the POA, waiting until the destruction terminates poa->destroy (1, 1); orb->destroy (); } catch (CORBA::Exception &ex) { std::cerr << "CORBA exception raised!" << std::endl; } return 0; }
TAO IDL Compilation Quoter.idl QuoterS.h, QuoterS.i, QuoterS.cpp QuoterS_T.h QuoterS_T.i, QuoterS_T.cpp IDL complier %tao_idl Quoter.idl QuoterC.h, QuoterC.i, QuoterC.cpp Generated Classes and Headers Stock_i.cpp, Stock_Factory_i.cpp C++ Compiler client.cpp server.cpp Quoter server executable Quoter client execuable
Example: Remote Quoter Object A Quoter provides stock quotes to clients Client Node Server Node IDL interface to quoter Client code calls an operation on remote quoter objects REDH$ MSFT$ Client Process Other CORBA Object C++ object Server Process
IDL the C++ Mapping • General CORBA mapping of IDL constructs to C++ implementation • Basic types • Modules • Interfaces • Other IDL types
Example: Remote Quoter Object Server Node Client Node IDL interface to quoter REDH$ Client code gets obj ref from factory then calls an operation on remote quoter objects Factory MSFT$ C++ object Client Process Server Process