diff options
Diffstat (limited to 'cpp/src/Ice/LocatorInfo.cpp')
-rw-r--r-- | cpp/src/Ice/LocatorInfo.cpp | 375 |
1 files changed, 312 insertions, 63 deletions
diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index 606d7557fdd..f14561fef20 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -375,92 +375,149 @@ IceInternal::LocatorInfo::getEndpoints(const IndirectReferencePtr& ref, int ttl, cached = objectCached || endpointsCached; } } - catch(const AdapterNotFoundException&) + catch(const Ice::Exception& ex) { - if(ref->getInstance()->traceLevels()->location >= 1) - { - Trace out(ref->getInstance()->initializationData().logger, - ref->getInstance()->traceLevels()->locationCat); - out << "adapter not found" << "\n"; - out << "adapter = " << ref->getAdapterId(); - } - - NotRegisteredException ex(__FILE__, __LINE__); - ex.kindOfObject = "object adapter"; - ex.id = ref->getAdapterId(); - throw ex; + getEndpointsException(ref, ex); } - catch(const ObjectNotFoundException&) - { - if(ref->getInstance()->traceLevels()->location >= 1) - { - Trace out(ref->getInstance()->initializationData().logger, - ref->getInstance()->traceLevels()->locationCat); - out << "object not found" << "\n"; - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()); - } - NotRegisteredException ex(__FILE__, __LINE__); - ex.kindOfObject = "object"; - ex.id = ref->getInstance()->identityToString(ref->getIdentity()); - throw ex; - } - catch(const NotRegisteredException&) + if(ref->getInstance()->traceLevels()->location >= 1) { - throw; + getEndpointsTrace(ref, endpoints, cached); } - catch(const LocalException& ex) + + return endpoints; +} + +void +IceInternal::LocatorInfo::getEndpoints(const IndirectReferencePtr& ref, int ttl, + const GetEndpointsCallbackPtr& callback) +{ + string adapterId = ref->getAdapterId(); + Ice::Identity identity = ref->getIdentity(); + InstancePtr instance = ref->getInstance(); + if(!adapterId.empty()) { - if(ref->getInstance()->traceLevels()->location >= 1) + vector<EndpointIPtr> endpoints; + if(!_table->getAdapterEndpoints(adapterId, ttl, endpoints)) { - Trace out(ref->getInstance()->initializationData().logger, - ref->getInstance()->traceLevels()->locationCat); - out << "couldn't contact the locator to retrieve adapter endpoints\n"; - if(ref->getAdapterId().empty()) + if(instance->traceLevels()->location >= 1) { - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()) << "\n"; + Trace out(instance->initializationData().logger, instance->traceLevels()->locationCat); + out << "searching for adapter by id" << "\nadapter = " << adapterId; } - else + + class Callback : public AMI_Locator_findAdapterById { - out << "adapter = " << ref->getAdapterId() << "\n"; + public: + + virtual void + ice_response(const Ice::ObjectPrx& object) + { + vector<EndpointIPtr> endpoints; + if(object) + { + endpoints = object->__reference()->getEndpoints(); + if(!endpoints.empty()) + { + _table->addAdapterEndpoints(_reference->getAdapterId(), endpoints); + } + } + + if(_reference->getInstance()->traceLevels()->location >= 1) + { + _locatorInfo->getEndpointsTrace(_reference, endpoints, false); + } + + _callback->setEndpoints(endpoints, false); + } + + virtual void + ice_exception(const Ice::Exception& ex) + { + _locatorInfo->getEndpointsException(_reference, ex, _callback); + } + + Callback(const LocatorInfoPtr& locatorInfo, const LocatorTablePtr& table, + const IndirectReferencePtr& reference, const GetEndpointsCallbackPtr& callback) : + _locatorInfo(locatorInfo), _table(table), _reference(reference), _callback(callback) + { + } + + private: + + const LocatorInfoPtr _locatorInfo; + const LocatorTablePtr _table; + const IndirectReferencePtr _reference; + const GetEndpointsCallbackPtr _callback; + }; + + // + // Search the adapter in the location service if we didn't + // find it in the cache. + // + _locator->findAdapterById_async(new Callback(this, _table, ref, callback), adapterId); + return; + } + else + { + if(instance->traceLevels()->location >= 1) + { + getEndpointsTrace(ref, endpoints, true); } - out << "reason = " << ex; + callback->setEndpoints(endpoints, true); + return; } - throw; } - - - if(ref->getInstance()->traceLevels()->location >= 1) + else { - if(!endpoints.empty()) + Ice::ObjectPrx object; + if(!_table->getProxy(identity, ttl, object)) { - if(cached) + if(instance->traceLevels()->location >= 1) { - trace("found endpoints in locator table", ref, endpoints); + Trace out(instance->initializationData().logger, instance->traceLevels()->locationCat); + out << "searching for object by id" << "\nobject = " << instance->identityToString(ref->getIdentity()); } - else + + class Callback : public Ice::AMI_Locator_findObjectById { - trace("retrieved endpoints from locator, adding to locator table", ref, endpoints); - } + public: + + virtual void + ice_response(const Ice::ObjectPrx& object) + { + _locatorInfo->getWellKnownObjectEndpoints(_reference, object, _ttl, false, _callback); + } + + virtual void + ice_exception(const Ice::Exception& ex) + { + _locatorInfo->getEndpointsException(_reference, ex, _callback); + } + + Callback(const LocatorInfoPtr& locatorInfo, const IndirectReferencePtr& reference, int ttl, + const GetEndpointsCallbackPtr& callback) : + _locatorInfo(locatorInfo), _reference(reference), _ttl(ttl), _callback(callback) + { + } + + private: + + const LocatorInfoPtr _locatorInfo; + const IndirectReferencePtr _reference; + int _ttl; + const GetEndpointsCallbackPtr _callback; + }; + + _locator->findObjectById_async(new Callback(this, ref, ttl, callback), identity); + return; } else { - Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat); - out << "no endpoints configured for "; - if(ref->getAdapterId().empty()) - { - out << "object\n"; - out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()); - } - else - { - out << "adapter\n"; - out << "adapter = " << ref->getAdapterId(); - } + getWellKnownObjectEndpoints(ref, object, ttl, true, callback); + return; } } - - return endpoints; } void @@ -548,3 +605,195 @@ IceInternal::LocatorInfo::trace(const string& msg, Ice::constMemFun(&Endpoint::toString)); out << "endpoints = " << o.str(); } + +void +IceInternal::LocatorInfo::getEndpointsException(const IndirectReferencePtr& ref, const Ice::Exception& exc) +{ + try + { + exc.ice_throw(); + } + catch(const AdapterNotFoundException&) + { + if(ref->getInstance()->traceLevels()->location >= 1) + { + Trace out(ref->getInstance()->initializationData().logger, + ref->getInstance()->traceLevels()->locationCat); + out << "adapter not found" << "\n"; + out << "adapter = " << ref->getAdapterId(); + } + + NotRegisteredException ex(__FILE__, __LINE__); + ex.kindOfObject = "object adapter"; + ex.id = ref->getAdapterId(); + throw ex; + } + catch(const ObjectNotFoundException&) + { + if(ref->getInstance()->traceLevels()->location >= 1) + { + Trace out(ref->getInstance()->initializationData().logger, + ref->getInstance()->traceLevels()->locationCat); + out << "object not found" << "\n"; + out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()); + } + + NotRegisteredException ex(__FILE__, __LINE__); + ex.kindOfObject = "object"; + ex.id = ref->getInstance()->identityToString(ref->getIdentity()); + throw ex; + } + catch(const NotRegisteredException&) + { + throw; + } + catch(const LocalException& ex) + { + if(ref->getInstance()->traceLevels()->location >= 1) + { + Trace out(ref->getInstance()->initializationData().logger, + ref->getInstance()->traceLevels()->locationCat); + out << "couldn't contact the locator to retrieve adapter endpoints\n"; + if(ref->getAdapterId().empty()) + { + out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()) << "\n"; + } + else + { + out << "adapter = " << ref->getAdapterId() << "\n"; + } + out << "reason = " << ex; + } + throw; + } +} + +void +IceInternal::LocatorInfo::getEndpointsException(const IndirectReferencePtr& ref, const Ice::Exception& exc, + const GetEndpointsCallbackPtr& callback) +{ + try + { + getEndpointsException(ref, exc); + } + catch(const Ice::LocalException& ex) + { + callback->setException(ex); + } +} + +void +IceInternal::LocatorInfo::getWellKnownObjectEndpoints(const IndirectReferencePtr& ref, + const Ice::ObjectPrx& object, + int ttl, + bool objectCached, + const GetEndpointsCallbackPtr& callback) +{ + class Callback : public GetEndpointsCallback + { + public: + + virtual void + setEndpoints(const vector<EndpointIPtr>& endpoints, bool endpointsCached) + { + if(!_objectCached && !endpoints.empty()) + { + _table->addProxy(_reference->getIdentity(), _object); + } + + if(_reference->getInstance()->traceLevels()->location >= 1) + { + _locatorInfo->getEndpointsTrace(_reference, endpoints, _objectCached || endpointsCached); + } + + _callback->setEndpoints(endpoints, _objectCached || endpointsCached); + } + + virtual void + setException(const Ice::LocalException& ex) + { + _callback->setException(ex); + } + + Callback(const LocatorInfoPtr& locatorInfo, const LocatorTablePtr& table, + const IndirectReferencePtr& reference, const Ice::ObjectPrx& object, + bool objectCached, const GetEndpointsCallbackPtr& callback) : + _locatorInfo(locatorInfo), _table(table), _reference(reference), _object(object), + _objectCached(objectCached), _callback(callback) + { + } + + private: + + const LocatorInfoPtr _locatorInfo; + const LocatorTablePtr _table; + const IndirectReferencePtr _reference; + const Ice::ObjectPrx _object; + const bool _objectCached; + const GetEndpointsCallbackPtr _callback; + }; + + vector<EndpointIPtr> endpoints; + if(object) + { + DirectReferencePtr odr = DirectReferencePtr::dynamicCast(object->__reference()); + if(odr) + { + endpoints = odr->getEndpoints(); + } + else + { + IndirectReferencePtr oir = IndirectReferencePtr::dynamicCast(object->__reference()); + assert(oir); + if(!oir->getAdapterId().empty()) + { + getEndpoints(oir, ttl, new Callback(this, _table, ref, object, objectCached, callback)); + return; + } + } + } + + if(!objectCached && !endpoints.empty()) + { + _table->addProxy(ref->getIdentity(), object); + } + + if(ref->getInstance()->traceLevels()->location >= 1) + { + getEndpointsTrace(ref, endpoints, objectCached); + } + + callback->setEndpoints(endpoints, objectCached); +} + +void +IceInternal::LocatorInfo::getEndpointsTrace(const IndirectReferencePtr& ref, const vector<EndpointIPtr>& endpoints, + bool cached) +{ + if(!endpoints.empty()) + { + if(cached) + { + trace("found endpoints in locator table", ref, endpoints); + } + else + { + trace("retrieved endpoints from locator, adding to locator table", ref, endpoints); + } + } + else + { + Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat); + out << "no endpoints configured for "; + if(ref->getAdapterId().empty()) + { + out << "object\n"; + out << "object = " << ref->getInstance()->identityToString(ref->getIdentity()); + } + else + { + out << "adapter\n"; + out << "adapter = " << ref->getAdapterId(); + } + } +} |