If there are potentially thousands of persistent objects, you may want your application to conserve resources and not register all of them at server startup. Servers may defer creating objects until a client makes a request to use one.
The server's runtime maintains a table of all its objects. The server gets a request from a client on an object that is uniquely identified by an object UUID (from the binding handle), and the object table maps object UUIDs to each object's address in the server's address space. The server's object table is a C++ class containing the following information:
· Object UUIDs
· Interface UUIDs
· Object addresses
If the runtime cannot find the UUID of the object requested, an exception is raised on the server to propagate to the client unless a user-defined object lookup function exists. If the lookup function does exist, the runtime automatically executes it. The lookup function is created by the server developer to create the object and, if required, register it as a named object. If the lookup function cannot create an object for the specified UUID, it should return a 0, which causes the runtime to raise an exception (rpc_x_object_not_found).
After the named object is registered, the object table contains the new object UUID, so subsequent attempts to use the object do not invoke the lookup function again. Alternatively, the lookup function can maintain its own object map. By not registering with the runtime, subsequent operations will invoke the lookup function. This allows the developer to use the lookup function to maintain complete control over the existence of the object.
A lookup function name is specified using an ACF when the interface is compiled. The following example is a portion of an ACF that specifies a lookup function:
[
cxx_lookup(object_lookup)
]
interface Matrix
{
[sstub] include "matrix_mgr", "lookup";
.
.
.
cxx_lookup(object_lookup)
To specify a lookup function use the cxx_lookup attribute with the name of the lookup function (in this case, object_lookup) as an
argument. A lookup function is interface-wide, so it is defined in the ACF header.
[sstub] include
Use the include statement with the sstub attribute to make the IDL compiler include implementation-specific header files in the server stub. The
matrix_mgr.h header file contains the manager class and the lookup.h file contains a declaration of the lookup function you create.
The following example shows the declaration of the object_lookup function in the lookup.h header file:
//FILE NAME: lookup.h
//This file declares the lookup function used
// for server management of object lookup.
Matrix *object_lookup(uuid_t *);
A lookup function has the following signature requirements:
· The lookup function returns a pointer to the interface class (Matrix *).
· The function name matches the one declared in the ACF (object_lookup).
· There is one input parameter pointer of type uuid_t.
An implementation of the object_lookup( ) function is shown in the following topic.