Object-Oriented Network Programming Writing CORBA Applications Dr. Douglas C. Schmidt [email protected] Introduction General

Object-Oriented Network Programming Writing CORBA Applications Dr. Douglas C. Schmidt Schmidt@Cs.Wustl.Edu Introduction General

Intro duction CORBA addresses two challenges of devel- oping distributed systems: Object-Oriented Network 1. Making distributed application development no more Programming dicult than developing centralized programs { Easier said than done due to: . Partial failures Writing CORBA Applications . Impact of latency . Load balancing Dr. Douglas C. Schmidt . Event ordering [email protected] u 2. Providing an infrastructure to integrate application comp onents into a distributed system { i.e., CORBA is an \enabling technology" 1 2 General ORB structure CORBA Interface De nition op(args) IDL OBJECT Language CLIENT IMPL IDL OMG IDL is an object-oriented interface SKELETON de nition language DYNAMIC Used to sp ecify interfaces containing metho ds and IDL ORB OBJECT { INVOCATION ADAPTER STUBS INTERFACE attributes INTERRFACE OBJECT OMG IDL supp ort interface inheritance b oth sin- REQUEST BROKER { gle and multiple inheritance OMG IDL is designed to map onto multiple programming languages Note that an ORB is a logical set of ser- { e.g., C, C++, Smalltalk, COBOL, Mo dula 3, DCE, etc. vices, rather than just a particular pro cess or library 4 3 OMG IDL Compiler OMG IDL Features A OMG IDL compiler generates client stubs OMG IDL is a sup erset of a subset of C++ and server skeletons { Note, it is not a complete programming language, it only de nes interfaces Stubs and skeletons automate the following activities in conjunction with the ORB: { Client proxy factories OMG IDL supp orts the following features: { Parameter marshalling/demarshalling * modules * interfaces * metho ds { Implementation class interface generation * attributes * inheritance { Object registration and activation *arrays * sequence { Object lo cation and binding * struct, enum, union, typedef * consts * exceptions { Per-object/p er-pro cess lters 5 6 A Sample CORBA Application OMG IDL vs. C++ Client DATABASE App. 1: log() SERVER LOGGER 2: send Di erences from C++ Logger request Proxy Logger Object * No data memb ers * No p ointers * No constructors or destructors * No overloaded metho ds int data typ e *No SERVER rameter passing mo des * Contains pa CLIENT NETWORK * Unions require a tag yp e * String t PRINTER * Sequence typ e * Di erent exception interface * No templates * No control constructs Distributed logging facility 7 8 Server-side OMG IDL Sp eci cation De nes the interface of the Logger Behavior of the Distributed // IDL specific at io n Logging Facility interface Logger { // Types of logging message s enum Log_Prio ri ty { LOG_DEBUG , // Debuggi ng message s The logging server collects, formats, and LOG_WARNI NG , // Warning message s outputs logging records forwarded from ap- LOG_ERROR , // Errors LOG_EMERG // A panic conditi on , normally broadcas t plications residing throughout a network or }; internetwork exception Disconn ec te d {}; struct Log_Reco rd { Log_Prior it y type; // Type of logging record. long host_add r; // IP address of the sender. An application interacts with the server log- long time; // Time logging record generate d. long pid; // Process ID of app. generati ng the record. ger via a CORBA interface sequence< ch ar > msg_data ; // Logging record data. }; // Transmit a Log_Rec or d to the logging server void log in Log_Reco rd log_rec raises Disconn ec te d ; attribute boolean verbose ; // Use verbose formatti ng }; 10 9 Creating Server-side OMG IDL Mapping Rules Implementation s The CORBA sp eci cation de nes mappings from CORBA IDL to various programming Running the Logger interface de nition through languages the IDL compiler generates a client stub and a server skeleton { e.g., C++, C, Smalltalk { The client stub acts as a proxy and handles object binding and parameter marshalling Mapping OMG IDL to C++ { The server skeleton handles object registration, activation, and parameter demarshalling { Each interface is mapp ed to a nested C++ class { Each op eration is mapp ed to a C++ metho d with appropriate parameters CORBA de nes two techniques for gener- ating server skeletons: { Each read/write attribute is mapp ed to a pair of get/set metho ds 1. Inheritance-based implementations e.g., Orbix BOAImpl . A read-only attribute is only mapp ed to a single 2. Object comp osition-based implemenations e.g., get metho d Orbix TIE 12 11 Inheritance-bas ed Object Comp osition -b ased Implementation s Implementation s In Orbix, inheritance-based implementations are supp orted by the BOAImpl approach: In Orbix, object comp osition-based imple- mentations are supp orted by the TIE ap- { The drawback with this approach is that the imple- mentation must inherit from the generated skele- proach: ton // Note, there is no use of inheritance and class Logger_i // methods need not be virtual! // Note the use of inheritance from automatically class Logger_i // generated class LoggerBOAImpl { : public virtual LoggerBOAImpl public: { // Start with verbose mode enabled. public: Logger_i bool verb = true: verbose_ verb {} Logger_i bool verb: verbose_ verb {} void log const Log_Record &log_rec, virtual void log const Log_Record &log_rec, CORBA::Environment &; CORBA::Environment &; bool verbose void, virtual bool verbose void, CORBA::Environment &; CORBA::Environment &; void verbose bool enable, virtual void verbose bool enable, CORBA::Environment &; CORBA::Environment &; private: private: bool verbose_; bool verbose_; }; }; 13 14 Writing the Server-side Metho d De nitions Object Comp osition -b ased Implementati on s cont'd Using either the BOAImpl or the TIE ap- proach, a develop er then writes C++ de - Orbix provides a set of macros that tie the nitions for the metho ds in class Logger i: Logger interface together with the Logger i void Logger_i::log const Log_Record &log_rec, implementation CORBA::Environment & { // Formatting and outputting the contents DEF_TIE Logger, Logger_i; // of log_rec omitted... Logger_i *log = new Logger_i; } Logger *logger = new TIE Logger, Logger_i log; bool Logger_i::verbose void, CORBA::Environment &; { This scheme works by placing a p ointer to return this->verbose_; the implementation object within the TIE } class and then delegating metho d calls to void Logger_i::verbose bool enabled, the implementation object CORBA::Environment &; { this->verbose_ = enabled; } 16 15 Exception Handling Writing Main Server Program The preceeding example illustrated how CORBA The main program for the logging server uses C++ exception handling to propagate errors. lo oks like: { However, many C++ compilers don't supp ort ex- // Shared activation ceptions yet int main void { Therefore, CORBA implementations provide an { alternative mechanism for handling errors // BOAImpl instance. Logger_i logger ; // Shared activat io n int main void { try { // Start with verbose mode enabled // Will block forever waiting for incoming Logger_ i logger true; // invocations and dispatching method callbacks TRY { CORBA::Orbix.impl_is_ready "Logger"; // Will block forever waiting for incoming } catch ... { // invocati on s and dispatc hi ng method callback s cerr << "server failed\n"; CORBA:: Or bi x. im pl _is _r ea dy "logge r" , IT_X; return 1; } CATCHAN Y { cerr << "server failed due to " << IT_X << endl; } } ENDTRY; cout << "server terminating\n"; cout << "server terminat in g\ n" ; return 0; return 0; } } 18 17 Object Activation Generated Client-si de Stubs If the service isn't running when a client in- The OMG IDL compiler automatically gen- vokes a metho d on an object it manages, erates a client-side stub used to de ne \proxy the ORB will automatically start the service objects," e.g., typedef Logger *LoggerRef; // Generated by Orbix Services must be registered with the ORB, e.g., class Logger // Base class for all IDL interfaces... putit Logger /usr/svcs/Logger/logger.exe : public virtual CORBA::Object { public: Services may b e installed on any machine static Logger *_bind /* Many binding formats */; virtual void log const Log_Record &log_rec, CORBA::Environment &; virtual void verbose bool enabled, CORBA::Environment &; Clients may bind to a service by using a virtual bool verbose void, CORBA::Environment &; lo cation broker or by explicitly naming the }; server 20 19 Client-sid e Example A client programmer writes the following: Binding a Client to a Target int Object main void { LoggerRef logger; Steps for binding a client to a target object Log_Record log_rec; 1. A CORBA client requestor obtains an \object logger = Logger::_bind ; // Bind to any logger. reference" from a server // Initialize the log_record log_rec.type = Logger::LOG_DEBUG; { May use a name service or lo cator service log_rec.time = ::time 0; log_rec.host_addr = // ... 2. This object reference serves as a lo cal proxy for // ... the remote target object try { { Object references may b e passed as parameters logger->verbose false; // Disable verbose logging. to other remote objects logger->log log_rec; // Xmit logging record. } catch Logger::Disconnected { 3. The client may then invoke metho ds on its proxy cerr << "logger disconnected" << endl; } catch ... { /* ... */ } return 0; } 21 22 Summary CORBA helps to reduce the complexity of developing distributed applications { However, there are many hard issues remaining:: : Other OMG do cuments e.g., COSS sp ec- ify higher level { e.g., transactions, events, naming, security, etc. 23.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us