Archived
This forum has been archived. Please start a new discussion on GitHub.
specifying proxy's locator
I have two indirect proxies and I want them to use two different locators. According to sec. 30.16.3 this can be done in 3 ways. I try 2 of them: by calling prx->ice_locator() and by calling comm->setDefaultLocator(). Both seem to have no effect: the proxies always get resolved through the original default locator.
Short sample code is below with debugging lines removed. BTW, I use ice_ping() and ice_connection() to see which objects the proxies resolve. for example:
obj->ice_ping();
cout<<obj->ice_connection()->toString()<<endl;
int App::run( int argc, char* argv[] )
{
// first locator
Ice::ObjectPrx olocA = communicator()->stringToProxy( "IceGrid/Locator: default -h remotehost -p 12000" );
Ice::LocatorPrx locA = Ice::LocatorPrx::checkedCast( olocA );
communicator()->setDefaultLocator( locA );
// create a proxy, it uses default locator (WORKS FINE)
Ice::ObjectPrx oadminA = communicator()->stringToProxy("IceGrid/Admin");
// define new locator
Ice::ObjectPrx olocB = communicator()->stringToProxy( "IceGrid/Locator:tcp -h localhost -p 12005" );
Ice::LocatorPrx locB = Ice::LocatorPrx::checkedCast( olocB );
// another proxy, change locator directly (DOES NOT WORK)
Ice::ObjectPrx oadminB = communicator()->stringToProxy("IceGrid/Admin");
oadminB = oadminB->ice_locator( locB );
// change the default locator
communicator()->setDefaultLocator( locB );
// create another proxy, should use the new locator (DOES NOT WORK)
Ice::ObjectPrx oadminC = communicator()->stringToProxy("IceGrid/Admin");
return 0;
}
here's the output (with ip addresses replaced with x.x.x). Note how "thru locator B" entries should go to localhost on 127.0.0.1 but they go to the remote host.
==========
default locator :IceGrid/Locator -t:tcp -h remotehost -p 12000
thru default locator :
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
thru default locator 2:
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
locator B:
local address = 127.0.0.1:60525
remote address = 127.0.0.1:12005
thru locator B :
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
new default locator :IceGrid/Locator -t:tcp -h localhost -p 12005
thru locator B as default :
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
======
Short sample code is below with debugging lines removed. BTW, I use ice_ping() and ice_connection() to see which objects the proxies resolve. for example:
obj->ice_ping();
cout<<obj->ice_connection()->toString()<<endl;
int App::run( int argc, char* argv[] )
{
// first locator
Ice::ObjectPrx olocA = communicator()->stringToProxy( "IceGrid/Locator: default -h remotehost -p 12000" );
Ice::LocatorPrx locA = Ice::LocatorPrx::checkedCast( olocA );
communicator()->setDefaultLocator( locA );
// create a proxy, it uses default locator (WORKS FINE)
Ice::ObjectPrx oadminA = communicator()->stringToProxy("IceGrid/Admin");
// define new locator
Ice::ObjectPrx olocB = communicator()->stringToProxy( "IceGrid/Locator:tcp -h localhost -p 12005" );
Ice::LocatorPrx locB = Ice::LocatorPrx::checkedCast( olocB );
// another proxy, change locator directly (DOES NOT WORK)
Ice::ObjectPrx oadminB = communicator()->stringToProxy("IceGrid/Admin");
oadminB = oadminB->ice_locator( locB );
// change the default locator
communicator()->setDefaultLocator( locB );
// create another proxy, should use the new locator (DOES NOT WORK)
Ice::ObjectPrx oadminC = communicator()->stringToProxy("IceGrid/Admin");
return 0;
}
here's the output (with ip addresses replaced with x.x.x). Note how "thru locator B" entries should go to localhost on 127.0.0.1 but they go to the remote host.
==========
default locator :IceGrid/Locator -t:tcp -h remotehost -p 12000
thru default locator :
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
thru default locator 2:
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
locator B:
local address = 127.0.0.1:60525
remote address = 127.0.0.1:12005
thru locator B :
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
new default locator :IceGrid/Locator -t:tcp -h localhost -p 12005
thru locator B as default :
local address = 129.x.x.x:60767
remote address = 172.x.x.x:32855
======
0
Comments
-
You need to use different object identities for your different locators. See IceGrid.InstanceName.
The Ice runtime uses these identities as keys of its local Locator caches.
Cheers,
Bernard0 -
Thanks Bernard,
made it all clear and it works now.
just a side note... as I was playing with the Ice::ObjectPrx interface, it seemed to me that it's slightly inconsistent.
there're several functions which come in pairs, basically getXXX and newXXX, e.g.
Context ice_getContext();
Object* ice_newContext(Context ctx);
and then there those which only have newXXX, but the name does not reflect it, e.g.
Object* ice_router(Router* rtr);
Object* ice_locator(Locator* loc);
I guess there're must be a reason why you don't have something like this:
Locator* ice_getLocator();
Object* ice_newLocator(Locator* loc);
cheers, alex0