本文整理汇总了C++中ice::ObjectAdapterPtr::setLocator方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectAdapterPtr::setLocator方法的具体用法?C++ ObjectAdapterPtr::setLocator怎么用?C++ ObjectAdapterPtr::setLocator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ice::ObjectAdapterPtr
的用法示例。
在下文中一共展示了ObjectAdapterPtr::setLocator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
ServerManagerI::startServer(const Ice::Current&)
{
for(::std::vector<Ice::CommunicatorPtr>::const_iterator i = _communicators.begin(); i != _communicators.end(); ++i)
{
(*i)->waitForShutdown();
(*i)->destroy();
}
_communicators.clear();
//
// Simulate a server: create a new communicator and object
// adapter. The object adapter is started on a system allocated
// port. The configuration used here contains the Ice.Locator
// configuration variable. The new object adapter will register
// its endpoints with the locator and create references containing
// the adapter id instead of the endpoints.
//
Ice::CommunicatorPtr serverCommunicator = Ice::initialize(_initData);
_communicators.push_back(serverCommunicator);
//
// Use fixed port to ensure that OA re-activation doesn't re-use previous port from
// another OA (e.g.: TestAdapter2 is re-activated using port of TestAdapter).
//
{
std::ostringstream os;
os << "default -p " << _nextPort++;
serverCommunicator->getProperties()->setProperty("TestAdapter.Endpoints", os.str());
}
{
std::ostringstream os;
os << "default -p " << _nextPort++;
serverCommunicator->getProperties()->setProperty("TestAdapter2.Endpoints", os.str());
}
Ice::ObjectAdapterPtr adapter = serverCommunicator->createObjectAdapter("TestAdapter");
Ice::ObjectAdapterPtr adapter2 = serverCommunicator->createObjectAdapter("TestAdapter2");
Ice::ObjectPrxPtr locator = serverCommunicator->stringToProxy("locator:default -p 12010");
adapter->setLocator(ICE_UNCHECKED_CAST(Ice::LocatorPrx, locator));
adapter2->setLocator(ICE_UNCHECKED_CAST(Ice::LocatorPrx, locator));
Ice::ObjectPtr object = ICE_MAKE_SHARED(TestI, adapter, adapter2, _registry);
_registry->addObject(adapter->add(object, serverCommunicator->stringToIdentity("test")));
_registry->addObject(adapter->add(object, serverCommunicator->stringToIdentity("test2")));
adapter->add(object, serverCommunicator->stringToIdentity("test3"));
adapter->activate();
adapter2->activate();
}
示例2: test
//.........这里部分代码省略.........
{
// Expected to fail once they endpoints have been updated in the background.
}
ic->destroy();
}
cout << "ok" << endl;
cout << "testing proxy from server after shutdown... " << flush;
hello = obj->getReplicatedHello();
obj->shutdown();
manager->startServer();
hello->sayHello();
cout << "ok" << endl;
cout << "testing object migration... " << flush;
hello = HelloPrx::checkedCast(communicator->stringToProxy("hello"));
obj->migrateHello();
// TODO: enable after fixing ICE-5489
//hello->ice_getConnection()->close(false);
hello->sayHello();
obj->migrateHello();
hello->sayHello();
obj->migrateHello();
hello->sayHello();
cout << "ok" << endl;
cout << "testing locator encoding resolution... " << flush;
hello = HelloPrx::checkedCast(communicator->stringToProxy("hello"));
count = locator->getRequestCount();
communicator->stringToProxy("[email protected]")->ice_encodingVersion(Ice::Encoding_1_1)->ice_ping();
test(count == locator->getRequestCount());
communicator->stringToProxy("[email protected]")->ice_encodingVersion(Ice::Encoding_1_0)->ice_ping();
test(++count == locator->getRequestCount());
communicator->stringToProxy("test -e [email protected]")->ice_ping();
test(++count == locator->getRequestCount());
cout << "ok" << endl;
cout << "shutdown server... " << flush;
obj->shutdown();
cout << "ok" << endl;
cout << "testing whether server is gone... " << flush;
try
{
obj2->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
}
try
{
obj3->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
}
try
{
obj5->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
}
cout << "ok" << endl;
cout << "testing indirect proxies to collocated objects... " << flush;
//
// Set up test for calling a collocated object through an indirect, adapterless reference.
//
Ice::PropertiesPtr properties = communicator->getProperties();
properties->setProperty("Ice.PrintAdapterReady", "0");
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Hello", "default");
adapter->setLocator(locator);
Ice::Identity id;
id.name = IceUtil::generateUUID();
registry->addObject(adapter->add(new HelloI, id));
adapter->activate();
try
{
HelloPrx helloPrx = HelloPrx::checkedCast(communicator->stringToProxy(communicator->identityToString(id)));
Ice::ConnectionPtr connection = helloPrx->ice_getConnection();
test(false);
}
catch(const Ice::CollocationOptimizationException&)
{
}
adapter->deactivate();
cout << "ok" << endl;
cout << "shutdown server manager... " << flush;
manager->shutdown();
cout << "ok" << endl;
}
示例3: while
void
ServerManagerI::startServer(const Ice::Current&)
{
for(::std::vector<Ice::CommunicatorPtr>::const_iterator i = _communicators.begin(); i != _communicators.end(); ++i)
{
(*i)->waitForShutdown();
(*i)->destroy();
}
_communicators.clear();
//
// Simulate a server: create a new communicator and object
// adapter. The object adapter is started on a system allocated
// port. The configuration used here contains the Ice.Locator
// configuration variable. The new object adapter will register
// its endpoints with the locator and create references containing
// the adapter id instead of the endpoints.
//
Ice::CommunicatorPtr serverCommunicator = Ice::initialize(_initData);
_communicators.push_back(serverCommunicator);
//
// Use fixed port to ensure that OA re-activation doesn't re-use previous port from
// another OA (e.g.: TestAdapter2 is re-activated using port of TestAdapter).
//
int nRetry = 10;
while(--nRetry > 0)
{
Ice::ObjectAdapterPtr adapter;
Ice::ObjectAdapterPtr adapter2;
try
{
Ice::PropertiesPtr props = _initData.properties;
serverCommunicator->getProperties()->setProperty("TestAdapter.Endpoints",
getTestEndpoint(props, _nextPort++));
serverCommunicator->getProperties()->setProperty("TestAdapter2.Endpoints",
getTestEndpoint(props, _nextPort++));
adapter = serverCommunicator->createObjectAdapter("TestAdapter");
adapter2 = serverCommunicator->createObjectAdapter("TestAdapter2");
Ice::ObjectPrxPtr locator = serverCommunicator->stringToProxy("locator:" + getTestEndpoint(props, 0));
adapter->setLocator(ICE_UNCHECKED_CAST(Ice::LocatorPrx, locator));
adapter2->setLocator(ICE_UNCHECKED_CAST(Ice::LocatorPrx, locator));
Ice::ObjectPtr object = ICE_MAKE_SHARED(TestI, adapter, adapter2, _registry);
_registry->addObject(adapter->add(object, Ice::stringToIdentity("test")));
_registry->addObject(adapter->add(object, Ice::stringToIdentity("test2")));
adapter->add(object, Ice::stringToIdentity("test3"));
adapter->activate();
adapter2->activate();
break;
}
catch(const Ice::SocketException&)
{
if(nRetry == 0)
{
throw;
}
// Retry, if OA creation fails with EADDRINUSE (this can occur when running with JS web
// browser clients if the driver uses ports in the same range as this test, ICE-8148)
if(adapter)
{
adapter->destroy();
}
if(adapter2)
{
adapter2->destroy();
}
}
}
}
示例4: test
//.........这里部分代码省略.........
communicator->stringToProxy("test")->ice_locatorCacheTimeout(-1)->ice_ping();
test(count == locator->getRequestCount());
communicator->stringToProxy("[email protected]")->ice_ping();
test(count == locator->getRequestCount());
communicator->stringToProxy("test")->ice_ping();
test(count == locator->getRequestCount());
test(communicator->stringToProxy("test")->ice_locatorCacheTimeout(99)->ice_getLocatorCacheTimeout() == 99);
cout << "ok" << endl;
cout << "testing proxy from server... " << flush;
HelloPrx hello = obj->getHello();
test(hello->ice_getAdapterId() == "TestAdapter");
hello->sayHello();
hello = obj->getReplicatedHello();
test(hello->ice_getAdapterId() == "ReplicatedAdapter");
hello->sayHello();
cout << "ok" << endl;
cout << "testing proxy from server after shutdown... " << flush;
obj->shutdown();
manager->startServer();
hello->sayHello();
cout << "ok" << endl;
cout << "testing object migration... " << flush;
hello = HelloPrx::checkedCast(communicator->stringToProxy("hello"));
obj->migrateHello();
hello->sayHello();
obj->migrateHello();
hello->sayHello();
obj->migrateHello();
hello->sayHello();
cout << "ok" << endl;
cout << "shutdown server... " << flush;
obj->shutdown();
cout << "ok" << endl;
cout << "testing whether server is gone... " << flush;
try
{
obj2->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
}
try
{
obj3->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
}
try
{
obj5->ice_ping();
test(false);
}
catch(const Ice::LocalException&)
{
}
cout << "ok" << endl;
cout << "testing indirect proxies to collocated objects... " << flush;
//
// Set up test for calling a collocated object through an indirect, adapterless reference.
//
Ice::PropertiesPtr properties = communicator->getProperties();
properties->setProperty("Ice.PrintAdapterReady", "0");
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Hello", "default");
adapter->setLocator(locator);
TestLocatorRegistryPrx registry = TestLocatorRegistryPrx::checkedCast(locator->getRegistry());
test(registry);
Ice::Identity id;
id.name = IceUtil::generateUUID();
registry->addObject(adapter->add(new HelloI, id));
adapter->activate();
try
{
HelloPrx helloPrx = HelloPrx::checkedCast(communicator->stringToProxy(communicator->identityToString(id)));
Ice::ConnectionPtr connection = helloPrx->ice_getConnection();
test(false);
}
catch(const Ice::CollocationOptimizationException&)
{
}
adapter->deactivate();
cout << "ok" << endl;
cout << "shutdown server manager... " << flush;
manager->shutdown();
cout << "ok" << endl;
}