簡體   English   中英

常量TAO CORBA IOR

[英]Constant TAO CORBA IOR

如何配置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仍然不同。 我還將此代碼與Page 412(高級Corba編程)中的代碼進行了比較,但仍然失敗。

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

更新:

使用“服務器-ORBListenEndpoints iiop://:1234> / tmp / ior1”,生成的兩個IOR為:

IOR:IOR 010000000d00000049444c3a746573743a312e300000000001000000000000007400000001010200150000007368696a69652d5468696e6b5061642d543431300000d2041b00000014010f0052535453f60054c6f80c000000000001000000010000000002000000000000000800000001000000004f41540100000018000000010000000100010001000000010001050901010000000000:010000000d00000049444c3a746573743a312e300000000001000000000000007400000001010200150000007368696a69652d5468696e6b5061642d543431300000d2041b00000014010f0052535468f60054da280a000000000001000000010000000002000000000000000800000001000000004f41540100000018000000010000000100010001000000010001050901010000000000

tao_catior對於ior1和ior2的結果:

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。

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

更新:

我沒有使用上面的代碼,而是使用了NamingService和TAO / examples / Simple助手TAO_ORB_Manager找到了更好的解決方案。 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幫助

您必須使用持久性生命周期策略創建POA,請參閱ACE_wrappers / TAO / tests / POA / Persistent_ID作為TAO分發的一部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM