【发布时间】:2014-01-22 09:27:52
【问题描述】:
我正在使用 MICO 创建一个 C++ CORBA 服务器。
在我的系统中,客户端应该能够使用 corbaloc 地址(无名称服务)直接访问服务器中的 corba 对象。 你知道MICO是否提供这样的功能吗?我该如何实施?我试过了:
ORB_ptr orb = CORBA::ORB_init (argc, argv, "mico-local-orb");
Object_var obj = orb -> resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj );
PortableServer::POAManager_var pman = poa -> the_POAManager();
pman -> activate();
PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId( "hello" );
HelloImpl* servant = new HelloImpl();
poa -> activate_object_with_id( oid.in(), servant );
servant -> _remove_ref();
orb -> run();
此代码适用于 OMNIORB,但不适用于 MICO。
编辑:我也尝试了持久的生命周期政策,但它也不起作用:
ORB_ptr orb = ORB_init( argc, argv );
Object_var obj = orb -> resolve_initial_references( "RootPOA" );
PortableServer::POA_var poa = PortableServer::POA::_narrow( obj );
PortableServer::POAManager_var pman = poa -> the_POAManager();
pman -> activate();
PortableServer::LifespanPolicy_var lifespan =
poa -> create_lifespan_policy( PortableServer::PERSISTENT );
PortableServer::IdAssignmentPolicy_var idassignment =
poa -> create_id_assignment_policy ( PortableServer::USER_ID );
CORBA::PolicyList policies( 2 );
policies.length( 2 );
policies[0] = PortableServer::IdAssignmentPolicy::_duplicate( idassignment );
policies[1] = PortableServer::LifespanPolicy::_duplicate( lifespan );
PortableServer::POA_var child_poa =
poa -> create_POA( "childPOA", pman.in(), policies );
PortableServer::POAManager_var child_pman = child_poa -> the_POAManager();
child_pman -> activate();
idassignment -> destroy();
lifespan -> destroy();
HelloImpl* servant = new HelloImpl();
PortableServer::ObjectId_var oid = child_poa -> activate_object( servant );
CORBA::Object_var ref = child_poa -> id_to_reference( oid.in() );
PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId( "hello" );
child_poa -> activate_object_with_id ( oid.in (), servant );
orb -> run();
编辑2:
我用一个尝试string_to_object以下corbaloc地址的客户端测试了服务器:
corbaloc:iiop:localhost:12345/hellocorbaloc:iiop:localhost:12345/childPOA/hello
但他们都没有工作。我总是收到CORBA::OBJECT_NOT_EXIST 异常。
谢谢
【问题讨论】:
-
@Reimeus 我也尝试了持久寿命策略(我将代码添加到我的问题中)。但它也不起作用。
-
究竟是什么不起作用,您是如何检查的?
-
@tuergeist 我写了一个客户端,使用
ORB::string_to_object解析corbaloc地址corbaloc:iiop:localhost:12345/hello,但是找不到远程对象。 -
你得到了什么样的异常? Object_not_found / 存在?还是瞬态的?
-
@tuergeist 我得到一个
CORBA::OBJECT_NOT_EXIST异常。