BEA Logo BEA WebLogic Enterprise Release 5.0

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   WLE Doc Home   |   CORBA Programming & Related Topics   |   Previous   |   Next   |   Contents   |   Index

CORBA Objects

Before any discussion of CORBA programming can be meaningful, it is important to have a clear understanding of what a CORBA object is and the object terminology used throughout the WLE information set.

This chapter discusses the following topics:

There are a number of variations on the definition of an object, depending on what architecture or programming language is involved. For example, the concept of a C++ object is significantly different from the concept of a CORBA object. Also, the notion of a COM object is quite different from the notion of a CORBA object.

Most importantly, the notion of CORBA object in this chapter is consistent with the definition presented by the Object Management Group (OMG). The OMG has a number of specifications and other documents that go into complete details on objects.

Definition of a CORBA Object

A CORBA object is a virtual entity in the sense that it does not exist on its own, but rather is brought to life when, using the reference to that CORBA object, the client application requests an operation on that object. The reference to the CORBA object is called an object reference. The object reference is the only means by which a CORBA object can be addressed and manipulated in an WLE system. For more information about object references, see Creating CORBA C++ Server Applications or Creating CORBA Java Server Applications in the WebLogic Enterprise online documentation.

When the client or server application issues a request on an object via an object reference, the WLE server application instantiates the object specified by the object reference, if the object is not already active in memory. (Note that a request always maps to a specific operation invocation on an object.)

Instantiating an object typically involves the server application initializing the object's state, which may include having the object's state read from durable storage, such as a database.

The object contains all the data necessary to do the following:

How a CORBA Object Comes into Being

The data that makes up a CORBA object may have its origin as a record in a database. The record in the database is the persistent, or durable, state of the object. This record becomes accessible via a CORBA object in an WLE domain when the following sequence has occurred:

  1. The server application's factory creates a reference for the object. The object reference includes information about how to locate the record in the database.

  2. Using the object reference created by the factory, the client application issues a request on the object.

  3. The object is instantiated. If the server application is implemented in C++, the object is instantiated by the TP Framework by invoking the Server::create_servant method, which exists in the Server object.

    If the server application is implemented in Java, the object is instantiated dynamically by the WLE system. (The create_servant method is not available to Server objects written in Java.)

  4. The WLE domain invokes the activate_object operation on the object, which causes the record containing state to be read into memory.

Whereas a language object exists only within the boundaries of the execution of the application, a CORBA object may exist across processes and machine systems. The WLE system provides the mechanism for constructing an object and for making that object accessible to the application.

The WLE server application programmer is responsible for writing the code that initializes an object's state and the code that handles that object's state after the object is no longer active in the application. If the object has data in durable storage, this code includes the operations that read from and write to durable storage. For more information about developing server applications, see Creating CORBA C++ Server Applications or Creating CORBA Java Server Applications.

Components of a CORBA Object

CORBA objects typically have the following components, shown in the figure that follows:

The sections that follow describe each of these object components in detail.

The Object ID

The object ID (OID) associates an object with its state, such as a database record, and identifies the instance of the object. When the factory creates an object reference, the factory assigns an OID that may be based on parameters that are passed to the factory in the request for the object reference.

Note: The server application programmer must create the factories used in the WLE client/server application. The programmer is responsible for writing the code that assigns OIDs. Factories, and examples of creating them, are discussed in Creating CORBA C++ Server Applications or Creating CORBA Java Server Applications.

The WLE system can determine how to instantiate the object by using the following information:

The Object Interface

The object's interface, described in the application's OMG IDL file, identifies the set of data and operations that can be performed on an object. For example, the interface for a university teller object would identify:

One distinguishing characteristic of a CORBA object is the run-time separation of the interface definition from its data and operations. In a CORBA system, a CORBA object's interface definition may exist in a component called the Interface Repository. The data and operations are specified by the interface definition, but the data and operations exist in the server application process when the object is activated.

The Object's Data

The object's data includes all of the information that is specific to an object class or an object instance. For example, within the context of a university application, a typical object might be a teller. The data of the teller could be:

You can encapsulate the object's data in an efficient way, such as by combining the object's data in a structure to which you can get access by means of an attribute. Attributes are a conventional way to differentiate the object's data from its operations.

The Object's Operations

The object's operations are the set of routines that can perform work using the object's data. For example, some of the operations that perform functions using teller object might include:

In a CORBA system, the body of code you write for an object's operations is sometimes called the object implementation, which is explained in the next section.

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 WLE 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 m3idltojava command, which you use to implement a server application in Java, does not produce a template implementation file.)

The WLE system implements an interface as a CORBA object. The IDL compiler also produces other files, which get built into the WLE 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 WLE 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:

  1. If no servant is currently available for the needed object, what happens next depends on the language in which the server application is written:

  2. The WLE domain passes control to the servant, and optionally invokes the servant's activate_object method, if you have implemented it. Invoking the activate_object method gives life to the CORBA object, as follows:

    1. You write the code for the activate_object method. The parameter to the activate_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.

    2. You initialize the CORBA object's data, which may involve reading state data from durable storage, such as from a record in a database.

    3. 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 C++ Server Applications or Creating CORBA Java Server Applications.

      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 C++ Server Applications or Creating CORBA Java Server Applications.

How Object Invocation Works

Since CORBA objects are meant to function in a distributed environment, OMG has defined an architecture for how object invocation works. A CORBA object can be invoked in one of two ways:

Creating CORBA Client Applications describes how dynamic invocation works. This section describes stub-style invocation, which is simpler to use than dynamic invocation.

When you compile your application's OMG IDL file, one file that the compiler generates is a source file called the client stub. The client stub maps OMG IDL operation definitions for an object type to the operations in the server application that the M3 system invokes to satisfy a request. The client stub contains code generated during the client application build process that is used in sending the request to the server application. Programmers should never modify the client stub code.

Another file produced by the IDL compiler is the skeleton, which is also a C++ or Java source file. The skeleton contains code used for operation invocations on each interface specified in the OMG IDL file. The skeleton is a map that points to the appropriate code in the CORBA object implementation that can satisfy the client request. The skeleton is connected to both the object implementation and the WLE Object Request Broker.

The following figure shows the client application, the client stub, the skeleton, and the CORBA object implementation:

When a client application sends a request, the request is implemented as an operation on the client stub. When the client stub receives the request, the client stub sends the request to the ORB, which then sends the request through the WLE system to the skeleton. The ORB interoperates with the TP Framework and the Portable Object Adapter (POA) to locate the correct skeleton and object implementation.

For more information about generating client stubs and skeletons, see Creating CORBA Client Applications and Creating CORBA C++ Server Applications or Creating CORBA Java Server Applications.