diff options
Diffstat (limited to 'cpp/src/Ice/ReferenceFactory.cpp')
-rw-r--r-- | cpp/src/Ice/ReferenceFactory.cpp | 206 |
1 files changed, 114 insertions, 92 deletions
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index 9689cf7bf99..b61f74df323 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -27,16 +27,32 @@ void IceInternal::incRef(::IceInternal::ReferenceFactory* p) { p->__incRef(); } void IceInternal::decRef(::IceInternal::ReferenceFactory* p) { p->__decRef(); } ReferencePtr +IceInternal::ReferenceFactory::clone(const Reference* r) const +{ + Mutex::Lock sync(*this); + + if(!_instance) + { + throw CommunicatorDestroyedException(__FILE__, __LINE__); + } + + const Ice::Identity& ident = r->getIdentity(); + if(ident.name.empty() && ident.category.empty()) + { + return 0; + } + + return r->clone(); +} + +ReferencePtr IceInternal::ReferenceFactory::create(const Identity& ident, const Context& context, const string& facet, Reference::Mode mode, bool secure, - const string& adapterId, const vector<EndpointPtr>& endpoints, const RouterInfoPtr& routerInfo, - const LocatorInfoPtr& locatorInfo, - const vector<ConnectionIPtr>& fixedConnections, bool collocationOptimization) { Mutex::Lock sync(*this); @@ -54,70 +70,66 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // // Create new reference // - ReferencePtr ref = new Reference(_instance, ident, context, facet, mode, secure, adapterId, - endpoints, routerInfo, locatorInfo, fixedConnections, - collocationOptimization); + return new DirectReference(_instance, ident, context, facet, mode, secure, + endpoints, routerInfo, collocationOptimization); +} +ReferencePtr +IceInternal::ReferenceFactory::create(const Identity& ident, + const Context& context, + const string& facet, + Reference::Mode mode, + bool secure, + const string& adapterId, + const RouterInfoPtr& routerInfo, + const LocatorInfoPtr& locatorInfo, + bool collocationOptimization) +{ + Mutex::Lock sync(*this); -// -// This code is currently not used, because the eviction code below is -// too slow when there are a large number of references. The savings -// are also rather questionable. -// -/* - // - // If we already have an equivalent reference, use such equivalent - // reference. Otherwise add the new reference to the reference - // set. - // - set<ReferencePtr>::iterator p = _references.end(); - - if(_referencesHint != _references.end()) + if(!_instance) { - if(*_referencesHint == ref) - { - p = _referencesHint; - } + throw CommunicatorDestroyedException(__FILE__, __LINE__); } - - if(p == _references.end()) + + if(ident.name.empty() && ident.category.empty()) { - p = _references.find(ref); + return 0; } - - if(p == _references.end()) + + // + // Create new reference + // + return new IndirectReference(_instance, ident, context, facet, mode, secure, + adapterId, routerInfo, locatorInfo, collocationOptimization); +} + +ReferencePtr +IceInternal::ReferenceFactory::create(const Identity& ident, + const Context& context, + const string& facet, + Reference::Mode mode, + bool secure, + bool collocationOptimization, + const vector<Ice::ConnectionIPtr>& fixedConnections) +{ + Mutex::Lock sync(*this); + + if(!_instance) { - _referencesHint = _references.insert(_referencesHint, ref); + throw CommunicatorDestroyedException(__FILE__, __LINE__); } - else + + if(ident.name.empty() && ident.category.empty()) { - _referencesHint = p; - ref = *_referencesHint; + return 0; } // - // At every 10th call, evict references which are not in use anymore. + // Create new reference // - if(++_evict >= 10) - { - _evict = 0; - p = _references.begin(); - while(p != _references.end()) - { - if((*p)->__getRef() == 1) - { - assert(p != _referencesHint); - _references.erase(p++); - } - else - { - ++p; - } - } - } -*/ - - return ref; + return new FixedReference(_instance, ident, context, facet, mode, secure, + collocationOptimization, fixedConnections); } ReferencePtr @@ -288,7 +300,7 @@ IceInternal::ReferenceFactory::create(const string& str) // // If any new options are added here, - // IceInternal::Reference::toString() must be updated as well. + // IceInternal::Reference::toString() and its derived classes must be updated as well. // switch(option[1]) { @@ -392,10 +404,19 @@ IceInternal::ReferenceFactory::create(const string& str) } } + RouterInfoPtr routerInfo = _instance->routerManager()->get(getDefaultRouter()); + LocatorInfoPtr locatorInfo = _instance->locatorManager()->get(getDefaultLocator()); + + if(beg == string::npos) + { + return create(ident, Context(), facet, mode, secure, "", routerInfo, locatorInfo, true); + } + vector<EndpointPtr> endpoints; - if(beg != string::npos) + + switch(s[beg]) { - if(s[beg] == ':') + case ':': { end = beg; @@ -413,8 +434,10 @@ IceInternal::ReferenceFactory::create(const string& str) EndpointPtr endp = _instance->endpointFactoryManager()->create(es); endpoints.push_back(endp); } + return create(ident, Context(), facet, mode, secure, endpoints, routerInfo, true); + break; } - else if(s[beg] == '@') + case '@': { beg = s.find_first_not_of(delim, beg + 1); if(beg == string::npos) @@ -424,39 +447,42 @@ IceInternal::ReferenceFactory::create(const string& str) throw ex; } - end = IceUtil::checkQuote(s, beg); - if(end == string::npos) - { + end = IceUtil::checkQuote(s, beg); + if(end == string::npos) + { ProxyParseException ex(__FILE__, __LINE__); ex.str = str; throw ex; - } - else if(end == 0) - { - end = s.find_first_of(delim, beg); - if(end == string::npos) - { - end = s.size(); - } - } - else - { - beg++; // Skip leading quote - } + } + else if(end == 0) + { + end = s.find_first_of(delim, beg); + if(end == string::npos) + { + end = s.size(); + } + } + else + { + beg++; // Skip leading quote + } - if(!IceUtil::unescapeString(s, beg, end, adapter) || adapter.size() == 0) - { + if(!IceUtil::unescapeString(s, beg, end, adapter) || adapter.size() == 0) + { ProxyParseException ex(__FILE__, __LINE__); ex.str = str; throw ex; - } + } + return create(ident, Context(), facet, mode, secure, adapter, routerInfo, locatorInfo, true); + break; + } + default: + { + ProxyParseException ex(__FILE__, __LINE__); + ex.str = str; + throw ex; } } - - RouterInfoPtr routerInfo = _instance->routerManager()->get(getDefaultRouter()); - LocatorInfoPtr locatorInfo = _instance->locatorManager()->get(getDefaultLocator()); - return create(ident, Context(), facet, mode, secure, adapter, endpoints, routerInfo, locatorInfo, - vector<ConnectionIPtr>(), true); } ReferencePtr @@ -501,6 +527,9 @@ IceInternal::ReferenceFactory::create(const Identity& ident, BasicStream* s) vector<EndpointPtr> endpoints; string adapterId; + RouterInfoPtr routerInfo = _instance->routerManager()->get(getDefaultRouter()); + LocatorInfoPtr locatorInfo = _instance->locatorManager()->get(getDefaultLocator()); + Ice::Int sz; s->readSize(sz); @@ -512,16 +541,13 @@ IceInternal::ReferenceFactory::create(const Identity& ident, BasicStream* s) EndpointPtr endpoint = _instance->endpointFactoryManager()->read(s); endpoints.push_back(endpoint); } + return create(ident, Context(), facet, mode, secure, endpoints, routerInfo, true); } else { s->read(adapterId); + return create(ident, Context(), facet, mode, secure, adapterId, routerInfo, locatorInfo, true); } - - RouterInfoPtr routerInfo = _instance->routerManager()->get(getDefaultRouter()); - LocatorInfoPtr locatorInfo = _instance->locatorManager()->get(getDefaultLocator()); - return create(ident, Context(), facet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, - vector<ConnectionIPtr>(), true); } void @@ -553,9 +579,7 @@ IceInternal::ReferenceFactory::getDefaultLocator() const } IceInternal::ReferenceFactory::ReferenceFactory(const InstancePtr& instance) : - _instance(instance), - _referencesHint(_references.end()), - _evict(0) + _instance(instance) { } @@ -572,6 +596,4 @@ IceInternal::ReferenceFactory::destroy() _instance = 0; _defaultRouter = 0; _defaultLocator = 0; - _references.clear(); - _referencesHint = _references.end(); } |