RouterInfoPtr IceInternal::RouterManager::erase(const RouterPrx& rtr) { RouterInfoPtr info; if(rtr) { RouterPrx router = RouterPrx::uncheckedCast(rtr->ice_router(0)); // The router cannot be routed. IceUtil::Mutex::Lock sync(*this); map<RouterPrx, RouterInfoPtr>::iterator p = _table.end(); if(_tableHint != _table.end() && _tableHint->first == router) { p = _tableHint; _tableHint = _table.end(); } if(p == _table.end()) { p = _table.find(router); } if(p != _table.end()) { info = p->second; _table.erase(p); } } return info; }
RouterInfoPtr IceInternal::RouterManager::get(const RouterPrx& rtr) { if(!rtr) { return 0; } RouterPrx router = RouterPrx::uncheckedCast(rtr->ice_router(0)); // The router cannot be routed. IceUtil::Mutex::Lock sync(*this); map<RouterPrx, RouterInfoPtr>::iterator p = _table.end(); if(_tableHint != _table.end()) { if(_tableHint->first == router) { p = _tableHint; } } if(p == _table.end()) { p = _table.find(router); } if(p == _table.end()) { _tableHint = _table.insert(_tableHint, pair<const RouterPrx, RouterInfoPtr>(router, new RouterInfo(router))); } else { _tableHint = p; } return _tableHint->second; }
void Ice::ObjectAdapterI::initialize(const RouterPrx& router) { if(_noConfig) { _reference = _instance->referenceFactory()->create("dummy -t", ""); return; } PropertiesPtr properties = _instance->initializationData().properties; StringSeq unknownProps; bool noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if(unknownProps.size() != 0 && properties->getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { Warning out(_instance->initializationData().logger); out << "found unknown properties for object adapter `" << _name << "':"; for(unsigned int i = 0; i < unknownProps.size(); ++i) { out << "\n " << unknownProps[i]; } } try { // // Make sure named adapter has some configuration // if(router == 0 && noProps) { InitializationException ex(__FILE__, __LINE__); ex.reason = "object adapter `" + _name + "' requires configuration"; throw ex; } const_cast<string&>(_id) = properties->getProperty(_name + ".AdapterId"); const_cast<string&>(_replicaGroupId) = properties->getProperty(_name + ".ReplicaGroupId"); // // Setup a reference to be used to get the default proxy options // when creating new proxies. By default, create twoway proxies. // string proxyOptions = properties->getPropertyWithDefault(_name + ".ProxyOptions", "-t"); try { _reference = _instance->referenceFactory()->create("dummy " + proxyOptions, ""); } catch(const ProxyParseException&) { InitializationException ex(__FILE__, __LINE__); ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; throw ex; } int threadPoolSize = properties->getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties->getPropertyAsInt(_name + ".ThreadPool.SizeMax"); bool hasPriority = properties->getProperty(_name + ".ThreadPool.ThreadPriority") != ""; // // Create the per-adapter thread pool, if necessary. This is done before the creation of the incoming // connection factory as the thread pool is needed during creation for the call to incFdsInUse. // if(threadPoolSize > 0 || threadPoolSizeMax > 0 || hasPriority) { _threadPool = new ThreadPool(_instance, _name + ".ThreadPool", 0); } _hasAcmTimeout = properties->getProperty(_name + ".ACM") != ""; if(_hasAcmTimeout) { _acmTimeout = properties->getPropertyAsInt(_name + ".ACM"); _instance->connectionMonitor()->checkIntervalForACM(_acmTimeout); } if(!router) { const_cast<RouterPrx&>(router) = RouterPrx::uncheckedCast( _instance->proxyFactory()->propertyToProxy(_name + ".Router")); } if(router) { _routerInfo = _instance->routerManager()->get(router); if(_routerInfo) { // // Make sure this router is not already registered with another adapter. // if(_routerInfo->getAdapter()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "object adapter with router", _instance->identityToString(router->ice_getIdentity())); } // // Add the router's server proxy endpoints to this object // adapter. // vector<EndpointIPtr> endpoints = _routerInfo->getServerEndpoints(); copy(endpoints.begin(), endpoints.end(), back_inserter(_routerEndpoints)); sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted. _routerEndpoints.erase(unique(_routerEndpoints.begin(), _routerEndpoints.end()), _routerEndpoints.end()); // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo->setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // _instance->outgoingConnectionFactory()->setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. // The connection factory might change it, for example, to // fill in the real port number. // vector<EndpointIPtr> endpoints = parseEndpoints(properties->getProperty(_name + ".Endpoints"), true); for(vector<EndpointIPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) { IncomingConnectionFactoryPtr factory = new IncomingConnectionFactory(_instance, *p, this); factory->initialize(_name); _incomingConnectionFactories.push_back(factory); } if(endpoints.empty()) { TraceLevelsPtr tl = _instance->traceLevels(); if(tl->network >= 2) { Trace out(_instance->initializationData().logger, tl->networkCat); out << "created adapter `" << _name << "' without endpoints"; } } // // Parse the published endpoints. // _publishedEndpoints = parsePublishedEndpoints(); } if(!properties->getProperty(_name + ".Locator").empty()) { setLocator(LocatorPrx::uncheckedCast(_instance->proxyFactory()->propertyToProxy(_name + ".Locator"))); } else { setLocator(_instance->referenceFactory()->getDefaultLocator()); } } catch(...) { destroy(); throw; } }
Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const CommunicatorPtr& communicator, const ObjectAdapterFactoryPtr& objectAdapterFactory, const string& name, const string& endpointInfo, const RouterPrx& router, bool noConfig) : _deactivated(false), _instance(instance), _communicator(communicator), _objectAdapterFactory(objectAdapterFactory), _servantManager(new ServantManager(instance, name)), _activateOneOffDone(false), _name(name), _directCount(0), _waitForActivate(false), _destroying(false), _destroyed(false), _noConfig(noConfig), _threadPerConnection(false), _threadPerConnectionStackSize(0) { if(_noConfig) { return; } PropertiesPtr properties = instance->initializationData().properties; StringSeq unknownProps; bool noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if(unknownProps.size() != 0 && properties->getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { Warning out(_instance->initializationData().logger); out << "found unknown properties for object adapter '" << _name << "':"; for(unsigned int i = 0; i < unknownProps.size(); ++i) { out << "\n " << unknownProps[i]; } } // // Make sure named adapter has some configuration // if(endpointInfo.empty() && router == 0 && noProps) { InitializationException ex(__FILE__, __LINE__); ex.reason = "object adapter \"" + _name + "\" requires configuration."; throw ex; } const_cast<string&>(_id) = properties->getProperty(_name + ".AdapterId"); const_cast<string&>(_replicaGroupId) = properties->getProperty(_name + ".ReplicaGroupId"); __setNoDelete(true); try { _threadPerConnection = properties->getPropertyAsInt(_name + ".ThreadPerConnection") > 0; int threadPoolSize = properties->getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties->getPropertyAsInt(_name + ".ThreadPool.SizeMax"); if(_threadPerConnection && (threadPoolSize > 0 || threadPoolSizeMax > 0)) { InitializationException ex(__FILE__, __LINE__); ex.reason = "object adapter \"" + _name + "\" cannot be configured for both\n" "thread pool and thread per connection"; throw ex; } if(!_threadPerConnection && threadPoolSize == 0 && threadPoolSizeMax == 0) { _threadPerConnection = _instance->threadPerConnection(); } if(_threadPerConnection) { int stackSize = properties->getPropertyAsIntWithDefault(_name + ".ThreadPerConnection.StackSize", static_cast<Int>(_instance->threadPerConnectionStackSize())); if(stackSize < 0) { stackSize = 0; } _threadPerConnectionStackSize = stackSize; } // // Create the per-adapter thread pool, if necessary. This is done before the creation of the incoming // connection factory as the thread pool is needed during creation for the call to incFdsInUse. // if(threadPoolSize > 0 || threadPoolSizeMax > 0) { _threadPool = new ThreadPool(_instance, _name + ".ThreadPool", 0); } if(!router) { const_cast<RouterPrx&>(router) = RouterPrx::uncheckedCast( _instance->proxyFactory()->propertyToProxy(_name + ".Router")); } if(router) { _routerInfo = _instance->routerManager()->get(router); if(_routerInfo) { // // Make sure this router is not already registered with another adapter. // if(_routerInfo->getAdapter()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "object adapter with router", _instance->identityToString(router->ice_getIdentity())); } // // Add the router's server proxy endpoints to this object // adapter. // vector<EndpointIPtr> endpoints = _routerInfo->getServerEndpoints(); copy(endpoints.begin(), endpoints.end(), back_inserter(_routerEndpoints)); sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted. _routerEndpoints.erase(unique(_routerEndpoints.begin(), _routerEndpoints.end()), _routerEndpoints.end()); // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo->setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // _instance->outgoingConnectionFactory()->setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. // The connection factory might change it, for example, to // fill in the real port number. // vector<EndpointIPtr> endpoints; if(endpointInfo.empty()) { endpoints = parseEndpoints(properties->getProperty(_name + ".Endpoints")); } else { endpoints = parseEndpoints(endpointInfo); } for(vector<EndpointIPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) { _incomingConnectionFactories.push_back(new IncomingConnectionFactory(instance, *p, this, _name)); } if(endpoints.empty()) { TraceLevelsPtr tl = _instance->traceLevels(); if(tl->network >= 2) { Trace out(_instance->initializationData().logger, tl->networkCat); out << "created adapter `" << name << "' without endpoints"; } } // // Parse published endpoints. If set, these are used in proxies // instead of the connection factory endpoints. // string endpts = properties->getProperty(_name + ".PublishedEndpoints"); _publishedEndpoints = parseEndpoints(endpts); if(_publishedEndpoints.empty()) { transform(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), back_inserter(_publishedEndpoints), Ice::constMemFun(&IncomingConnectionFactory::endpoint)); } // // Filter out any endpoints that are not meant to be published. // _publishedEndpoints.erase(remove_if(_publishedEndpoints.begin(), _publishedEndpoints.end(), not1(Ice::constMemFun(&EndpointI::publish))), _publishedEndpoints.end()); } if(!properties->getProperty(_name + ".Locator").empty()) { setLocator(LocatorPrx::uncheckedCast(_instance->proxyFactory()->propertyToProxy(_name + ".Locator"))); } else { setLocator(_instance->referenceFactory()->getDefaultLocator()); } } catch(...) { destroy(); __setNoDelete(false); throw; } __setNoDelete(false); }
Ice::ObjectAdapter::ObjectAdapter(const InstancePtr& instance, const CommunicatorPtr& communicator, const ObjectAdapterFactoryPtr& objectAdapterFactory, const string& name, const string& endpointInfo, #ifdef ICEE_HAS_ROUTER const RouterPrx& router, #endif bool noConfig) : _deactivated(false), _instance(instance), _communicator(communicator), _objectAdapterFactory(objectAdapterFactory), _servantManager(new ServantManager(instance, name)), _activateOneOffDone(false), _name(name), #ifdef ICEE_HAS_LOCATOR _id(instance->initializationData().properties->getProperty(name + ".AdapterId")), _replicaGroupId(instance->initializationData().properties->getProperty(name + ".ReplicaGroupId")), #endif _waitForActivate(false), _destroying(false), _destroyed(false), _noConfig(noConfig) { if(_noConfig) { _reference = _instance->referenceFactory()->create("dummy -t", ""); return; } PropertiesPtr properties = instance->initializationData().properties; // // Setup a reference to be used to get the default proxy options // when creating new proxies. By default, create twoway proxies. // string proxyOptions = properties->getPropertyWithDefault(_name + ".ProxyOptions", "-t"); try { _reference = _instance->referenceFactory()->create("dummy " + proxyOptions, ""); } catch(const ProxyParseException&) { InitializationException ex(__FILE__, __LINE__); ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; throw ex; } __setNoDelete(true); try { #ifdef ICEE_HAS_ROUTER if(!router) { string routerStr = _instance->initializationData().properties->getProperty(_name + ".Router"); if(!routerStr.empty()) { const_cast<RouterPrx&>(router) = RouterPrx::uncheckedCast(_instance->proxyFactory()->stringToProxy(routerStr)); } } if(router) { _routerInfo = _instance->routerManager()->get(router); if(_routerInfo) { // // Make sure this router is not already registered with another adapter. // if(_routerInfo->getAdapter()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "object adapter with router", _instance->identityToString(router->ice_getIdentity())); } // // Add the router's server proxy endpoints to this object // adapter. // vector<EndpointPtr> endpoints = _routerInfo->getServerEndpoints(); copy(endpoints.begin(), endpoints.end(), back_inserter(_routerEndpoints)); sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted. _routerEndpoints.erase(unique(_routerEndpoints.begin(), _routerEndpoints.end()), _routerEndpoints.end()); // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo->setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // _instance->outgoingConnectionFactory()->setRouterInfo(_routerInfo); } } else #endif { // // Parse the endpoints, but don't store them in the adapter. // The connection factory might change it, for example, to // fill in the real port number. // vector<EndpointPtr> endpoints; if(endpointInfo.empty()) { endpoints = parseEndpoints(_instance->initializationData().properties->getProperty(_name + ".Endpoints"), true); } else { endpoints = parseEndpoints(endpointInfo, true); } for(vector<EndpointPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) { _incomingConnectionFactories.push_back(new IncomingConnectionFactory(_instance, *p, this)); } if(endpoints.empty()) { TraceLevelsPtr tl = _instance->traceLevels(); if(tl->network >= 2) { Trace out(_instance->initializationData().logger, tl->networkCat); out << "created adapter `" << name << "' without endpoints"; } } // // Parse published endpoints. // _publishedEndpoints = parsePublishedEndpoints(); } #ifdef ICEE_HAS_LOCATOR string locator = _instance->initializationData().properties->getProperty(_name + ".Locator"); if(!locator.empty()) { setLocator(LocatorPrx::uncheckedCast(_instance->proxyFactory()->stringToProxy(locator))); } else { setLocator(_instance->referenceFactory()->getDefaultLocator()); } #endif } catch(...) { // // There's no need to remove the adapter from the factory if // creation fails. Furthermore, since this code is called with // the factory mutex locked, we can't call removeObjectAdapter // on the factory here so we clear the factory reference to // ensure it won't be called by destroy(). // _objectAdapterFactory = 0; destroy(); __setNoDelete(false); throw; } __setNoDelete(false); }