Previous Table of Contents Next


11.6.3 Explicit Activation with POA-assigned Object Ids


   By specifying the SYSTEM_ID policy on a POA, objects may be explicitly activated through the POA without providing a user-specified identity value. Using this approach, objects are activated by performing the activate_object operation on the POA with the object in question. For this operation, the POA allocates, assigns, and returns a unique identity value for the object.

   Generally this capability is most useful for transient objects, where the Object Id needs to be valid only as long as the servant is active in the server. The Object Ids can remain completely hidden and no servant manager need be provided. When this is the case, the identity and lifetime of the servant and the abstract object are essentially equivalent. When POA-assigned Object Ids are used with persistent objects or objects that are activated on demand, the application must be able to associate the generated Object Id value with its corresponding object state.

   This example illustrates a simple implementation of transient objects using POA-assigned Object Ids. It presumes a POA that has the SYSTEM_ID, USE_SERVANT_MANAGER, and RETAIN policies.

   Assume this interface:

   // IDLinterface Foo {long doit();};

   This might result in the generation of the following skeleton:

   class POA_Foo : public ServantBase{public:...virtual CORBA::Long doit() = 0;}

   Derive your implementation:

   class MyFooServant : public POA_Foo{

   public:MyFooServant(POA_ptr poa, Long value): my_poa(POA::_duplicate(poa)), my_value(value) {}~MyFooServant() {CORBA::release(my_poa);}virtual POA_ptr _default_POA()

   {return POA::_duplicate(my_poa);}virtual Long doit() {return my_value;}

   protected:POA_ptr my_poa;Long my_value;

   };

   Now, somewhere in the program during initialization, probably in main():

   MyFooServant* afoo = new MyFooServant(poa,27);

   PortableServer::ObjectId_var oid =

   poa->activate_object(afoo);Foo_var foo = afoo->_this();poa->the_POAManager()->activate();orb->run();

   This object is activated with a generated Object Id.