Previous Table of Contents Next


11.6.6 Servant Manager Definition and Creation


   Servant managers are object implementations, and are required to satisfy all of the requirements of object implementations necessary for their intended function. Because servant managers are local objects, and their use is limited to a single narrow role, some simplifications in their implementation are possible. Note that these simplifications are suggestions, not normative requirements. They are intended as examples of ways to reduce the programming effort required to define servant managers.

   A servant manager implementation must provide the following things:

   The first two are obvious; their content is dictated by the requirements of the implementation that the servant manager is managing. For the third point, the default servant manager on the root POA already supplies this implementation code. User-written servant managers will have to provide this themselves.

   Since servant managers are objects, they themselves must be activated. It is expected that most servant managers can be activated on the root POA with its default set of policies (see “POA Creation? on page 11-6). It is for this reason that the root POA has the IMPLICIT_ACTIVATION policy so that a servant manager can easily be activated. Users may choose to activate a servant manager on other POAs.

   The following is an example servant manager to activate objects on demand. This example presumes a POA that has the USER_ID, USE_SERVANT_MANAGER, and RETAIN policies.

   Since RETAIN is in effect, the type of servant manager used is a ServantActivator. The ORB supplies a servant activator skeleton class in a library:

   // C++namespace POA_PortableServer{

   class ServantActivator : public virtual ServantManager

   {

   public:

   virtual ~ServantActivator();

   virtual Servant incarnate(

   const ObjectId& POA_ptr poa) = 0;

   virtual void etherealize(

   const ObjectId&, POA_ptr poa,

   Servant, Boolean remaining_activations) = 0;

   };};

   A ServantActivator servant manager might then look like:

   // C++class MyFooServantActivator : public

   POA_PortableServer::ServantActivator{

   public:

   // ...

   Servant incarnate(

   const ObjectId& oid, POA_ptr poa)

   {

   String_var s = PortbleServer::ObjectId_to_string(oid);if (strcmp(s, “myLittleFoo?) == 0) {return new MyFooServant(poa, 27);else {throw CORBA::OBJECT_NOT_EXIST();}}

   void etherealize(const ObjectId& oid, POA_ptr poa,Servant servant, Boolean remaining_activations)

   {if (remaining_activations == 0)

   delete servant;}// ...

   };