0

在 TAO/example/Simple/Bank 的例子中,AccountManager 中定义了 open 和 close 两个 idl 方法,前者是生成一个新的激活的 Accountservant,后者是回收它。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) 什么时候 account(in Bank::Account_ptr account) 对象在 close 方法中被回收。在该方法中,它只是去激活和脱离POA。

4

1 回答 1

0

一个仆人在 POA 下被激活,所以如果你想在一个新的 ORB 下激活帐户仆人,你必须在某处创建那个 ORB,创建一个新的 POA,并覆盖帐户仆人中的 _default_POA 方法以返回不同的行动计划。另一种选择是不使用 _this,而是手动激活 POA。

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

于 2013-12-05T08:40:47.253 回答