diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-01-20 11:04:02 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-01-20 11:04:02 +0000 |
commit | 46bc9a1b8b086902e99eb5ae3d281dd2c6cd43ae (patch) | |
tree | 64b38c0ff3cf9496a49462cb56cc98464cab6be1 /cpp/src | |
parent | :changeLocator() (diff) | |
download | ice-46bc9a1b8b086902e99eb5ae3d281dd2c6cd43ae.tar.bz2 ice-46bc9a1b8b086902e99eb5ae3d281dd2c6cd43ae.tar.xz ice-46bc9a1b8b086902e99eb5ae3d281dd2c6cd43ae.zip |
Improved IcePack reliability.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IcePack/AdapterRegistryI.cpp | 30 | ||||
-rw-r--r-- | cpp/src/IcePack/AdapterRegistryI.h | 7 | ||||
-rw-r--r-- | cpp/src/IcePack/AdminI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/ApplicationRegistryI.cpp | 22 | ||||
-rw-r--r-- | cpp/src/IcePack/ApplicationRegistryI.h | 5 | ||||
-rw-r--r-- | cpp/src/IcePack/IcePackNode.cpp | 35 | ||||
-rw-r--r-- | cpp/src/IcePack/IcePackRegistry.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IcePack/Internal.ice | 9 | ||||
-rw-r--r-- | cpp/src/IcePack/LocatorI.cpp | 63 | ||||
-rw-r--r-- | cpp/src/IcePack/LocatorI.h | 8 | ||||
-rw-r--r-- | cpp/src/IcePack/LocatorRegistryI.cpp | 157 | ||||
-rw-r--r-- | cpp/src/IcePack/LocatorRegistryI.h | 12 | ||||
-rw-r--r-- | cpp/src/IcePack/NodeRegistryI.cpp | 78 | ||||
-rw-r--r-- | cpp/src/IcePack/NodeRegistryI.h | 7 | ||||
-rw-r--r-- | cpp/src/IcePack/ObjectRegistryI.cpp | 31 | ||||
-rw-r--r-- | cpp/src/IcePack/ObjectRegistryI.h | 12 | ||||
-rw-r--r-- | cpp/src/IcePack/Registry.cpp | 266 | ||||
-rw-r--r-- | cpp/src/IcePack/Registry.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/ServerRegistryI.cpp | 28 | ||||
-rw-r--r-- | cpp/src/IcePack/ServerRegistryI.h | 8 |
20 files changed, 445 insertions, 341 deletions
diff --git a/cpp/src/IcePack/AdapterRegistryI.cpp b/cpp/src/IcePack/AdapterRegistryI.cpp index 158c639a481..7e6fbaf0c0e 100644 --- a/cpp/src/IcePack/AdapterRegistryI.cpp +++ b/cpp/src/IcePack/AdapterRegistryI.cpp @@ -14,15 +14,15 @@ using namespace std; using namespace IcePack; -IcePack::AdapterRegistryI::AdapterRegistryI(const Ice::CommunicatorPtr& communicator, - const string& envName, const string& dbName, +const string AdapterRegistryI::_dbName = "adapterregistry"; + +IcePack::AdapterRegistryI::AdapterRegistryI(const Ice::CommunicatorPtr& communicator, const string& envName, const TraceLevelsPtr& traceLevels) : _connectionCache(Freeze::createConnection(communicator, envName)), - _dictCache(_connectionCache, dbName), + _dictCache(_connectionCache, _dbName), _traceLevels(traceLevels), _envName(envName), - _communicator(communicator), - _dbName(dbName) + _communicator(communicator) { } @@ -84,7 +84,7 @@ IcePack::AdapterRegistryI::add(const string& id, const AdapterPrx& adapter, cons } AdapterPrx -IcePack::AdapterRegistryI::remove(const string& id, const Ice::Current&) +IcePack::AdapterRegistryI::remove(const string& id, const AdapterPrx& orig, const Ice::Current&) { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxyDict dict(connection, _dbName); @@ -96,6 +96,10 @@ IcePack::AdapterRegistryI::remove(const string& id, const Ice::Current&) } AdapterPrx adapter = AdapterPrx::uncheckedCast(p->second); + if(orig != 0 && orig != adapter) // Only remove if the adapter is equal to the provided proxy (if not null) + { + return 0; + } dict.erase(p); if(_traceLevels->adapterRegistry > 0) @@ -116,19 +120,7 @@ IcePack::AdapterRegistryI::findById(const string& id, const Ice::Current&) StringObjectProxyDict::iterator p = dict.find(id); if(p != dict.end()) { - try - { - p->second->ice_ping(); - return AdapterPrx::uncheckedCast(p->second->ice_collocationOptimization(false)); - } - catch(const Ice::ObjectNotExistException&) - { - dict.erase(p); - } - catch(const Ice::LocalException&) - { - return AdapterPrx::uncheckedCast(p->second->ice_collocationOptimization(false)); - } + return AdapterPrx::uncheckedCast(p->second->ice_collocationOptimization(false)); } throw AdapterNotExistException(); } diff --git a/cpp/src/IcePack/AdapterRegistryI.h b/cpp/src/IcePack/AdapterRegistryI.h index 81700c3571b..eadf3983d1a 100644 --- a/cpp/src/IcePack/AdapterRegistryI.h +++ b/cpp/src/IcePack/AdapterRegistryI.h @@ -23,22 +23,23 @@ class AdapterRegistryI : public AdapterRegistry { public: - AdapterRegistryI(const Ice::CommunicatorPtr&, const std::string&, const std::string&, const TraceLevelsPtr&); + AdapterRegistryI(const Ice::CommunicatorPtr&, const std::string&, const TraceLevelsPtr&); virtual void add(const std::string&, const AdapterPrx&, const ::Ice::Current&); - virtual AdapterPrx remove(const std::string&, const ::Ice::Current&); + virtual AdapterPrx remove(const std::string&, const AdapterPrx&, const ::Ice::Current&); virtual AdapterPrx findById(const ::std::string&, const ::Ice::Current&); virtual Ice::StringSeq getAll(const ::Ice::Current&) const; private: + static const std::string _dbName; + Freeze::ConnectionPtr _connectionCache; StringObjectProxyDict _dictCache; TraceLevelsPtr _traceLevels; const std::string _envName; const Ice::CommunicatorPtr _communicator; - const std::string _dbName; }; diff --git a/cpp/src/IcePack/AdminI.cpp b/cpp/src/IcePack/AdminI.cpp index 1c2eed86c8a..fa57199fd67 100644 --- a/cpp/src/IcePack/AdminI.cpp +++ b/cpp/src/IcePack/AdminI.cpp @@ -970,7 +970,7 @@ ServerCleaner::visitAdapterStart(const AdapterWrapper&, const AdapterDescriptor& AdapterPrx adpt; try { - adpt = _adapterRegistry->remove(adapter.id); + adpt = _adapterRegistry->remove(adapter.id, 0); adpt->destroy(); } catch(const AdapterNotExistException&) diff --git a/cpp/src/IcePack/ApplicationRegistryI.cpp b/cpp/src/IcePack/ApplicationRegistryI.cpp index 3a7fa001038..98c6e44c5ed 100644 --- a/cpp/src/IcePack/ApplicationRegistryI.cpp +++ b/cpp/src/IcePack/ApplicationRegistryI.cpp @@ -14,23 +14,23 @@ using namespace std; using namespace IcePack; -IcePack::ApplicationRegistryI::ApplicationRegistryI(const Ice::CommunicatorPtr& communicator, - const ServerRegistryPtr& serverRegistry, - const string& envName, - const string& dbName, - const TraceLevelsPtr& traceLevels) : +const string ApplicationRegistryI::_dbName = "applicationregistry"; + +ApplicationRegistryI::ApplicationRegistryI(const Ice::CommunicatorPtr& communicator, + const ServerRegistryPtr& serverRegistry, + const string& envName, + const TraceLevelsPtr& traceLevels) : _serverRegistry(serverRegistry), _connectionCache(Freeze::createConnection(communicator, envName)), - _dictCache(_connectionCache, dbName), + _dictCache(_connectionCache, _dbName), _traceLevels(traceLevels), _envName(envName), - _communicator(communicator), - _dbName(dbName) + _communicator(communicator) { } void -IcePack::ApplicationRegistryI::add(const string& name, const Ice::Current&) +ApplicationRegistryI::add(const string& name, const Ice::Current&) { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringStringSeqDict dict(connection, _dbName); @@ -51,7 +51,7 @@ IcePack::ApplicationRegistryI::add(const string& name, const Ice::Current&) } void -IcePack::ApplicationRegistryI::remove(const string& name, const Ice::Current&) +ApplicationRegistryI::remove(const string& name, const Ice::Current&) { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringStringSeqDict dict(connection, _dbName); @@ -140,7 +140,7 @@ ApplicationRegistryI::getDescriptor(const string& name, const Ice::Current&) } Ice::StringSeq -IcePack::ApplicationRegistryI::getAll(const Ice::Current&) const +ApplicationRegistryI::getAll(const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringStringSeqDict dict(connection, _dbName); diff --git a/cpp/src/IcePack/ApplicationRegistryI.h b/cpp/src/IcePack/ApplicationRegistryI.h index 9735646c05c..2d3bad3cd88 100644 --- a/cpp/src/IcePack/ApplicationRegistryI.h +++ b/cpp/src/IcePack/ApplicationRegistryI.h @@ -23,7 +23,7 @@ class ApplicationRegistryI : public ApplicationRegistry { public: - ApplicationRegistryI(const Ice::CommunicatorPtr&, const ServerRegistryPtr&, const std::string&, const std::string&, + ApplicationRegistryI(const Ice::CommunicatorPtr&, const ServerRegistryPtr&, const std::string&, const TraceLevelsPtr&); virtual void add(const std::string&, const ::Ice::Current&); @@ -36,6 +36,8 @@ public: virtual Ice::StringSeq getAll(const ::Ice::Current&) const; private: + + static const std::string _dbName; ServerRegistryPtr _serverRegistry; Freeze::ConnectionPtr _connectionCache; @@ -43,7 +45,6 @@ private: TraceLevelsPtr _traceLevels; const std::string _envName; const Ice::CommunicatorPtr _communicator; - const std::string _dbName; }; } diff --git a/cpp/src/IcePack/IcePackNode.cpp b/cpp/src/IcePack/IcePackNode.cpp index f74367a2766..3ab27eb2eb5 100644 --- a/cpp/src/IcePack/IcePackNode.cpp +++ b/cpp/src/IcePack/IcePackNode.cpp @@ -178,7 +178,6 @@ IcePack::NodeService::start(int argc, char* argv[]) // termination listener instead? // properties->setProperty("Ice.ServerIdleTime", "0"); - if(properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 5) <= 5) { properties->setProperty("Ice.ThreadPool.Server.Size", "5"); @@ -190,8 +189,7 @@ IcePack::NodeService::start(int argc, char* argv[]) if(properties->getPropertyAsInt("IcePack.Node.CollocateRegistry") > 0) { // - // The node needs a different thread pool to avoid - // deadlocks in connection validation. + // The node needs a different thread pool. // if(properties->getPropertyAsInt("IcePack.Node.ThreadPool.Size") == 0) { @@ -207,7 +205,7 @@ IcePack::NodeService::start(int argc, char* argv[]) } _registry = auto_ptr<Registry>(new Registry(communicator())); - if(!_registry->start(nowarn, true)) + if(!_registry->start(nowarn)) { return false; } @@ -321,11 +319,9 @@ IcePack::NodeService::start(int argc, char* argv[]) } // - // Set the adapter id for this node and create the node object - // adapter. + // Set the adapter id for this node and create the node object adapter. // properties->setProperty("IcePack.Node.AdapterId", "IcePack.Node." + name); - ObjectAdapterPtr adapter = communicator()->createObjectAdapter("IcePack.Node"); TraceLevelsPtr traceLevels = new TraceLevels(properties, communicator()->getLogger()); @@ -347,25 +343,25 @@ IcePack::NodeService::start(int argc, char* argv[]) // evictors and object factories necessary to store these objects. // ServerFactoryPtr serverFactory = new ServerFactory(adapter, traceLevels, envName, _activator, _waitQueue); - NodePtr node = new NodeI(_activator, name, serverFactory, communicator(), properties); - NodePrx nodeProxy = NodePrx::uncheckedCast(adapter->addWithUUID(node)); + Identity id = stringToIdentity(IceUtil::generateUUID()); + adapter->add(node, id); + NodePrx nodeProxy = NodePrx::uncheckedCast(adapter->createDirectProxy(id)); // // Register this node with the node registry. // try { - NodeRegistryPrx nodeRegistry = NodeRegistryPrx::checkedCast( - communicator()->stringToProxy("IcePack/NodeRegistry@IcePack.Registry.Internal")); - nodeRegistry->add(name, nodeProxy); + ObjectPrx nodeRegistry = communicator()->stringToProxy("IcePack/NodeRegistry@IcePack.Registry.Internal"); + NodeRegistryPrx::uncheckedCast(nodeRegistry)->add(name, nodeProxy); } catch(const NodeActiveException&) { error("a node with the same name is already registered and active"); return false; } - catch(const LocalException&) + catch(const LocalException& ex) { error("couldn't contact the IcePack registry"); return false; @@ -385,9 +381,14 @@ IcePack::NodeService::start(int argc, char* argv[]) _activator->start(); // - // We are ready to go! Activate the object adapter. + // We are ready to go! Activate the object adapter. NOTE: we don't want the activate call to + // set the direct proxy of the object adapter with the locator registry. This was already + // taken care of by the node registry. Furthermore, this wouldn't work anyway because the + // locator registry proxy would have collocation optimization enabled. // + adapter->setLocator(0); adapter->activate(); + adapter->setLocator(communicator()->getDefaultLocator()); // // Deploy application if a descriptor is passed as a command-line option. @@ -418,15 +419,13 @@ IcePack::NodeService::start(int argc, char* argv[]) catch(const DeploymentException& ex) { ostringstream ostr; - ostr << "failed to deploy application `" << descriptor << "':" << endl - << ex << ": " << ex.reason; + ostr << "failed to deploy application `" << descriptor << "':" << endl << ex << ": " << ex.reason; warning(ostr.str()); } catch(const LocalException& ex) { ostringstream ostr; - ostr << "failed to deploy application `" << descriptor << "':" << endl - << ex; + ostr << "failed to deploy application `" << descriptor << "':" << endl << ex; warning(ostr.str()); } } diff --git a/cpp/src/IcePack/IcePackRegistry.cpp b/cpp/src/IcePack/IcePackRegistry.cpp index 35e40773a85..1e51177588e 100644 --- a/cpp/src/IcePack/IcePackRegistry.cpp +++ b/cpp/src/IcePack/IcePackRegistry.cpp @@ -84,9 +84,9 @@ IcePack::RegistryService::start(int argc, char* argv[]) } _registry = auto_ptr<Registry>(new Registry(communicator())); - if(!_registry->start(nowarn, false)) + if(!_registry->start(nowarn)) { - return false; + return false; } return true; diff --git a/cpp/src/IcePack/Internal.ice b/cpp/src/IcePack/Internal.ice index efebc5a082f..4bdb541316d 100644 --- a/cpp/src/IcePack/Internal.ice +++ b/cpp/src/IcePack/Internal.ice @@ -112,7 +112,7 @@ interface Adapter * active adapter. * **/ - void setDirectProxy(Object* proxy) + ["ami"] void setDirectProxy(Object* proxy) throws AdapterActiveException; /** @@ -150,10 +150,11 @@ interface AdapterRegistry /** * - * Remove an adapter from the registry. + * Remove an adapter from the registry. If the given adapter proxy is not null, the adapter will + * be removed from the registry only if the proxy matches. * **/ - Adapter* remove(string id) + Adapter* remove(string id, Adapter* adpt) throws AdapterNotExistException; /** @@ -333,7 +334,7 @@ class Server * Set the process proxy. * **/ - void setProcess(Ice::Process* proc); + ["ami"] void setProcess(Ice::Process* proc); /** * diff --git a/cpp/src/IcePack/LocatorI.cpp b/cpp/src/IcePack/LocatorI.cpp index 56f2cb1c4e6..882c9c2c27c 100644 --- a/cpp/src/IcePack/LocatorI.cpp +++ b/cpp/src/IcePack/LocatorI.cpp @@ -17,14 +17,17 @@ namespace IcePack { // -// Callback from asynchronous call to adapter->getDirectProxy() -// invoked in LocatorI::findAdapterById_async(). +// Callback from asynchronous call to adapter->getDirectProxy() invoked in LocatorI::findAdapterById_async(). // class AMI_Adapter_getDirectProxyI : public AMI_Adapter_getDirectProxy { public: - AMI_Adapter_getDirectProxyI(const Ice::AMD_Locator_findAdapterByIdPtr& cb) : _cb(cb) + AMI_Adapter_getDirectProxyI(const Ice::AMD_Locator_findAdapterByIdPtr& cb, + const AdapterRegistryPtr& registry, + const string& id, + const AdapterPrx& adapter) : + _cb(cb), _adapterRegistry(registry), _id(id), _adapter(adapter) { } @@ -45,18 +48,25 @@ public: catch(const Ice::ObjectNotExistException&) { // - // Expected if the adapter is destroyed. + // Expected if the adapter is destroyed, if that's the case, we remove it from the adapter + // registry. // + try + { + _adapterRegistry->remove(_id, _adapter); + } + catch(const AdapterNotExistException&) + { + } _cb->ice_exception(Ice::AdapterNotFoundException()); return; } catch(const Ice::LocalException&) { // - // Expected if we couldn't contact the adapter object - // (possibly because the IcePack node is down). Return a - // null proxy in this case (the client will get empty - // endpoints and throw a NoEndpointException). + // Expected if we couldn't contact the adapter object (possibly because the IcePack node is + // down). Return a null proxy in this case (the client will get empty endpoints and throw a + // NoEndpointException). // _cb->ice_response(0); return; @@ -75,12 +85,14 @@ public: private: - Ice::AMD_Locator_findAdapterByIdPtr _cb; + const Ice::AMD_Locator_findAdapterByIdPtr _cb; + const AdapterRegistryPtr& _adapterRegistry; + const string _id; + const AdapterPrx _adapter; }; // -// Callback from asynchrnous call to LocatorI::findAdapterById_async() -// invoked in LocatorI::findObjectById_async(). +// Callback from asynchrnous call to LocatorI::findAdapterById_async() invoked in LocatorI::findObjectById_async(). // class AMD_Locator_findAdapterByIdI : public Ice::AMD_Locator_findAdapterById { @@ -151,9 +163,8 @@ public: private: - Ice::AMD_Locator_findObjectByIdPtr _cb; - Ice::ObjectPrx _obj; - + const Ice::AMD_Locator_findObjectByIdPtr _cb; + const Ice::ObjectPrx _obj; }; } @@ -172,7 +183,8 @@ IcePack::LocatorI::LocatorI(const AdapterRegistryPtr& adapterRegistry, // registry. // void -IcePack::LocatorI::findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr& response, const Ice::Identity& id, +IcePack::LocatorI::findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr& cb, + const Ice::Identity& id, const Ice::Current& current) const { ObjectDescriptor obj; @@ -186,19 +198,18 @@ IcePack::LocatorI::findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr } // - // OPTIMIZATION: If the object is registered with an adapter id, - // try to get the adapter direct proxy (which might caused the - // server activation). This will avoid the client to lookup for + // OPTIMIZATION: If the object is registered with an adapter id, try to get the adapter direct + // proxy (which might caused the server activation). This will avoid the client to lookup for // the adapter id endpoints. // if(!obj.adapterId.empty()) { - Ice::AMD_Locator_findAdapterByIdPtr cb = new AMD_Locator_findAdapterByIdI(response, obj.proxy); - findAdapterById_async(cb, obj.adapterId, current); + Ice::AMD_Locator_findAdapterByIdPtr amiCB = new AMD_Locator_findAdapterByIdI(cb, obj.proxy); + findAdapterById_async(amiCB, obj.adapterId, current); } else { - response->ice_response(obj.proxy); + cb->ice_response(obj.proxy); } } @@ -207,13 +218,15 @@ IcePack::LocatorI::findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr // registry. If found, we try to get its direct proxy. // void -IcePack::LocatorI::findAdapterById_async(const Ice::AMD_Locator_findAdapterByIdPtr& response, - const string& id, const Ice::Current&) const +IcePack::LocatorI::findAdapterById_async(const Ice::AMD_Locator_findAdapterByIdPtr& cb, + const string& id, + const Ice::Current&) const { try { - AMI_Adapter_getDirectProxyPtr cb = new AMI_Adapter_getDirectProxyI(response); - _adapterRegistry->findById(id)->getDirectProxy_async(cb, true); + AdapterPrx adapter = AdapterPrx::uncheckedCast(_adapterRegistry->findById(id)); + AMI_Adapter_getDirectProxyPtr amiCB = new AMI_Adapter_getDirectProxyI(cb, _adapterRegistry, id, adapter); + adapter->getDirectProxy_async(amiCB, true); } catch(const AdapterNotExistException&) { diff --git a/cpp/src/IcePack/LocatorI.h b/cpp/src/IcePack/LocatorI.h index ab5ecd65123..08d18fd083b 100644 --- a/cpp/src/IcePack/LocatorI.h +++ b/cpp/src/IcePack/LocatorI.h @@ -16,7 +16,7 @@ namespace IcePack { -class LocatorI : public ::Ice::Locator +class LocatorI : public Ice::Locator { public: @@ -32,9 +32,9 @@ public: private: - AdapterRegistryPtr _adapterRegistry; - ObjectRegistryPtr _objectRegistry; - Ice::LocatorRegistryPrx _locatorRegistry; + const AdapterRegistryPtr _adapterRegistry; + const ObjectRegistryPtr _objectRegistry; + const Ice::LocatorRegistryPrx _locatorRegistry; }; } diff --git a/cpp/src/IcePack/LocatorRegistryI.cpp b/cpp/src/IcePack/LocatorRegistryI.cpp index f28e45f4557..fe2b1a9d94d 100644 --- a/cpp/src/IcePack/LocatorRegistryI.cpp +++ b/cpp/src/IcePack/LocatorRegistryI.cpp @@ -14,6 +14,87 @@ using namespace std; using namespace IcePack; +class AMI_Adapter_setDirectProxyI : public AMI_Adapter_setDirectProxy +{ +public: + + AMI_Adapter_setDirectProxyI(const Ice::AMD_LocatorRegistry_setAdapterDirectProxyPtr& cb) : _cb(cb) + { + } + + virtual void ice_response() + { + _cb->ice_response(); + } + + virtual void ice_exception(const ::Ice::Exception& ex) + { + try + { + ex.ice_throw(); + } + catch(const AdapterActiveException&) + { + _cb->ice_exception(Ice::AdapterAlreadyActiveException()); + return; + } + catch(const Ice::ObjectNotExistException&) + { + _cb->ice_exception(Ice::AdapterNotFoundException()); // Expected if the adapter was destroyed. + return; + } + catch(const Ice::LocalException&) + { + _cb->ice_response(); + return; + } + + assert(false); + } + +private: + + Ice::AMD_LocatorRegistry_setAdapterDirectProxyPtr _cb; +}; + +class AMI_Server_setProcessI : public AMI_Server_setProcess +{ +public: + + AMI_Server_setProcessI(const Ice::AMD_LocatorRegistry_setServerProcessProxyPtr& cb) : _cb(cb) + { + } + + virtual void ice_response() + { + _cb->ice_response(); + } + + virtual void ice_exception(const ::Ice::Exception& ex) + { + try + { + ex.ice_throw(); + } + catch(const Ice::ObjectNotExistException&) + { + _cb->ice_exception(Ice::ServerNotFoundException()); // Expected if the adapter was destroyed. + return; + } + catch(const Ice::LocalException&) + { + _cb->ice_response(); + return; + } + + assert(false); + } + +private: + + Ice::AMD_LocatorRegistry_setServerProcessProxyPtr _cb; +}; + IcePack::LocatorRegistryI::LocatorRegistryI(const AdapterRegistryPtr& adapterRegistry, const ServerRegistryPtr& serverRegistry, const AdapterFactoryPtr& adapterFactory, @@ -26,7 +107,10 @@ IcePack::LocatorRegistryI::LocatorRegistryI(const AdapterRegistryPtr& adapterReg } void -IcePack::LocatorRegistryI::setAdapterDirectProxy(const string& id, const Ice::ObjectPrx& proxy, const Ice::Current&) +IcePack::LocatorRegistryI::setAdapterDirectProxy_async(const Ice::AMD_LocatorRegistry_setAdapterDirectProxyPtr& cb, + const string& id, + const Ice::ObjectPrx& proxy, + const Ice::Current&) { while(true) { @@ -35,56 +119,33 @@ IcePack::LocatorRegistryI::setAdapterDirectProxy(const string& id, const Ice::Ob // // Get the adapter from the registry and set its direct proxy. // - _adapterRegistry->findById(id)->setDirectProxy(proxy); + AMI_Adapter_setDirectProxyPtr amiCB = new AMI_Adapter_setDirectProxyI(cb); + _adapterRegistry->findById(id)->setDirectProxy_async(amiCB, proxy); return; } catch(const AdapterNotExistException&) { } - catch(const AdapterActiveException&) - { - throw Ice::AdapterAlreadyActiveException(); - } - catch(const Ice::ObjectNotExistException&) + catch(const Ice::LocalException& ex) { - // - // Expected if the adapter was destroyed. - // - } - catch(const Ice::LocalException&) - { - // - // TODO: We couldn't contact the adapter object. This - // is possibly because the IcePack node is down and - // the server is started manually for example. We - // should probably throw here to prevent the server - // from starting? - // + cb->ice_response(); return; } - // - // Create a new standalone adapter. The adapter will be - // persistent. It's the responsability of the user to cleanup - // adapter entries which were dynamically added from the - // registry. - // if(_dynamicRegistration) { + // + // Create a new standalone adapter. The adapter will be persistent. It's the responsability of + // the user to cleanup adapter entries which were dynamically added from the registry. + // + AdapterPrx adapter = _adapterFactory->createStandaloneAdapter(id); try { - AdapterPrx adapter = _adapterFactory->createStandaloneAdapter(id); - try - { - _adapterRegistry->add(id, adapter); - } - catch(const AdapterExistsException&) - { - adapter->destroy(); - } + _adapterRegistry->add(id, adapter); } - catch(const Ice::AlreadyRegisteredException&) + catch(const AdapterExistsException&) { + adapter->destroy(); } } else @@ -95,35 +156,33 @@ IcePack::LocatorRegistryI::setAdapterDirectProxy(const string& id, const Ice::Ob } void -IcePack::LocatorRegistryI::setServerProcessProxy(const string& name, const Ice::ProcessPrx& proxy, const Ice::Current&) +IcePack::LocatorRegistryI::setServerProcessProxy_async(const Ice::AMD_LocatorRegistry_setServerProcessProxyPtr& cb, + const string& name, + const Ice::ProcessPrx& proxy, + const Ice::Current&) { try { // // Get the server from the registry and set its process proxy. // - _serverRegistry->findByName(name)->setProcess(proxy); + AMI_Server_setProcessPtr amiCB = new AMI_Server_setProcessI(cb); + _serverRegistry->findByName(name)->setProcess_async(amiCB, proxy); return; } catch(const ServerNotExistException&) { } - catch(const Ice::ObjectNotExistException&) - { - // - // Expected if the server was destroyed. - // - } catch(const Ice::LocalException&) { // - // TODO: We couldn't contact the server object. This - // is possibly because the IcePack node is down and - // the server is started manually for example. We - // should probably throw here to prevent the server + // TODO: We couldn't contact the server object. This is possibly because the IcePack node is down and + // the server is started manually for example. We should probably throw here to prevent the server // from starting? // - return; + cb->ice_response(); + return; } + throw Ice::ServerNotFoundException(); } diff --git a/cpp/src/IcePack/LocatorRegistryI.h b/cpp/src/IcePack/LocatorRegistryI.h index f76a1014ca8..8b619763c18 100644 --- a/cpp/src/IcePack/LocatorRegistryI.h +++ b/cpp/src/IcePack/LocatorRegistryI.h @@ -26,14 +26,16 @@ public: LocatorRegistryI(const AdapterRegistryPtr&, const ServerRegistryPtr&, const AdapterFactoryPtr&, bool); - virtual void setAdapterDirectProxy(const ::std::string&, const ::Ice::ObjectPrx&, const ::Ice::Current&); - virtual void setServerProcessProxy(const ::std::string&, const ::Ice::ProcessPrx&, const ::Ice::Current&); + virtual void setAdapterDirectProxy_async(const Ice::AMD_LocatorRegistry_setAdapterDirectProxyPtr&, + const ::std::string&, const ::Ice::ObjectPrx&, const ::Ice::Current&); + virtual void setServerProcessProxy_async(const Ice::AMD_LocatorRegistry_setServerProcessProxyPtr&, + const ::std::string&, const ::Ice::ProcessPrx&, const ::Ice::Current&); private: - AdapterRegistryPtr _adapterRegistry; - ServerRegistryPtr _serverRegistry; - AdapterFactoryPtr _adapterFactory; + const AdapterRegistryPtr _adapterRegistry; + const ServerRegistryPtr _serverRegistry; + const AdapterFactoryPtr _adapterFactory; const bool _dynamicRegistration; }; diff --git a/cpp/src/IcePack/NodeRegistryI.cpp b/cpp/src/IcePack/NodeRegistryI.cpp index 5d2d5827274..b75fb2290d0 100644 --- a/cpp/src/IcePack/NodeRegistryI.cpp +++ b/cpp/src/IcePack/NodeRegistryI.cpp @@ -15,20 +15,20 @@ using namespace std; using namespace IcePack; -IcePack::NodeRegistryI::NodeRegistryI(const Ice::CommunicatorPtr& communicator, - const string& envName, - const string& dbName, - const AdapterRegistryPtr& adapterRegistry, - const AdapterFactoryPtr& adapterFactory, - const TraceLevelsPtr& traceLevels) : +const string NodeRegistryI::_dbName = "noderegistry"; + +NodeRegistryI::NodeRegistryI(const Ice::CommunicatorPtr& communicator, + const string& envName, + const AdapterRegistryPtr& adapterRegistry, + const AdapterFactoryPtr& adapterFactory, + const TraceLevelsPtr& traceLevels) : _connectionCache(Freeze::createConnection(communicator, envName)), - _dictCache(_connectionCache, dbName), + _dictCache(_connectionCache, _dbName), _adapterRegistry(adapterRegistry), _adapterFactory(adapterFactory), _traceLevels(traceLevels), _envName(envName), - _communicator(communicator), - _dbName(dbName) + _communicator(communicator) { for(StringObjectProxyDict::iterator p = _dictCache.begin(); p != _dictCache.end(); ++p) { @@ -48,7 +48,7 @@ IcePack::NodeRegistryI::NodeRegistryI(const Ice::CommunicatorPtr& communicator, } void -IcePack::NodeRegistryI::add(const string& name, const NodePrx& node, const Ice::Current& current) +NodeRegistryI::add(const string& name, const NodePrx& node, const Ice::Current& current) { while(true) { @@ -101,36 +101,46 @@ IcePack::NodeRegistryI::add(const string& name, const NodePrx& node, const Ice:: break; } - try - { - _adapterRegistry->findById("IcePack.Node." + name); - - // - // TODO: ensure this adapter has been created by the adapter factory. It's possible that an - // adapter has been created with the same name. In such a case, the best is probably to - // prevent the node registration by throwing an appropriate exception. The user would then - // need to remove the adapter from the adapter registry to be able to run the node. - // - } - catch(const AdapterNotExistException&) + AdapterPrx adapter; + while(!adapter) { - // - // Create and register the node adapter. - // - AdapterPrx adapter = _adapterFactory->createStandaloneAdapter("IcePackNodeAdapter." + name); try { - _adapterRegistry->add("IcePack.Node." + name, adapter); - } - catch(const AdapterExistsException&) + adapter = _adapterRegistry->findById("IcePack.Node." + name); + + // + // TODO: ensure this adapter has been created by the adapter factory. It's possible that an + // adapter has been created with the same name. In such a case, the best is probably to + // prevent the node registration by throwing an appropriate exception. The user would then + // need to remove the adapter from the adapter registry to be able to run the node. + // + } + catch(const AdapterNotExistException&) { - adapter->destroy(); + // + // Create and register the node adapter. + // + adapter = _adapterFactory->createStandaloneAdapter("IcePackNodeAdapter." + name); + try + { + _adapterRegistry->add("IcePack.Node." + name, adapter); + } + catch(const AdapterExistsException&) + { + adapter->destroy(); + adapter = 0; + } } } + + // + // Set the direct proxy of the node object adapter. + // + adapter->setDirectProxy(node); } void -IcePack::NodeRegistryI::remove(const string& name, const Ice::Current&) +NodeRegistryI::remove(const string& name, const Ice::Current&) { IceUtil::Mutex::Lock sync(*this); @@ -158,7 +168,7 @@ IcePack::NodeRegistryI::remove(const string& name, const Ice::Current&) { AdapterPrx adapter = _adapterRegistry->findById("IcePack.Node." + name); adapter->destroy(); - _adapterRegistry->remove("IcePack.Node." + name); + _adapterRegistry->remove("IcePack.Node." + name, 0); } catch(const AdapterNotExistException&) { @@ -166,7 +176,7 @@ IcePack::NodeRegistryI::remove(const string& name, const Ice::Current&) } NodePrx -IcePack::NodeRegistryI::findByName(const string& name, const Ice::Current&) +NodeRegistryI::findByName(const string& name, const Ice::Current&) { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxyDict dict(connection, _dbName); @@ -190,7 +200,7 @@ IcePack::NodeRegistryI::findByName(const string& name, const Ice::Current&) } Ice::StringSeq -IcePack::NodeRegistryI::getAll(const Ice::Current&) const +NodeRegistryI::getAll(const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxyDict dict(connection, _dbName); diff --git a/cpp/src/IcePack/NodeRegistryI.h b/cpp/src/IcePack/NodeRegistryI.h index d0271715de2..211d00a43cb 100644 --- a/cpp/src/IcePack/NodeRegistryI.h +++ b/cpp/src/IcePack/NodeRegistryI.h @@ -26,8 +26,8 @@ class NodeRegistryI : public NodeRegistry, public IceUtil::Mutex { public: - NodeRegistryI(const Ice::CommunicatorPtr&, const std::string&, const std::string&, - const AdapterRegistryPtr&, const AdapterFactoryPtr&, const TraceLevelsPtr&); + NodeRegistryI(const Ice::CommunicatorPtr&, const std::string&, const AdapterRegistryPtr&, + const AdapterFactoryPtr&, const TraceLevelsPtr&); virtual void add(const std::string&, const NodePrx&, const ::Ice::Current&); virtual void remove(const std::string&, const ::Ice::Current& = Ice::Current()); @@ -37,6 +37,8 @@ public: private: + static const std::string _dbName; + Freeze::ConnectionPtr _connectionCache; StringObjectProxyDict _dictCache; AdapterRegistryPtr _adapterRegistry; @@ -44,7 +46,6 @@ private: TraceLevelsPtr _traceLevels; const std::string _envName; const Ice::CommunicatorPtr _communicator; - const std::string _dbName; }; } diff --git a/cpp/src/IcePack/ObjectRegistryI.cpp b/cpp/src/IcePack/ObjectRegistryI.cpp index c43cc0c1931..caaba45b346 100644 --- a/cpp/src/IcePack/ObjectRegistryI.cpp +++ b/cpp/src/IcePack/ObjectRegistryI.cpp @@ -14,24 +14,23 @@ using namespace std; using namespace IcePack; -IcePack::ObjectRegistryI::ObjectRegistryI(const Ice::CommunicatorPtr& communicator, - const string& envName, - const string& objectsDbName, - const string& typesDbName, - const TraceLevelsPtr& traceLevels) : +const string ObjectRegistryI::_objectsDbName = "objectregistry"; +const string ObjectRegistryI::_typesDbName = "objectregistry-types"; + +ObjectRegistryI::ObjectRegistryI(const Ice::CommunicatorPtr& communicator, + const string& envName, + const TraceLevelsPtr& traceLevels) : _connectionCache(Freeze::createConnection(communicator, envName)), - _objectsCache(_connectionCache, objectsDbName, true), - _typesCache(_connectionCache, typesDbName, true), + _objectsCache(_connectionCache, _objectsDbName, true), + _typesCache(_connectionCache, _typesDbName, true), _traceLevels(traceLevels), _envName(envName), - _communicator(communicator), - _objectsDbName(objectsDbName), - _typesDbName(typesDbName) + _communicator(communicator) { } void -IcePack::ObjectRegistryI::add(const ObjectDescriptor& obj, const Ice::Current&) +ObjectRegistryI::add(const ObjectDescriptor& obj, const Ice::Current&) { IceUtil::Mutex::Lock sync(*this); @@ -85,7 +84,7 @@ IcePack::ObjectRegistryI::add(const ObjectDescriptor& obj, const Ice::Current&) } void -IcePack::ObjectRegistryI::remove(const Ice::ObjectPrx& object, const Ice::Current&) +ObjectRegistryI::remove(const Ice::ObjectPrx& object, const Ice::Current&) { IceUtil::Mutex::Lock sync(*this); @@ -148,7 +147,7 @@ IcePack::ObjectRegistryI::remove(const Ice::ObjectPrx& object, const Ice::Curren } ObjectDescriptor -IcePack::ObjectRegistryI::getObjectDescriptor(const Ice::Identity& id, const Ice::Current&) const +ObjectRegistryI::getObjectDescriptor(const Ice::Identity& id, const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); IdentityObjectDescDict objects(connection, _objectsDbName); @@ -163,7 +162,7 @@ IcePack::ObjectRegistryI::getObjectDescriptor(const Ice::Identity& id, const Ice } Ice::ObjectPrx -IcePack::ObjectRegistryI::findById(const Ice::Identity& id, const Ice::Current&) const +ObjectRegistryI::findById(const Ice::Identity& id, const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); IdentityObjectDescDict objects(connection, _objectsDbName); @@ -178,7 +177,7 @@ IcePack::ObjectRegistryI::findById(const Ice::Identity& id, const Ice::Current&) } Ice::ObjectPrx -IcePack::ObjectRegistryI::findByType(const string& type, const Ice::Current&) const +ObjectRegistryI::findByType(const string& type, const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxySeqDict types(connection, _typesDbName); @@ -194,7 +193,7 @@ IcePack::ObjectRegistryI::findByType(const string& type, const Ice::Current&) co } Ice::ObjectProxySeq -IcePack::ObjectRegistryI::findAllWithType(const string& type, const Ice::Current&) const +ObjectRegistryI::findAllWithType(const string& type, const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxySeqDict types(connection, _typesDbName); diff --git a/cpp/src/IcePack/ObjectRegistryI.h b/cpp/src/IcePack/ObjectRegistryI.h index a75d455a26b..318ef874ebf 100644 --- a/cpp/src/IcePack/ObjectRegistryI.h +++ b/cpp/src/IcePack/ObjectRegistryI.h @@ -25,11 +25,7 @@ class ObjectRegistryI : public ObjectRegistry, public IceUtil::Mutex { public: - ObjectRegistryI(const Ice::CommunicatorPtr& communicator, - const std::string&, - const std::string&, - const std::string&, - const TraceLevelsPtr& traceLevels); + ObjectRegistryI(const Ice::CommunicatorPtr& communicator, const std::string&, const TraceLevelsPtr& traceLevels); virtual void add(const IcePack::ObjectDescriptor&, const ::Ice::Current&); virtual void remove(const Ice::ObjectPrx&, const ::Ice::Current&); @@ -42,15 +38,15 @@ public: private: + static const std::string _objectsDbName; + static const std::string _typesDbName; + Freeze::ConnectionPtr _connectionCache; IdentityObjectDescDict _objectsCache; StringObjectProxySeqDict _typesCache; const TraceLevelsPtr _traceLevels; const std::string _envName; const Ice::CommunicatorPtr _communicator; - const std::string _objectsDbName; - const std::string _typesDbName; - }; } diff --git a/cpp/src/IcePack/Registry.cpp b/cpp/src/IcePack/Registry.cpp index 4b4bca341d0..3a83ec1a862 100644 --- a/cpp/src/IcePack/Registry.cpp +++ b/cpp/src/IcePack/Registry.cpp @@ -40,6 +40,14 @@ using namespace std; using namespace Ice; using namespace IcePack; +string +intToString(int v) +{ + ostringstream os; + os << v; + return os.str(); +} + IcePack::Registry::Registry(const CommunicatorPtr& communicator) : _communicator(communicator) { @@ -50,7 +58,7 @@ IcePack::Registry::~Registry() } bool -IcePack::Registry::start(bool nowarn, bool requiresInternalEndpoints) +IcePack::Registry::start(bool nowarn) { assert(_communicator); PropertiesPtr properties = _communicator->getProperties(); @@ -93,21 +101,12 @@ IcePack::Registry::start(bool nowarn, bool requiresInternalEndpoints) return false; } - bool hasInternalEndpoints = !properties->getProperty("IcePack.Registry.Internal.Endpoints").empty(); - if(requiresInternalEndpoints && !hasInternalEndpoints) + if(properties->getProperty("IcePack.Registry.Internal.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IcePack.Registry.Internal.Endpoints' is not set"; return false; } - else if(!requiresInternalEndpoints && !hasInternalEndpoints) - { - if(!nowarn) - { - Warning out(_communicator->getLogger()); - out << "internal endpoints `IcePack.Registry.Internal.Endpoints' disabled"; - } - } if(!properties->getProperty("IcePack.Registry.Admin.Endpoints").empty()) { @@ -118,159 +117,192 @@ IcePack::Registry::start(bool nowarn, bool requiresInternalEndpoints) } } - if(properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 5) <= 5) - { - properties->setProperty("Ice.ThreadPool.Server.Size", "5"); - } - - _communicator->setDefaultLocator(0); - properties->setProperty("Ice.PrintProcessId", "0"); properties->setProperty("Ice.Warn.Leaks", "0"); properties->setProperty("Ice.ServerIdleTime", "0"); - - TraceLevelsPtr traceLevels = new TraceLevels(properties, _communicator->getLogger()); + properties->setProperty("IcePack.Registry.Internal.AdapterId", "IcePack.Registry.Internal"); // - // Create the internal registries (node, server, adapter, object). + // Setup thread pool size for each thread pool. // - properties->setProperty("IcePack.Registry.Internal.AdapterId", "IcePack.Registry.Internal"); + int nThreadPool = 0; + if(properties->getPropertyAsInt("IcePack.Registry.Client.ThreadPool.Size") == 0 && + properties->getPropertyAsInt("IcePack.Registry.Client.ThreadPool.SizeMax") == 0) + { + ++nThreadPool; + } + if(properties->getPropertyAsInt("IcePack.Registry.Server.ThreadPool.Size") == 0 && + properties->getPropertyAsInt("IcePack.Registry.Server.ThreadPool.SizeMax") == 0) + { + ++nThreadPool; + } + if(properties->getPropertyAsInt("IcePack.Registry.Admin.ThreadPool.Size") == 0 && + properties->getPropertyAsInt("IcePack.Registry.Admin.ThreadPool.SizeMax") == 0) + { + ++nThreadPool; + } - ObjectAdapterPtr registryAdapter = _communicator->createObjectAdapter("IcePack.Registry.Internal"); + int size = properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 10); + if(size < nThreadPool) + { + size = nThreadPool; + } + int sizeMax = properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.SizeMax", size * 10); + if(sizeMax < size) + { + sizeMax = size; + } + int sizeWarn = properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.SizeWarn", sizeMax * 80 / 100); - AdapterFactoryPtr adapterFactory = new AdapterFactory(registryAdapter, traceLevels, _envName); - - ObjectRegistryPtr objectRegistry = new ObjectRegistryI(_communicator, _envName, - "objectregistry", "objectregistry-types", - traceLevels); + if(properties->getPropertyAsInt("IcePack.Registry.Client.ThreadPool.Size") == 0 && + properties->getPropertyAsInt("IcePack.Registry.Client.ThreadPool.SizeMax") == 0) + { + properties->setProperty("IcePack.Registry.Client.ThreadPool.Size", intToString(size / nThreadPool)); + properties->setProperty("IcePack.Registry.Client.ThreadPool.SizeMax", intToString(sizeMax / nThreadPool)); + properties->setProperty("IcePack.Registry.Client.ThreadPool.SizeWarn", intToString(sizeWarn / nThreadPool)); + } + if(properties->getPropertyAsInt("IcePack.Registry.Server.ThreadPool.Size") == 0 && + properties->getPropertyAsInt("IcePack.Registry.Server.ThreadPool.SizeMax") == 0) + { + properties->setProperty("IcePack.Registry.Server.ThreadPool.Size", intToString(size / nThreadPool)); + properties->setProperty("IcePack.Registry.Server.ThreadPool.SizeMax", intToString(sizeMax / nThreadPool)); + properties->setProperty("IcePack.Registry.Server.ThreadPool.SizeWarn", intToString(sizeWarn / nThreadPool)); + } + if(properties->getPropertyAsInt("IcePack.Registry.Admin.ThreadPool.Size") == 0 && + properties->getPropertyAsInt("IcePack.Registry.Admin.ThreadPool.SizeMax") == 0) + { + properties->setProperty("IcePack.Registry.Admin.ThreadPool.Size", intToString(size / nThreadPool)); + properties->setProperty("IcePack.Registry.Admin.ThreadPool.SizeMax", intToString(sizeMax / nThreadPool)); + properties->setProperty("IcePack.Registry.Admin.ThreadPool.SizeWarn", intToString(sizeWarn / nThreadPool)); + } - AdapterRegistryPtr adapterRegistry = new AdapterRegistryI(_communicator, _envName, "adapterregistry", traceLevels); + int clientSize = properties->getPropertyAsInt("IcePack.Registry.Client.ThreadPool.Size") * 2; + int serverSize = properties->getPropertyAsInt("IcePack.Registry.Server.ThreadPool.Size") * 2; + properties->setProperty("IcePack.Registry.Internal.ThreadPool.Size", intToString(clientSize + serverSize)); - ServerRegistryPtr serverRegistry = new ServerRegistryI(_communicator, _envName, "serverregistry", - "serverdescriptors", traceLevels); + int clientSizeMax = properties->getPropertyAsInt("IcePack.Registry.Client.ThreadPool.SizeMax") * 2; + if(clientSizeMax < clientSize) + { + clientSizeMax = clientSize; + } + int serverSizeMax = properties->getPropertyAsInt("IcePack.Registry.Server.ThreadPool.SizeMax") * 2; + if(serverSizeMax < serverSize) + { + serverSizeMax = serverSize; + } + properties->setProperty("IcePack.Registry.Internal.ThreadPool.SizeMax", + intToString(clientSizeMax + serverSizeMax)); + + int clientSizeWarn = properties->getPropertyAsIntWithDefault("IcePack.Registry.Client.ThreadPool.SizeWarn", + clientSizeMax * 80 / 100) * 2; + int serverSizeWarn = properties->getPropertyAsIntWithDefault("IcePack.Registry.Server.ThreadPool.SizeWarn", + serverSizeMax * 80 / 100) * 2; + properties->setProperty("IcePack.Registry.Internal.ThreadPool.SizeWarn", + intToString(clientSizeWarn + serverSizeWarn)); + + TraceLevelsPtr traceLevels = new TraceLevels(properties, _communicator->getLogger()); - ApplicationRegistryPtr applicationRegistry = new ApplicationRegistryI(_communicator, serverRegistry, _envName, - "applicationregistry", traceLevels); + _communicator->setDefaultLocator(0); - NodeRegistryPtr nodeRegistry = new NodeRegistryI(_communicator, _envName, "noderegistry", - adapterRegistry, adapterFactory, traceLevels); + // + // Create the object adapters. + // + ObjectAdapterPtr serverAdapter = _communicator->createObjectAdapter("IcePack.Registry.Server"); + ObjectAdapterPtr clientAdapter = _communicator->createObjectAdapter("IcePack.Registry.Client"); + ObjectAdapterPtr adminAdapter = _communicator->createObjectAdapter("IcePack.Registry.Admin"); + ObjectAdapterPtr registryAdapter = _communicator->createObjectAdapter("IcePack.Registry.Internal"); + + // + // Create the internal registries (node, server, adapter, object). + // + AdapterFactoryPtr adapterFactory = new AdapterFactory(registryAdapter, traceLevels, _envName); + ObjectRegistryPtr objectRegistry = new ObjectRegistryI(_communicator, _envName, traceLevels); + AdapterRegistryPtr adapterRegistry = new AdapterRegistryI(_communicator, _envName, traceLevels); + ServerRegistryPtr serverRegistry = new ServerRegistryI(_communicator, _envName, traceLevels); + ApplicationRegistryPtr appReg = new ApplicationRegistryI(_communicator, serverRegistry, _envName, traceLevels); + NodeRegistryPtr nodeReg = new NodeRegistryI(_communicator, _envName, adapterRegistry, adapterFactory, traceLevels); registryAdapter->add(objectRegistry, stringToIdentity("IcePack/ObjectRegistry")); registryAdapter->add(adapterRegistry, stringToIdentity("IcePack/AdapterRegistry")); registryAdapter->add(serverRegistry, stringToIdentity("IcePack/ServerRegistry")); - registryAdapter->add(serverRegistry, stringToIdentity("IcePack/ApplicationRegistry")); - registryAdapter->add(nodeRegistry, stringToIdentity("IcePack/NodeRegistry")); + registryAdapter->add(appReg, stringToIdentity("IcePack/ApplicationRegistry")); + registryAdapter->add(nodeReg, stringToIdentity("IcePack/NodeRegistry")); // - // Create the locator registry adapter and servant. + // Create the locator registry and locator interfaces. // - ObjectAdapterPtr serverAdapter = _communicator->createObjectAdapter("IcePack.Registry.Server"); - - Identity locatorRegistryId; - locatorRegistryId.category = "IcePack"; - locatorRegistryId.name = IceUtil::generateUUID(); - bool dynamicReg = properties->getPropertyAsInt("IcePack.Registry.DynamicRegistration") > 0; ObjectPtr locatorRegistry = new LocatorRegistryI(adapterRegistry, serverRegistry, adapterFactory, dynamicReg); - LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::uncheckedCast( - serverAdapter->add(locatorRegistry, locatorRegistryId)); + ObjectPrx obj = serverAdapter->add(locatorRegistry, stringToIdentity("IcePack/" + IceUtil::generateUUID())); + LocatorRegistryPrx locatorRegistryPrx = LocatorRegistryPrx::uncheckedCast(obj->ice_collocationOptimization(false)); + ObjectPtr locator = new LocatorI(adapterRegistry, objectRegistry, locatorRegistryPrx); + clientAdapter->add(locator, stringToIdentity("IcePack/Locator")); // - // Create the locator adapter and servant. + // Create the query interface and register it with the object registry. // - ObjectAdapterPtr clientAdapter = _communicator->createObjectAdapter("IcePack.Registry.Client"); - - ObjectPtr locator = new LocatorI(adapterRegistry, objectRegistry, locatorRegistryPrx); - LocatorPrx locatorPrx = LocatorPrx::uncheckedCast( - clientAdapter->add(locator, stringToIdentity("IcePack/Locator"))->ice_collocationOptimization(false)); - QueryPtr query = new QueryI(_communicator, objectRegistry); clientAdapter->add(query, stringToIdentity("IcePack/Query")); - - ObjectAdapterPtr adminAdapter; - - if(!properties->getProperty("IcePack.Registry.Admin.Endpoints").empty()) + ObjectPrx queryPrx = clientAdapter->createDirectProxy(stringToIdentity("IcePack/Query")); + try { - // - // Create the admin adapter and servant. - // - properties->setProperty("IcePack.Registry.Admin.AdapterId", "IcePack.Registry.Admin"); - adminAdapter = _communicator->createObjectAdapter("IcePack.Registry.Admin"); - - AdminPtr admin = new AdminI(_communicator, nodeRegistry, applicationRegistry, serverRegistry, adapterRegistry, - objectRegistry); - adminAdapter->add(admin, stringToIdentity("IcePack/Admin")); - - // - // Register the IcePack/Admin object with the object registry. - // - AdminPrx adminPrx = AdminPrx::uncheckedCast( - adminAdapter->createDirectProxy(stringToIdentity("IcePack/Admin"))); - - try - { - objectRegistry->remove(adminPrx); - } - catch(const ObjectNotExistException&) - { - } - - IcePack::ObjectDescriptor desc; - desc.proxy = adminPrx; - desc.type = "::IcePack::Admin"; - - objectRegistry->add(desc); + objectRegistry->remove(queryPrx); } + catch(const ObjectNotExistException&) + { + } + IcePack::ObjectDescriptor desc; + desc.proxy = queryPrx; + desc.type = "::IcePack::Query"; + objectRegistry->add(desc); // - // Register the IcePack/Query object with the object registry. + // Create the admin interface and register it with the object registry. // - QueryPrx queryPrx = QueryPrx::uncheckedCast(clientAdapter->createDirectProxy(stringToIdentity("IcePack/Query"))); + ObjectPtr admin = new AdminI(_communicator, nodeReg, appReg, serverRegistry, adapterRegistry, objectRegistry); + adminAdapter->add(admin, stringToIdentity("IcePack/Admin")); + ObjectPrx adminPrx = adminAdapter->createDirectProxy(stringToIdentity("IcePack/Admin")); try { - objectRegistry->remove(queryPrx); + objectRegistry->remove(adminPrx); } catch(const ObjectNotExistException&) { } - - IcePack::ObjectDescriptor desc; - desc.proxy = queryPrx; - desc.type = "::IcePack::Query"; + desc.proxy = adminPrx; + desc.type = "::IcePack::Admin"; objectRegistry->add(desc); - if(!properties->getProperty("IcePack.Registry.Internal.Endpoints").empty()) + // + // Register the IcePack.Registry.Internal adapter with the adapter registry. + // + try { - // - // Register the IcePack.Registry.Internal adapter with the adapter - // registry and set the locator on the registry adapter. - // - try - { - adapterRegistry->remove("IcePack.Registry.Internal"); - } - catch(const AdapterNotExistException&) - { - } - adapterRegistry->add("IcePack.Registry.Internal", AdapterPrx::uncheckedCast( - serverAdapter->addWithUUID(new StandaloneAdapterI()))); - - registryAdapter->setLocator(locatorPrx); + adapterRegistry->remove("IcePack.Registry.Internal", 0); } + catch(const AdapterNotExistException&) + { + } + obj = registryAdapter->addWithUUID(new StandaloneAdapterI()); + registryAdapter->activate(); + AdapterPrx adapter = AdapterPrx::uncheckedCast(registryAdapter->createDirectProxy(obj->ice_getIdentity())); + adapterRegistry->add("IcePack.Registry.Internal", adapter); + adapter->setDirectProxy(adapter); + + // + // Setup a internal locator to be used by the IcePack registry itself. This locator is + // registered with the registry object adapter which is using an independant threadpool. + // + locator = new LocatorI(adapterRegistry, objectRegistry, locatorRegistryPrx); + registryAdapter->add(locator, stringToIdentity("IcePack/Locator")); + obj = registryAdapter->createDirectProxy(stringToIdentity("IcePack/Locator")); + _communicator->setDefaultLocator(LocatorPrx::uncheckedCast(obj->ice_collocationOptimization(false))); - _communicator->setDefaultLocator(locatorPrx); - // // We are ready to go! // - // NOTE: the locator registry adapter must be activated before the - // registry adapter since the registry adapter needs the locator - // to work to register itself on activation. - // serverAdapter->activate(); clientAdapter->activate(); - registryAdapter->activate(); - if(adminAdapter) { adminAdapter->activate(); diff --git a/cpp/src/IcePack/Registry.h b/cpp/src/IcePack/Registry.h index 490f678e522..41f7e2e2676 100644 --- a/cpp/src/IcePack/Registry.h +++ b/cpp/src/IcePack/Registry.h @@ -20,7 +20,7 @@ public: Registry(const Ice::CommunicatorPtr&); ~Registry(); - bool start(bool, bool); + bool start(bool); private: diff --git a/cpp/src/IcePack/ServerRegistryI.cpp b/cpp/src/IcePack/ServerRegistryI.cpp index 8f06a40fde9..8d3ee10c88d 100644 --- a/cpp/src/IcePack/ServerRegistryI.cpp +++ b/cpp/src/IcePack/ServerRegistryI.cpp @@ -14,24 +14,22 @@ using namespace std; using namespace IcePack; -IcePack::ServerRegistryI::ServerRegistryI(const Ice::CommunicatorPtr& communicator, - const string& envName, - const string& dbName, - const string& dbDescriptorName, - const TraceLevelsPtr& traceLevels) : +const string ServerRegistryI::_dbName = "serverregistry"; +const string ServerRegistryI::_dbDescriptorName = "serverdescriptors"; + +ServerRegistryI::ServerRegistryI(const Ice::CommunicatorPtr& communicator, const string& envName, + const TraceLevelsPtr& traceLevels) : _connectionCache(Freeze::createConnection(communicator, envName)), - _dictCache(_connectionCache, dbName), - _dictDescriptorCache(_connectionCache, dbDescriptorName), + _dictCache(_connectionCache, _dbName), + _dictDescriptorCache(_connectionCache, _dbDescriptorName), _traceLevels(traceLevels), _envName(envName), - _communicator(communicator), - _dbName(dbName), - _dbDescriptorName(dbDescriptorName) + _communicator(communicator) { } void -IcePack::ServerRegistryI::add(const string& name, +ServerRegistryI::add(const string& name, const ServerPrx& server, const ServerDescriptorPtr& descriptor, const Ice::Current& current) @@ -83,7 +81,7 @@ IcePack::ServerRegistryI::add(const string& name, } ServerPrx -IcePack::ServerRegistryI::remove(const string& name, const Ice::Current&) +ServerRegistryI::remove(const string& name, const Ice::Current&) { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxyDict dict(connection, _dbName); @@ -109,7 +107,7 @@ IcePack::ServerRegistryI::remove(const string& name, const Ice::Current&) } ServerPrx -IcePack::ServerRegistryI::findByName(const string& name, const Ice::Current&) +ServerRegistryI::findByName(const string& name, const Ice::Current&) { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxyDict dict(connection, _dbName); @@ -148,7 +146,7 @@ ServerRegistryI::getDescriptor(const string& name, const Ice::Current&) } Ice::StringSeq -IcePack::ServerRegistryI::getAll(const Ice::Current&) const +ServerRegistryI::getAll(const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringObjectProxyDict dict(connection, _dbName); @@ -165,7 +163,7 @@ IcePack::ServerRegistryI::getAll(const Ice::Current&) const } ServerDescriptorSeq -IcePack::ServerRegistryI::getAllDescriptorsOnNode(const string& node, const Ice::Current&) const +ServerRegistryI::getAllDescriptorsOnNode(const string& node, const Ice::Current&) const { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); StringServerDescriptorDict dict(connection, _dbDescriptorName); diff --git a/cpp/src/IcePack/ServerRegistryI.h b/cpp/src/IcePack/ServerRegistryI.h index 4ed572b241e..cb90edda993 100644 --- a/cpp/src/IcePack/ServerRegistryI.h +++ b/cpp/src/IcePack/ServerRegistryI.h @@ -24,8 +24,7 @@ class ServerRegistryI : public ServerRegistry { public: - ServerRegistryI(const Ice::CommunicatorPtr&, const std::string&, const std::string&, const std::string&, - const TraceLevelsPtr&); + ServerRegistryI(const Ice::CommunicatorPtr&, const std::string&, const TraceLevelsPtr&); virtual void add(const std::string&, const ServerPrx&, const ServerDescriptorPtr&, const ::Ice::Current&); virtual ServerPrx remove(const std::string&, const ::Ice::Current&); @@ -37,14 +36,15 @@ public: private: + static const std::string _dbName; + static const std::string _dbDescriptorName; + Freeze::ConnectionPtr _connectionCache; StringObjectProxyDict _dictCache; StringServerDescriptorDict _dictDescriptorCache; TraceLevelsPtr _traceLevels; const std::string _envName; const Ice::CommunicatorPtr _communicator; - const std::string _dbName; - const std::string _dbDescriptorName; }; } |