1 / 158

CORBA Outline

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

milos
Télécharger la présentation

CORBA Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Introduction to CORBA • CORBA Goals and Philosophy • Client/Server architecture • Intro to CORBA components • IDL • language constructs • examples

  3. 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

  4. CORBA Key Concepts • Transparent Distribution • Objects • Client / Server model • Portable • across platforms, languages, networks • Standard

  5. Distributed Application Architectures • Multiple computers on a network • Services can reside on any node • file service • name service • print service • CORBA transparently distributes applications

  6. 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

  7. Client Server Model • Client makes method call of remote object • Call is forwarded by ORB to server • Object implementation receives the call and responds

  8. 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

  9. 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)

  10. Lifecycle Naming Event Persistence Relationship Externalization Transaction Concurrency Security Time Licensing Query Trader Scheduling CORBA Services

  11. 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

  12. 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”

  13. modules interfaces operations attributes inheritance basic types arrays sequence struct enum typedef const exceptions OMG IDL Features

  14. 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++

  15. 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

  16. Interfaces • The basic unit is the interface • defining the interface to a type of object interface account { // operation and attribute definitions };

  17. 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);

  18. 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

  19. 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); . . . }; };

  20. 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

  21. 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

  22. 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 (…); };

  23. 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(); };

  24. 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

  25. 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; };

  26. 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;

  27. 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 * …); };

  28. 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

  29. 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

  30. 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

  31. OMG IDL Compiler • IDL compiler generates client stubs and server skeletons in specific programming language • Programmer “fills-in” implementation • See example later

  32. 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

  33. 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

  34. 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); };

  35. 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

  36. Write a Client • Client initializes access to ORB • Client gets a reference to the desired object • Calls methods to access the object

  37. 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

  38. 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]);

  39. 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

  40. 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 ()); }

  41. 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

  42. 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

  43. 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

  44. 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 (); }

  45. 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 (); }

  46. 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; }

  47. 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

  48. 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

  49. IDL the C++ Mapping • General CORBA mapping of IDL constructs to C++ implementation • Basic types • Modules • Interfaces • Other IDL types

  50. 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

More Related