diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-04-12 17:32:00 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-04-12 17:32:00 +0000 |
commit | b764fe6ce04b1367522a20a518933cca3ae54c66 (patch) | |
tree | 9334709074a791244c90a5ea78240ba930a93524 /cppe/src/IceE/ObjectAdapter.cpp | |
parent | Fix (diff) | |
download | ice-b764fe6ce04b1367522a20a518933cca3ae54c66.tar.bz2 ice-b764fe6ce04b1367522a20a518933cca3ae54c66.tar.xz ice-b764fe6ce04b1367522a20a518933cca3ae54c66.zip |
Added createObjectAdapterWithRouter
Diffstat (limited to 'cppe/src/IceE/ObjectAdapter.cpp')
-rw-r--r-- | cppe/src/IceE/ObjectAdapter.cpp | 239 |
1 files changed, 120 insertions, 119 deletions
diff --git a/cppe/src/IceE/ObjectAdapter.cpp b/cppe/src/IceE/ObjectAdapter.cpp index 2a025eb64a2..ce898b77ae8 100644 --- a/cppe/src/IceE/ObjectAdapter.cpp +++ b/cppe/src/IceE/ObjectAdapter.cpp @@ -8,6 +8,7 @@ // ********************************************************************** #include <IceE/ObjectAdapter.h> +#include <IceE/ObjectAdapterFactory.h> #include <IceE/UUID.h> #include <IceE/Instance.h> #include <IceE/ProxyFactory.h> @@ -220,6 +221,26 @@ Ice::ObjectAdapter::deactivate() return; } +#ifdef ICEE_HAS_ROUTER + if(_routerInfo) + { + // + // Remove entry from the router manager. + // + _instance->routerManager()->erase(_routerInfo->getRouter()); + + // + // Clear this object adapter with the router. + // + _routerInfo->setAdapter(0); + + // + // Update all existing outgoing connections. + // + _instance->outgoingConnectionFactory()->setRouterInfo(_routerInfo); + } +#endif + incomingConnectionFactories = _incomingConnectionFactories; outgoingConnectionFactory = _instance->outgoingConnectionFactory(); @@ -286,6 +307,8 @@ Ice::ObjectAdapter::waitForDeactivate() _servantManager->destroy(); } + ObjectAdapterFactoryPtr objectAdapterFactory; + { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); @@ -307,9 +330,29 @@ Ice::ObjectAdapter::waitForDeactivate() _instance = 0; _servantManager = 0; _communicator = 0; +#ifdef ICEE_HAS_ROUTER + _routerInfo = 0; +#endif +#ifdef ICEE_HAS_LOCATOR + _locatorInfo = 0; +#endif + objectAdapterFactory = _objectAdapterFactory; + _objectAdapterFactory = 0; + } + + if(objectAdapterFactory) + { + objectAdapterFactory->removeObjectAdapter(_name); } } +void +Ice::ObjectAdapter::destroy() +{ + deactivate(); + waitForDeactivate(); +} + ObjectPrx Ice::ObjectAdapter::add(const ObjectPtr& object, const Identity& ident) { @@ -474,91 +517,6 @@ Ice::ObjectAdapter::createReverseProxy(const Identity& ident) const return _instance->proxyFactory()->referenceToProxy(ref); } -#ifdef ICEE_HAS_ROUTER -void -Ice::ObjectAdapter::addRouter(const RouterPrx& router) -{ - IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - - checkForDeactivation(); - - RouterInfoPtr routerInfo = _instance->routerManager()->get(router); - if(routerInfo) - { - _routerInfos.push_back(routerInfo); - - // - // Add the router's server proxy endpoints to this object - // adapter. - // - ObjectPrx proxy = routerInfo->getServerProxy(); - vector<EndpointPtr> endpoints = proxy->__reference()->getEndpoints(); - 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); - } -} - -void -Ice::ObjectAdapter::removeRouter(const RouterPrx& router) -{ - IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - - checkForDeactivation(); - - RouterInfoPtr routerInfo = _instance->routerManager()->erase(router); - if(routerInfo) - { - // - // Rebuild the router endpoints from our set of router infos. - // - _routerEndpoints.clear(); - vector<RouterInfoPtr>::iterator p = _routerInfos.begin(); - while(p != _routerInfos.end()) - { - if(*p == routerInfo) - { - p = _routerInfos.erase(p); - continue; - } - ObjectPrx proxy = (*p)->getServerProxy(); - vector<EndpointPtr> endpoints = proxy->__reference()->getEndpoints(); - copy(endpoints.begin(), endpoints.end(), back_inserter(_routerEndpoints)); - ++p; - } - - sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted. - _routerEndpoints.erase(unique(_routerEndpoints.begin(), _routerEndpoints.end()), _routerEndpoints.end()); - - // - // Clear this object adapter with the router. - // - routerInfo->setAdapter(0); - - // - // Also modify all existing outgoing connections to the - // router's client proxy to use this object adapter for - // callbacks. - // - _instance->outgoingConnectionFactory()->setRouterInfo(routerInfo); - } -} -#endif - #ifdef ICEE_HAS_LOCATOR void Ice::ObjectAdapter::setLocator(const LocatorPrx& locator) @@ -624,10 +582,16 @@ Ice::ObjectAdapter::getServantManager() const } Ice::ObjectAdapter::ObjectAdapter(const InstancePtr& instance, const CommunicatorPtr& communicator, - const string& name, const string& endpointInfo) : + const ObjectAdapterFactoryPtr& objectAdapterFactory, + const string& name, const string& endpointInfo +#ifdef ICEE_HAS_ROUTER + , const RouterPrx& router +#endif + ) : _deactivated(false), _instance(instance), _communicator(communicator), + _objectAdapterFactory(objectAdapterFactory), _servantManager(new ServantManager(instance, name)), _printAdapterReadyDone(false), _name(name), @@ -641,43 +605,80 @@ Ice::ObjectAdapter::ObjectAdapter(const InstancePtr& instance, const Communicato __setNoDelete(true); try { - // - // 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 = parseEndpoints(endpointInfo); - for(vector<EndpointPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) - { - _incomingConnectionFactories.push_back(new IncomingConnectionFactory(_instance, *p, this)); - } - - // - // Parse published endpoints. These are used in proxies - // instead of the connection factory endpoints. - // - string endpts = _instance->initializationData().properties->getProperty(name + ".PublishedEndpoints"); - _publishedEndpoints = parseEndpoints(endpts); - if(_publishedEndpoints.empty()) +#ifdef ICEE_HAS_ROUTER + if(!router) { - transform(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), - back_inserter(_publishedEndpoints), Ice::constMemFun(&IncomingConnectionFactory::endpoint)); + string routerStr = _instance->initializationData().properties->getProperty(_name + ".Router"); + if(!routerStr.empty()) + { + const_cast<RouterPrx&>(router) = + RouterPrx::uncheckedCast(_instance->proxyFactory()->stringToProxy(routerStr)); + } } - - // - // Filter out any endpoints that are not meant to be published. - // - _publishedEndpoints.erase(remove_if(_publishedEndpoints.begin(), _publishedEndpoints.end(), - not1(Ice::constMemFun(&Endpoint::publish))), _publishedEndpoints.end()); - -#ifdef ICEE_HAS_ROUTER - string router = _instance->initializationData().properties->getProperty(_name + ".Router"); - if(!router.empty()) - { - addRouter(RouterPrx::uncheckedCast(_instance->proxyFactory()->stringToProxy(router))); + if(router) + { + _routerInfo = _instance->routerManager()->get(router); + if(_routerInfo) + { + // + // Add the router's server proxy endpoints to this object + // adapter. + // + ObjectPrx proxy = _routerInfo->getServerProxy(); + vector<EndpointPtr> endpoints = proxy->__reference()->getEndpoints(); + 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 = parseEndpoints(endpointInfo); + for(vector<EndpointPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) + { + _incomingConnectionFactories.push_back(new IncomingConnectionFactory(_instance, *p, this)); + } + + // + // Parse published endpoints. These are used in proxies + // instead of the connection factory endpoints. + // + string endpts = _instance->initializationData().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(&Endpoint::publish))), _publishedEndpoints.end()); + } + #ifdef ICEE_HAS_LOCATOR string locator = _instance->initializationData().properties->getProperty(_name + ".Locator"); if(!locator.empty()) |