CORBA Programming Using ACE/TAO Ken Waller EEL 6897 - Software Development for Real Time Engineering Systems Fall 2007 Agenda What Is CORBA? CORBA Basics Overview of ACE/TAO Example 1: Simple Client-Server CORBA Services Clients, Servers, and Servants ORBs and POAs IDL and the Role of IDL Compilers IORs Tying it all together Naming Service Trading Service Event Service Example 2: Using the Naming Service Multi-Threaded Issues Using CORBA Example 3: A Multi-Threaded Server What Is CORBA? Common Object Request Broker Architecture Common Architecture Object Request Broker – ORB Specification from the OMG http://www.omg.org/technology/document s/corba_spec_catalog.htm Must be implemented before usable What Is CORBA? More specifically: “(CORBA) is a standard defined by the Object Management Group (OMG) that enables software components written in multiple computer languages and running on multiple computers to work together ” (1) Allows for Object Interoperability, regardless of: Operating Systems Programming Language Takes care of Marshalling and Unmarshalling of Data A method to perform Distributed Computing What Is CORBA? CORBA Program A Program B • Running on a Windows PC • Running on a Linux Machine • Written in Java • Written in C++ What is CORBA? CORBA is being used in many industries Defense, Financial, Medical CORBA can be used to: Harness the power of several machines to solve a problem Several CPU’s Simulations Communicate between real Tactical Systems Perform true component based development What is CORBA? Conceptually simple: Simply sending messages and data between objects running on different machines “Devil is in the Details” (3) Many new concepts and terms to learn Not unlike objects communicating ORB, POA, IOR, etc. “Alphabet Soup” True experts are rare and highly sought after Abstraction above Sockets CORBA Basics: Clients, Servers, and Servants CORBA Clients An Application (program) Request services from Servant object Can exist on a different computer from Servant Invoke a method call Can also exist on same computer, or even within the same program, as the Servant Implemented by Software Developer CORBA Basics: Clients, Servers, and Servants CORBA Servers An Application (program) Performs setup needed to get Servants configured properly ORB’s, POA’s Instantiates and starts Servants object(s) Once configuration done and Servant(s) running, Clients can begin to send messages Implemented by Software Developer CORBA Basics: Clients, Servers, and Servants Servants Objects Implement interfaces Respond to Client requests Exists within the same program as the Server that created and started it Implemented by Software Developer ORB’s and POA’s ORB: Object Request Broker The “ORB” in “CORBA” Enables communication Implemented by ORB Vendor An organization that implements the CORBA Specification (a company, a University, etc.) Can be viewed as an API/Framework At the heart of CORBA Set of classes and method Used by Clients and Servers to properly setup communication Client and Server ORB’s communicate over a network Glue between Client and Server applications ORB’s and POA’s POA: Portable Object Adapter A central CORBA goal: Programs using different ORB’s (provided by different ORB Vendors) can still communicate In the early days of CORBA, this was not possible The POA was adopted as the solution Can be viewed as an API/Framework Set of classes and method Sits between ORB’s and Servants A clear shortcoming Glue between Servants and ORBs Job is to: Receive messages from ORB’s Activate the appropriate Servant Deliver the message to the Servant CORBA Basics: IDL IDL: The Interface Definition Language Keyword: Definition No “executable” code (cannot implement anything) Very similar to C++ Header Files Language independent from Target Language A “contract” between Clients and Servers Allows Client and Server applications to be written in different (several) languages Both MUST have the exact same IDL Specifies messages and data that can be sent by Clients and received by Servants Written by Software Developer CORBA Basics: IDL Used to define interfaces (i.e. Servants) Classes and methods that provide services IDL Provides… Primitive Data Types (int, float, boolean, char, string) Ability to compose primitives into more complex data structures Enumerations, Unions, Arrays, etc. Object-Oriented Inheritance CORBA Basics: IDL IDL Compilers Converts IDL files to target language files Done via Language Mappings Target language files contain all the implementation code that facilitates CORBA-based communication Useful to understand your Language Mapping scheme More or less “hides” the details from you Creates client “stubs” and Server “skeletons” Provided by ORB Vendor CORBA Basics: IDL IDL Compiler IDL File Generates Client Program Association Client Programs used the classes in the Client Stub files to send messages to the Servant objects Generates Client Stub Files Server Skeleton Files Generated Files are in Target Language: Generated Files are in Target Language: • C++ • C++ • Java • Java • etc. • etc. Inheritance Servant Object Servant Objects inherit from classes in the Server Skeleton files to receive messages from the Client programs CORBA Basics: IDL Can also generate empty Servant class files IDL Compiler converts to C++ (in this case) CORBA Basics: IOR’s IOR: Interoperable Object Reference Can be thought of as a “Distributed Pointer” Unique to each Servant Used by ORB’s and POA’s to locate Servants Opaque to Client and Server applications For Clients, used to find Servants across networks For Servers, used to find proper Servant running within the application Only meaningful to ORB’s and POA’s Contains information about IP Address, Port Numbers, networking protocols used, etc. The difficult part is obtaining them This is the purpose/reasoning behind developing and using CORBA Services CORBA Basics: IOR’s Can be viewed in “stringified” format, but… Still not very meaningful CORBA Basics: IOR’s Standardized, to some degree: … Standardized by the OMG: • Used by Client side ORB’s to locate Server side (destination) ORB’s • Contains information needed to make physical connection … NOT Standardized by the OMG; proprietary to ORB Vendors • Used by Server side ORB’s and POA’s to locate destination Servants CORBA Basics: Tying it All Together In order to use CORBA: Obtain a CORBA implementation ACE/TAO is used in this presentation (free, open source) ORBIX (commercial) is most widely used (better support) Consider what platforms and languages vendor supports Learn how to use the CORBA API Can read the specification Recommended: Find a good CORBA book Massive Perhaps “too technical” More clear and concise See (3) Must also rely on documentation from the CORBA implementation provider The specs standardize lots of things, but not everything Some aspects left to the CORBA implementers CORBA Basics: Tying it All Together Recommended development strategy: Develop IDL and system architecture (i.e. High-Level design) Sequence Diagrams and UML can be useful during this phase Decide IOR passing strategy (i.e. CORBA Services) Design and Develop Server and Client programs CORBA Basics: Tying it All Together In general, a Server program must take the following steps: In general, a Client program must take the following steps: Configure the ORB (different from Server ORB) Obtain a Servant’s IOR from a CORBA Service Use the IOR to call a method on the Servant object These directions are oversimplification Configure the ORB Configure the POA Create and Configure the Servant object Register the Servant’s IOR with a CORBA Service Start the Servant Must learn how to use the CORBA API properly This is just a High-Level view In general, the server program must be run before the client program CORBA Basics: Tying it All Together Server ORB POA Servant CORBA Service Configure ORB Configure POA Create/Configure Servant Object Client Register Servant IOR Start Servant ORB Configure ORB Obtain IOR IOR Call Servant Method Response *optional* CORBA Basics: Tying it All Together Logical Flow Client Program IOR (Servant Ref) Server Program Message(Data) Servant Actual Flow Client Program IOR (Servant Ref) Once ORB’s and POA’s set up and configured properly, transparency is possible • ORB’s communicate over network • POA’s activate servants and deliver messages Server Program Servant POA ORB ORB Overview of ACE/TAO ACE: Adaptive Communications Environment Object-Oriented Framework/API Implements many concurrent programming design patterns Can be used to build more complex communications-based packages For example, an ORB Freely available from (2) Overview of ACE/TAO TAO: The ACE ORB Built on top of ACE A CORBA implementation Includes many (if not all) CORBA features specified by the OMG Not just an ORB Provides POA’s, CORBA Services, etc. Object-Oriented Framework/API Freely available from (2) Example 1: Simply Client/Server CORBA Services Previous example: Server started the Servant Servant wrote its IOR out to a file in a stringified format Client obtained IOR by reading the IOR in from the file This is not true distribution The CORBA Specification includes extensions to help facilitate obtaining IOR’s in a more distributed fashion CORBA Services: The Naming Service The CORBA Naming Service is similar to the White Pages (phone book) Servants place their “names,” along with their IOR’s, into the Naming Service Later, Clients obtain IOR’s from the Naming Service by passing the name of the Servant object to it The Naming Service stores these as pairs The Naming Service returns the IOR Clients may then use to make requests CORBA Services: The Trading Service The CORBA Naming Service is similar to the Yellow Pages (phone book) Servants place a description of the services they can provide (i.e. their “Trades”), along with their IOR’s, into the Trading Services Clients obtain IOR’s from the Trading Service by passing the type(s) of Services they require The Trading Service stores these The Trading Service returns an IOR Clients may then use to make requests Example 2: Using the Naming Service Multi-Threaded Issues Using CORBA Server performance can be improved by using multiple threads GUI Thread Listening Thread Processing Thread Can also use multiple ORBs and POAs to improve performance Requires a multi-threaded solution Example 3: A Multi-Threaded Server Conclusions Advantages: Object-Oriented distributed communication Easy to define messages and data contents using IDL Once setup/configuration of ORB’s, POA’s, Servants, IOR’s complete, communication is fairly straightforward Relieves programmers from having to write Socket software Disadvantages: Can be difficult to learn Even harder to master Scalability issues could cause a mind-boggling amount of ORB’s, POA, threads, etc. to be used Acquiring IOR’s can be difficult References (1) http://en.wikipedia.org/wiki/CORBA (2) http://download.dre.vanderbilt.edu/ (3) “Advanced CORBA Programming with C++” by Henning and Vinoski Questions?