Ice::ObjectPrx WellKnownObjectsManager::getWellKnownObjectReplicatedProxy(const Ice::Identity& id, const string& endpt) { try { Ice::ObjectPrx proxy = _database->getObjectProxy(id); Ice::EndpointSeq registryEndpoints = getEndpoints(endpt)->ice_getEndpoints(); // // Re-order the endpoints to return first the endpoint for this // registry replica. // Ice::EndpointSeq endpoints = proxy->ice_getEndpoints(); Ice::EndpointSeq newEndpoints = registryEndpoints; for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { if(find(registryEndpoints.begin(), registryEndpoints.end(), *p) == registryEndpoints.end()) { newEndpoints.push_back(*p); } } return proxy->ice_endpoints(newEndpoints); } catch(const ObjectNotRegisteredException&) { // // If for some reasons the object isn't registered, we compute // the endpoints with the replica cache. For slaves, this will // however only return the slave endpoints. // return _database->getReplicaCache().getEndpoints(endpt, getEndpoints(endpt))->ice_identity(id); } }
Ice::ObjectPrx ReplicaCache::getEndpoints(const string& name, const Ice::ObjectPrx& proxy) const { Ice::EndpointSeq endpoints; if(proxy) { Ice::EndpointSeq endpts = proxy->ice_getEndpoints(); endpoints.insert(endpoints.end(), endpts.begin(), endpts.end()); } Lock sync(*this); for(map<string, ReplicaEntryPtr>::const_iterator p = _entries.begin(); p != _entries.end(); ++p) { Ice::ObjectPrx prx = p->second->getSession()->getEndpoint(name); if(prx) { Ice::EndpointSeq endpts = prx->ice_getEndpoints(); endpoints.insert(endpoints.end(), endpts.begin(), endpts.end()); } } return _communicator->stringToProxy("dummy")->ice_endpoints(endpoints); }
string IceStormInternal::describeEndpoints(const Ice::ObjectPrx& proxy) { ostringstream os; if(proxy) { Ice::EndpointSeq endpoints = proxy->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator i = endpoints.begin(); i != endpoints.end(); ++i) { if(i != endpoints.begin()) { os << ", "; } os << "\"" << (*i)->toString() << "\""; } } else { os << "subscriber proxy is null"; } return os.str(); }
void ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locatorInfo, const Ice::ObjectPrx& proxy, bool registerProcess) { if(!registerProcess && _id.empty()) { return; // Nothing to update. } // // Call on the locator registry outside the synchronization to // blocking other threads that need to lock this OA. // LocatorRegistryPrx locatorRegistry = locatorInfo ? locatorInfo->getLocatorRegistry() : LocatorRegistryPrx(); string serverId; if(registerProcess) { assert(_instance); serverId = _instance->initializationData().properties->getProperty("Ice.ServerId"); if(!locatorRegistry) { Warning out(_instance->initializationData().logger); out << "object adapter `" << getName() << "' cannot register the process without a locator registry"; } else if(serverId.empty()) { Warning out(_instance->initializationData().logger); out << "object adapter `" << getName() << "' cannot register the process without a value for Ice.ServerId"; } } if(!locatorRegistry) { return; } if(!_id.empty()) { try { if(_replicaGroupId.empty()) { locatorRegistry->setAdapterDirectProxy(_id, proxy); } else { locatorRegistry->setReplicatedAdapterDirectProxy(_id, _replicaGroupId, proxy); } } catch(const AdapterNotFoundException&) { if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n"; out << "the object adapter is not known to the locator registry"; } NotRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "object adapter"; ex.id = _id; throw ex; } catch(const InvalidReplicaGroupIdException&) { if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n"; out << "the replica group `" << _replicaGroupId << "' is not known to the locator registry"; } NotRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "replica group"; ex.id = _replicaGroupId; throw ex; } catch(const AdapterAlreadyActiveException&) { if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n"; out << "the object adapter endpoints are already set"; } ObjectAdapterIdInUseException ex(__FILE__, __LINE__); ex.id = _id; throw ex; } catch(const LocalException& ex) { if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n" << ex; } throw; // TODO: Shall we raise a special exception instead of a non obvious local exception? } if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "updated object adapter `" + _id + "' endpoints with the locator registry\n"; out << "endpoints = "; if(proxy) { EndpointSeq endpts = proxy ? proxy->ice_getEndpoints() : EndpointSeq(); ostringstream o; transform(endpts.begin(), endpts.end(), ostream_iterator<string>(o, endpts.size() > 1 ? ":" : ""), Ice::constMemFun(&Endpoint::toString)); out << o.str(); } } } if(registerProcess && !serverId.empty()) { { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); if(_processId.name == "") { ProcessPtr servant = new ProcessI(_communicator); _processId = addWithUUID(servant)->ice_getIdentity(); } } try { locatorRegistry->setServerProcessProxy(serverId, ProcessPrx::uncheckedCast(createDirectProxy(_processId))); } catch(const ServerNotFoundException&) { if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "couldn't register server `" + serverId + "' with the locator registry:\n"; out << "the server is not known to the locator registry"; } NotRegisteredException ex(__FILE__, __LINE__); ex.kindOfObject = "server"; ex.id = serverId; throw ex; } catch(const Ice::LocalException& ex) { if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "couldn't register server `" + serverId + "' with the locator registry:\n" << ex; } throw; // TODO: Shall we raise a special exception instead of a non obvious local exception? } if(_instance->traceLevels()->location >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat); out << "registered server `" + serverId + "' with the locator registry"; } } }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "cycle"); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx topic; while(true) { try { topic = manager->retrieve("single"); break; } // This can happen if the replica group loses the majority // during retrieve. In this case we retry. catch(const Ice::UnknownException&) { continue; } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } } assert(topic); // // Get a publisher object, create a twoway proxy and then cast to // a Single object. // if(opts.isSet("cycle")) { Ice::ObjectPrx prx = topic->getPublisher()->ice_twoway(); vector<SinglePrx> single; Ice::EndpointSeq endpoints = prx->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { if((*p)->toString().substr(0, 3) != "udp") { Ice::EndpointSeq e; e.push_back(*p); single.push_back(SinglePrx::uncheckedCast(prx->ice_endpoints(e))); } } if(single.size() <= 1) { cerr << argv[0] << ": Not enough endpoints in publisher proxy" << endl; return EXIT_FAILURE; } int which = 0; for(int i = 0; i < 1000; ++i) { single[which]->event(i); which = (which + 1) % static_cast<int>(single.size()); } } else { SinglePrx single = SinglePrx::uncheckedCast(topic->getPublisher()->ice_twoway()); for(int i = 0; i < 1000; ++i) { single->event(i); } } return EXIT_SUCCESS; }
int main(int argc, char** argv) { cout << "testing proxy hash algorithm collisions... " << flush; map<Ice::Int, Ice::ObjectPrx> seenProxy; map<Ice::Int, Ice::EndpointPtr> seenEndpoint; unsigned int proxyCollisions = 0; unsigned int i = 0; unsigned int maxCollisions = 10; unsigned int maxIterations = 10000; Ice::InitializationData id; id.properties = Ice::createProperties(argc, argv); #ifndef ICE_OS_WINRT // // In Ice for WinRT IceSSL is part of Ice core. // id.properties->setProperty("Ice.Plugin.IceSSL", "IceSSL:createIceSSL"); id.properties->setProperty("IceSSL.Keychain", "client.keychain"); id.properties->setProperty("IceSSL.KeychainPassword", "password"); #endif Ice::CommunicatorPtr communicator = Ice::initialize(id); for(i = 0; proxyCollisions < maxCollisions && i < maxIterations; ++i) { ostringstream os; os << i << ":tcp -p " << IceUtilInternal::random(65536) << " -t 10" << IceUtilInternal::random(1000000) << ":udp -p " << IceUtilInternal::random(65536) << " -h " << IceUtilInternal::random(100); Ice::ObjectPrx obj = communicator->stringToProxy(os.str()); Ice::EndpointSeq endpoints = obj->ice_getEndpoints(); if(!seenProxy.insert(make_pair(obj->__hash(), obj)).second) { ++proxyCollisions; } test(obj->__hash() == obj->__hash()); } test(proxyCollisions < maxCollisions); // // Check the same proxy produce the same hash, even when we recreate the proxy. // Ice::ObjectPrx prx1 = communicator->stringToProxy("Glacier2/router:tcp -p 10010"); Ice::ObjectPrx prx2 = communicator->stringToProxy("Glacier2/router:ssl -p 10011"); Ice::ObjectPrx prx3 = communicator->stringToProxy("Glacier2/router:udp -p 10012"); Ice::ObjectPrx prx4 = communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010"); Ice::ObjectPrx prx5 = communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011"); Ice::ObjectPrx prx6 = communicator->stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012"); Ice::ObjectPrx prx7 = communicator->stringToProxy("Glacier2/router:tcp -p 10010 -t 10000"); Ice::ObjectPrx prx8 = communicator->stringToProxy("Glacier2/router:ssl -p 10011 -t 10000"); Ice::ObjectPrx prx9 = communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000"); Ice::ObjectPrx prx10 = communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000"); map<string, int> proxyMap; proxyMap["prx1"] = prx1->__hash(); proxyMap["prx2"] = prx2->__hash(); proxyMap["prx3"] = prx3->__hash(); proxyMap["prx4"] = prx4->__hash(); proxyMap["prx5"] = prx5->__hash(); proxyMap["prx6"] = prx6->__hash(); proxyMap["prx7"] = prx7->__hash(); proxyMap["prx8"] = prx8->__hash(); proxyMap["prx9"] = prx9->__hash(); proxyMap["prx10"] = prx10->__hash(); test( communicator->stringToProxy("Glacier2/router:tcp -p 10010")->__hash() == proxyMap["prx1"]); test( communicator->stringToProxy("Glacier2/router:ssl -p 10011")->__hash() == proxyMap["prx2"]); test( communicator->stringToProxy("Glacier2/router:udp -p 10012")->__hash() == proxyMap["prx3"]); test( communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010")->__hash() == proxyMap["prx4"]); test( communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011")->__hash() == proxyMap["prx5"]); test( communicator->stringToProxy("Glacier2/router:udp -h zeroc.com -p 10012")->__hash() == proxyMap["prx6"]); test( communicator->stringToProxy("Glacier2/router:tcp -p 10010 -t 10000")->__hash() == proxyMap["prx7"]); test( communicator->stringToProxy("Glacier2/router:ssl -p 10011 -t 10000")->__hash() == proxyMap["prx8"]); test( communicator->stringToProxy("Glacier2/router:tcp -h zeroc.com -p 10010 -t 10000")->__hash() == proxyMap["prx9"]); test( communicator->stringToProxy("Glacier2/router:ssl -h zeroc.com -p 10011 -t 10000")->__hash() == proxyMap["prx10"]); cerr << "ok" << endl; if(communicator) { try { communicator->destroy(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; } } return EXIT_SUCCESS; }