Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Advanced CORBA Programming wit C++ - M. Henning, S. Vinoski.pdf
Скачиваний:
65
Добавлен:
24.05.2014
Размер:
5 Mб
Скачать

IT-SC book: Advanced CORBA® Programming with C++

corresponding interface and implements the stub through which the client dispatches calls. This approach ensures type safety; the client cannot invoke an operation unless it holds a proxy of the correct type because only that proxy has the correct member function.

2.6 General CORBA Application Development

In the previous few sections, we have briefly explored all the parts of CORBA that you need to know about when developing applications. Here, we cover the general steps required to actually build CORBA-based systems. The intent is not to provide a false sense of simplicity but rather to help you see how all the portions of CORBA described in this chapter relate to one another in the context of application development.

To develop a C++ CORBA application consisting of two executables—one a client and one a server—you generally perform the following steps.

Determine your application's objects and define their interfaces in IDL.

As with the development of any object-oriented program, you must find your objects, define their interfaces, and define how they relate to one another. This process is usually a difficult and iterative one, and CORBA does not make this part of the development life cycle any easier for you.

In fact, designing a CORBA application, or any distributed object application for that matter, is often more difficult than designing a normal program because you must deal with issues related to distribution. Although CORBA and its language mappings hide much of the complexity and many of the low-level details associated with typical network programming, it does not magically take care of all the problems that distributed systems encounter, such as messaging latency, network partitions, and partial system failure. Basing your application on an ORB certainly helps in this regard, but you must still take latency and distributed failure modes into account if you want to write highquality distributed applications. We discuss some of these design issues in Chapter 22. Compile your IDL definitions into C++ stubs and skeletons.

ORB implementations normally supply IDL compilers that follow language mapping rules to compile your IDL into client stubs and server skeletons. For C++, IDL compilers typically emit C++ header files that contain declarations for proxy classes, server skeletons, and other supporting types. They also generate C++ implementation files that implement the classes and types declared in the header files.

By translating your IDL definitions into C++, you generate a code base that allows you to write clients and servants that respectively access and implement CORBA objects supporting your IDL interfaces.

Declare and implement C++ servant classes that can incarnate your CORBA objects.

44

IT-SC book: Advanced CORBA® Programming with C++

Each of your CORBA objects must be incarnated by an instance of a C++ servant class before the ORB can dispatch requests to it. You must define your servant classes and implement their member functions (which represent their IDL methods) to perform the services that you want your CORBA objects to provide to your clients.

Write a server main program.

As with all C++ programs, the main function provides the entry and exit points for a C++ CORBA application. For your server, your main must initialize the ORB and the POA, create some servants, arrange for the servants to incarnate your CORBA objects, and finally, start listening for requests.

Compile and link your server implementation files with the generated stubs and skeletons to create your server executable.

For a C++ CORBA server, you provide the method implementations. The generated stubs and skeletons provide the IDL type implementations and the request dispatching code to translate incoming CORBA requests into C++ function calls on your servants.

Write, compile, and link your client code together with the generated stubs.

Finally, you implement your clients to first obtain object references for your CORBA objects. To have services performed on their behalf, your clients then invoke operations on your CORBA objects. Your client code invokes requests and receives replies as if making normal C++ function calls. The generated stubs translate those function calls into CORBA request invocations on the objects in your server.

Naturally, these steps vary somewhat depending on the nature of the application. For example, sometimes the server already exists, and you need only write a client. In that case, you would perform only those steps related to developing clients.

If this CORBA application development process is not clear to you, do not worry. We have kept our explanation of these steps at a high level; we want only to give you an overview of what you must do to create C++ CORBA applications. Subsequent chapters cover many more details related to the development of real-world applications, so do not be disheartened by the lack of depth in the coverage provided here.

2.7 Summary

The problems associated with distributed heterogeneous computing are with us for the foreseeable future. Computer networks will continue to be heterogeneous for some time to come because of continued advances in computing hardware, networking, and operating systems. This heterogeneity makes the development, deployment, and maintenance of networked applications difficult because of the overwhelming number of low-level details that must be considered and addressed.

45

IT-SC book: Advanced CORBA® Programming with C++

CORBA provides the abstractions and services you need to develop portable distributed applications without worrying about low-level details. Its support for multiple requestresponse models, transparent object location and activation, and programming language and operating system independence provides a solid basis for both the integration of legacy systems and the development of new applications.

Application developers define the interfaces of their CORBA objects in the OMG IDL, a C++-like declarative language. You use it to define types such as structures, sequences, and arrays to be passed to operations supported by objects. Using object-oriented development techniques, you group related operations in interfaces in much the same way that you define related C++ member functions in C++ classes.

To implement CORBA objects in C++, you create C++ object instances called servants and register them with the POA. The ORB and POA cooperate to dispatch all requests invoked on a target object to the servant incarnating that object.

Clients invoke requests via object references, which are opaque entities that contain communication information used by ORBs to direct requests to their target objects. IORs have a standardized format that allow independently developed ORBs to interoperate.

Because the first step in implementing CORBA objects is to define their interfaces, we describe IDL in detail in Chapter 4. Before that, however, we continue to ease you into the development of CORBA applications with C++ in Chapter 3 by showing you how to write a simple client and server.

46