恒TAO CORBA IOR

时间:2014-08-26 23:32:59

标签: corba object-to-string tao

如何配置TAO corba服务器以使从object_to_string生成的此服务器的IOR字符串是常量?

每次从object_to_string生成的IOR字符串在服务器重新启动后都会更改。这很不方便,因为客户端必须通过重新加载IOR文件或命名服务访问来更新其缓存的服务器IOR字符串。因此,无论重启多少次,服务器都可以生成一个常量IOR字符串,这将非常有用。

我的corba服务器基于ACE + TAO,我确实记得TAO支持常量IOR字符串:每次生成的IOR字符串都相同,解决方案是为服务器添加一些配置。但我现在不记得这些配置了。

============================================= 更新:

在ACE_wrappers / TAO / tests / POA / Persistent_ID / server.cpp中,我添加了一个名为testUniqe()的新函数,它与creatPOA方法类似。更新文件内容为:

void testUniqu(CORBA::ORB_ptr orb_, PortableServer::POA_ptr poa_){

  CORBA::PolicyList policies (2);
  policies.length (2);          
                                                     //IOR is the same even it is SYSTEM_ID
  policies[0] =   poa_->create_id_assignment_policy (PortableServer::USER_ID); 

  policies[1] =   poa_->create_lifespan_policy (PortableServer::PERSISTENT);
  PortableServer::POAManager_var poa_manager = poa_->the_POAManager ();
  PortableServer::POA_ptr child_poa_ =   poa_->create_POA ("childPOA", poa_manager.in (), policies);

  // Destroy the policies
  for (CORBA::ULong i = 0;  i < policies.length ();  ++i)  {
      policies[i]->destroy ();
    }

  test_i *servant =   new test_i (orb_, child_poa_);

  PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("xushijie");
  child_poa_->activate_object_with_id (oid,  servant);

  PortableServer::ObjectId_var id =  poa_->activate_object (servant);
  CORBA::Object_var object = poa_->id_to_reference (id.in ());

  test_var test =  test::_narrow (object.in ());
  CORBA::String_var ior = orb_->object_to_string(test.in());
  std::cout<<ior.in()<<std::endl;

  poa_->the_POAManager()->activate();
  orb_->run();
}

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      int result = parse_args (argc, argv);
      CORBA::Object_var obj =
        orb->resolve_initial_references ("RootPOA");

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();
      testUniqu(orb.in(), root_poa.in());
       orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught");
      return -1;
    }

  return 0;
}

问题是一旦重启,输出服务器IOR仍然不同。我还将此代码与第412页(Advance Corba Programming)中的代码进行了比较,但仍然失败..

///////////////////////////////////

更新:

使用“server -ORBListenEndpoints iiop://:1234&gt; / tmp / ior1”,生成的两个IOR为:

IOR:010000000d00000049444c3a746573743a312e300000000001000000000000007400000001010200150000007368696a69652d5468696e6b5061642d543431300000d2041b00000014010f0052535453f60054c6f80c000000000001000000010000000002000000000000000800000001000000004f41540100000018000000010000000100010001000000010001050901010000000000 IOR:010000000d00000049444c3a746573743a312e300000000001000000000000007400000001010200150000007368696a69652d5468696e6b5061642d543431300000d2041b00000014010f0052535468f60054da280a000000000001000000010000000002000000000000000800000001000000004f41540100000018000000010000000100010001000000010001050901010000000000

对于ior1和ior2的tao_catior的结果:

ior1: 
The Byte Order: Little Endian
The Type Id:    "IDL:test:1.0"
Number of Profiles in IOR:      1
Profile number: 1
IIOP Version:   1.2
    Host Name:  **
    Port Number:        1234
    Object Key len:     27
    Object Key as hex:
    14 01 0f 00 52 53 54 53 f6 00 54 c6 f8 0c 00 00
    00 00 00 01 00 00 00 01 00 00 00
    The Object Key as string:
    ....RSTS..T................
    The component <1> ID is 00 (TAG_ORB_TYPE)
            ORB Type: 0x54414f00 (TAO)
    The component <2> ID is 11 (TAG_CODE_SETS)
        Component length: 24
        Component byte order:   Little Endian
        Native CodeSet for char:  Hex - 10001   Description - ISO8859_1
        Number of CCS for char 1
        Conversion Codesets for char are:
        1)  Hex - 5010001       Description - UTF-8
        Native CodeSet for wchar:  Hex - 10109  Description - UTF-16
        Number of CCS for wchar 0
ecoding an IOR:


//ior2
The Byte Order: Little Endian
The Type Id:    "IDL:test:1.0"
Number of Profiles in IOR:      1
Profile number: 1
IIOP Version:   1.2
    Host Name:  **
    Port Number:        1234
    Object Key len:     27
    Object Key as hex:
    14 01 0f 00 52 53 54 68 f6 00 54 da 28 0a 00 00
    00 00 00 01 00 00 00 01 00 00 00
    The Object Key as string:
    ....RSTh..T.(..............
    The component <1> ID is 00 (TAG_ORB_TYPE)
            ORB Type: 0x54414f00 (TAO)
    The component <2> ID is 11 (TAG_CODE_SETS)
        Component length: 24
        Component byte order:   Little Endian
        Native CodeSet for char:  Hex - 10001   Description - ISO8859_1
        Number of CCS for char 1
        Conversion Codesets for char are:
        1)  Hex - 5010001       Description - UTF-8
        Native CodeSet for wchar:  Hex - 10109  Description - UTF-16
        Number of CCS for wchar 0

差异结果是:

<     14 01 0f 00 52 53 54 53 f6 00 54 c6 f8 0c 00 00 
---
>     14 01 0f 00 52 53 54 68 f6 00 54 da 28 0a 00 00 
19c19
<     ....RSTS..T................
---
>     ....RSTh..T.(..............

类似的差异结果是:

<     14 01 0f 00 52 53 54 62 fd 00 54 2c 9a 0e 00 00 
---
>     14 01 0f 00 52 53 54 02 fd 00 54 f9 a9 09 00 00 
19c19
<     ....RSTb..T,...............
---
>     ....RST...T................

不同之处在于ObjectKey。

============================================

更新:

我没有使用上面的代码,而是找到了一个更好的解决方案,使用了助手TAO_ORB_Manager,它使用了NamingService和TAO / examples / Simple。 TAO_ORB_Manager封装API并生成持久性IOR,作为Simple.cpp中的示例代码:

  if (this->orb_manager_.init_child_poa (argc, argv, "child_poa") == -1){
      CORBA::String_var str  = 
        this->orb_manager_.activate_under_child_poa (servant_name,
                                                     this->servant_.in ());
  }

这是TAO_ORB_Manager的一些描述:

class TAO_UTILS_Export TAO_ORB_Manager
{
  /**
   * Creates a child poa under the root poa with PERSISTENT and
   * USER_ID policies.  Call this if you want a @a child_poa with the
   * above policies, otherwise call init.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int init_child_poa (int &argc,
                      ACE_TCHAR *argv[],
                      const char *poa_name,
                      const char *orb_name = 0);


  /**
   * Precondition: init_child_poa has been called.  Activate <servant>
   * using the POA <activate_object_with_id> created from the string
   * <object_name>. Users should call this to activate objects under
   * the child_poa.
   *
   * @param object_name  String name which will be used to create
   *                     an Object ID for the servant.
   * @param servant  The servant to activate under the child POA.
   *
   * @return 0 on failure, a string representation of the object ID if
   *           successful.  Caller of this method is responsible for
   *           memory deallocation of the string.
   */
  char *activate_under_child_poa (const char *object_name,
                                  PortableServer::Servant servant);
  ...................
}

构建之后,我可以使用-ORBListenEndpoints iiop:// localhost:2809选项获得我想要的内容。谢谢@Johnny Willemsen的帮助

1 个答案:

答案 0 :(得分:1)

您必须使用持久性生命周期策略创建POA,请参阅ACE_wrappers / TAO / tests / POA / Persistent_ID作为TAO分发的一部分。