【问题标题】:Destroy of corba servants actived by _this_this激活的眼镜蛇仆从的毁灭
【发布时间】:2013-12-05 04:29:32
【问题描述】:

在 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。

【问题讨论】:

    标签: corba ace tao


    【解决方案1】:

    在 POA 下激活了一个servant,所以如果你想在一个新的 ORB 下激活 accountservant,你必须在某个地方创建那个 ORB,创建一个新的 POA,然后覆盖 Accountservant 中的 _default_POA 方法以返回那个不同的 POA。另一种选择是不使用 _this,而是手动激活 POA。

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

    【讨论】:

    • 应该是 !account.is_nil() 关闭。示例中可能有错误 dre.vanderbilt.edu/~schmidt/DOC_ROOT/TAO/examples/Simple/bank/… 。在 open 方法中,新的 Account_i 被分配给 'Account_var result' 并在 result._this() 之后被回收,因为结果超出了范围。 close 方法的参数 Account_ptr 是 open 方法的一个返回值。关键问题是我们是否应该在open方法中回收等于result->_this()的Account_ptr?
    • 使用 _this(),Account_i 在 POA 中被激活,并返回一个客户端对象引用。此客户端对象引用再次用于关闭服务方。我看不出该代码有什么问题。
    • 第一个,if(account.is_nil ()) 应该是 if(!account.is_nil ()) 在你指出的关闭方法中; 2、不知道是否应该释放Accounti_ptr客户端引用?或者Account_i_ptr什么时候会被回收?
    • 你不需要在Account_i中释放_ptr,调用方法中的Account_var会丢弃对象引用的引用计数,这意味着它会得到析构函数。与1相关,我已经对代码进行了改编,将在下一个TAO版本中出现。
    • 还检查 TAOX11 作为支持 IDL 到 C++11 的 CORBA 实现,这更容易使用
    猜你喜欢
    • 2015-01-28
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 2014-10-29
    • 2022-01-05
    • 1970-01-01
    相关资源
    最近更新 更多