2.4 Where an Object Gets Its Operations
As explained in the preceding section, the data that makes up a CORBA object may exist in a record in a database. Alternatively, the data could be established for a CORBA object only when the object is active in memory. This section explains how to write operations for a CORBA object and how to make the operations a part of the object.
The operations you write for a given CORBA object are also known as the object’s implementation. You can think of the implementation as the code that provides the behavior of the object. When you create an Oracle Tuxedo CORBA client/server application, one of the steps you take is to compile the application’s OMG IDL file. The OMG IDL file contains statements that describe the application’s interfaces and the operations that can be performed on those interfaces.
If you are implementing your server application in C++, one of the several files optionally produced by the IDL compiler is a template for the implementation file . The template for the implementation file contains default constructors and method signatures for your application’s objects. The implementation file is where you write the code that implements an object; that is, this file contains the business logic of the operations for a given interface.
The Oracle Tuxedo system implements an interface as a CORBA object. The IDL compiler also produces other files, which get built into the Oracle Tuxedo CORBA client and server application, that make sure that the implementation you write for a given object gets properly connected to the correct object data during run time.
This is where the notion of a servant comes in. A servant is an instance of the object class; that is, a servant is an instance of the method code you wrote for each operation in the implementation file. When the Oracle Tuxedo CORBA client and server applications are running, and a client request arrives in the server application for an object that is not active -- that is, the object is not in memory -- the following events occur:
- If no servant is currently available for the needed object, the Oracle Tuxedo system invokes the
Server::create_servant
method on the Server object.The
Server::create_servant
method is entirely user-written. The code that you write for theServer::create_servant
method instantiates the servant needed for the request. Your code can use the interface name, which is passed as a parameter to theServer::create_servant
method, to determine the type of servant that the Oracle Tuxedo domain creates.The servant that the Oracle Tuxedo domain creates is a specific servant object instance (it is not a CORBA object), and this servant contains an executable version of the operations you wrote earlier that implement the CORBA object needed for the request.
- The Oracle Tuxedo domain passes control to the servant, and optionally invokes the servant’s
activate_object
method, if you have implemented it. Invoking theactivate_object
method gives life to the CORBA object, as follows:- You write the code for the
activate_object
method. The parameter to theactivate_object
method is the string value of the object ID for the object to be activated. You may use the object ID as a key to how to initialize the object. - You initialize the CORBA object’s data, which may involve reading state data from durable storage, such as from a record in a database.
- The servant’s operations become bound to the data, and the combination of those operations and the data establish the activated CORBA object.
After steps a, b, and c are completed, the CORBA object is said to be activated.
Implementing the
activate_object
method on an object is optional. For more information about when you want to implement this operation on an object, see Creating CORBA Server Applications in the Oracle Tuxedo online documentation. - You write the code for the
Note:
A servant is not a CORBA object. In fact, the servant is represented as a language object. The server performs operations on an object via its servant.For more information about creating object implementations, see Creating CORBA Server Applications in the Oracle Tuxedo online documentation.
Parent topic: CORBA Objects