Previous Table of Contents Next


11.6.4 Explicit Activation with User-assigned Object Ids


   An object may be explicitly activated by a server using a user-assigned identity. This may be done for several reasons. For example, a programmer may know that certain objects are commonly used, or act as initial points of contact through which clients access other objects (for example, factories). The server could be implemented to create and explicitly activate these objects during initialization, avoiding the need for a servant manager.

   If an implementation has a reasonably small number of servants, the server may be designed to keep them all active continuously (as long as the server is executing). If this is the case, the implementation need not provide a servant manager. When the server initializes, it could create all available servants, loading their state and identities from some persistent store. The POA supports an explicit activation operation, activate_object_with_id, that associates a servant with an Object Id. This operation would be used to activate all of the existing objects managed by the server during server initialization. Assuming the POA has the USE_SERVANT_MANAGER policy and no servant manager is associated with a POA, any request received by the POA for an Object Id value not present in the Active Object Map will result in an OBJ_ADAPTER exception.

   In simple cases of well-known, long-lived objects, it may be sufficient to activate them with well-known Object Id values during server initialization, before activating the POA. This approach ensures that the objects are always available when the POA is active, and doesn’t require writing a servant manager. It has severe practical limitations for a large number of objects, though.

   This example illustrates the explicit activation of an object using a user-chosen Object Id. This example presumes a POA that has the USER_ID, USE_SERVANT_MANAGER, and RETAIN policies.

   The code is like the previous example, but replace the last portion of the example shown above with the following code:

   // C++MyFooServant* afoo = new MyFooServant(poa, 27);PortableServer::ObjectId_var oid =

   PortableServer::string_to_ObjectId(“myLittleFoo?);

   poa->activate_object_with_id(oid.in(), afoo);

   Foo_var foo = afoo->_this();