摧毁由_this活跃的corba仆人

时间:2013-12-05 04:29:32

标签: corba ace tao

在TAO / example / Simple / Bank的示例中,两个idl方法:open和close在AccountManager中定义,前者用于生成新激活的Account servant,而后者用于回收它。 AccountManager_i类似于:

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");
  }
}

问题是 1)结果(新创建的帐户服务方)是否在open方法中与AccountManager_i共享相同的ORB对象?如何使用此服务方的新重复ORB重置它?

2)何时在close方法中回收帐户(在Bank :: Account_ptr帐户中)对象。在该方法中,它仅从POA停用和分离。

1 个答案:

答案 0 :(得分:0)

在POA下激活服务方,因此如果您希望在新的ORB下激活帐户服务方,则必须在某处创建该ORB,创建新的POA,并覆盖帐户服务方中的_default_POA方法返回不同的POA。另一种选择是不使用_this,而是手动激活POA。

在close方法中,if(account.is_nil())应该是!account.is_nil(),据我所知。仆人是引用计数,当最后一个引用丢弃它被删除时,我看不到任何代码它被回收。