Destroy of corba servants actived by _this

1.2k views Asked by At

In the example of TAO/example/Simple/Bank, the two idl methods: open and close are defined in the AccountManager, the former is to generate a new activated Account servant while the latter is to recycle it . The AccountManager_i is like:

Bank::Account_ptr
AccountManager_i::open (const char *name,
                    CORBA::Float initial_balance)
{
     Account_i_var result;
     if (hash_map_.find (name, result) != 0)
     {
         Account_i *tmp = 0;
         ACE_NEW_THROW_EX (tmp,
                    Account_i (name,
                               initial_balance),
                    CORBA::NO_MEMORY ());
         result = tmp;
     }
    // Generate an IOR for the result object and register it with the
   // POA.  In case the object already exists then the previously
   // generated IOR is returned.
   return result->_this ();
 }

// Shutdown.
void
AccountManager_i::close (Bank::Account_ptr account)
{
  try
    {
     CORBA::String_var name = account->name ();
     Account_i_var account;
     ..
     if (account.is_nil ())
     {
      PortableServer::POA_var poa = account->_default_POA ();

      PortableServer::ObjectId_var id = poa->servant_to_id (account.in ());

      poa->deactivate_object (id.in ());
    }
   }
   catch (const CORBA::Exception& ex)
  {
     ex._tao_print_exception ("Unable to close Account\n");
  }
}

The question is 1) Is result(new created account servant)shares same ORB object with AccountManager_i in the open method? How can i reset it with a new duplicated ORB for this servant?

2) When did account(in Bank::Account_ptr account) object is recycled in the close method. In the method, it is only deactivate and detached from POA.

1

There are 1 answers

11
Johnny Willemsen On

A servant is activated under a POA, so if you want to have the account servant be activated under a new ORB, you have to create that ORB somewhere, create a new POA, and override the _default_POA method in the Account servant to return that different POA. The other option is to not use _this, but do a manual activation of the POA.

In the close method, the if (account.is_nil()) should be !account.is_nil() as far as I can determine. The servants are reference counted, when the last reference drops it gets deleted, I can't see any code that it is recycled.