summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/.depend2
-rw-r--r--cpp/src/Ice/Exception.cpp7
-rw-r--r--cpp/src/Ice/LocatorInfo.cpp293
-rw-r--r--cpp/src/Ice/LocatorInfo.h24
-rw-r--r--cpp/src/Ice/LocatorInfoF.h8
-rw-r--r--cpp/src/Ice/Object.cpp4
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp9
-rw-r--r--cpp/src/Ice/ObjectFactoryManager.cpp4
-rw-r--r--cpp/src/Ice/Proxy.cpp10
-rw-r--r--cpp/src/Ice/ReferenceFactory.cpp6
-rw-r--r--cpp/src/Ice/UserExceptionFactoryManager.cpp4
11 files changed, 251 insertions, 120 deletions
diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend
index 796459867c7..e05ea92e663 100644
--- a/cpp/src/Ice/.depend
+++ b/cpp/src/Ice/.depend
@@ -92,5 +92,5 @@ Router.cpp: ../../slice/Ice/Router.ice
RouterF.cpp: ../../slice/Ice/RouterF.ice
Plugin.cpp: ../../slice/Ice/Plugin.ice
PluginF.cpp: ../../slice/Ice/PluginF.ice
-Locator.cpp: ../../slice/Ice/Locator.ice
+Locator.cpp: ../../slice/Ice/Locator.ice ../../slice/Ice/Identity.ice
LocatorF.cpp: ../../slice/Ice/LocatorF.ice
diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp
index d2f924bc5a8..93861ac9b9e 100644
--- a/cpp/src/Ice/Exception.cpp
+++ b/cpp/src/Ice/Exception.cpp
@@ -92,6 +92,13 @@ Ice::ObjectAdapterDeactivatedException::ice_print(ostream& out) const
}
void
+Ice::ObjectAdapterIdInUseException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ":\nobject adapter with id `" << id << "' is already in use";
+}
+
+void
Ice::NoEndpointException::ice_print(ostream& out) const
{
Exception::ice_print(out);
diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp
index 958678f93ca..7c28a737f29 100644
--- a/cpp/src/Ice/LocatorInfo.cpp
+++ b/cpp/src/Ice/LocatorInfo.cpp
@@ -35,8 +35,8 @@ void IceInternal::decRef(LocatorManager* p) { p->__decRef(); }
void IceInternal::incRef(LocatorInfo* p) { p->__incRef(); }
void IceInternal::decRef(LocatorInfo* p) { p->__decRef(); }
-void IceInternal::incRef(LocatorAdapterTable* p) { p->__incRef(); }
-void IceInternal::decRef(LocatorAdapterTable* p) { p->__decRef(); }
+void IceInternal::incRef(LocatorTable* p) { p->__incRef(); }
+void IceInternal::decRef(LocatorTable* p) { p->__decRef(); }
IceInternal::LocatorManager::LocatorManager() :
_tableHint(_table.end())
@@ -53,7 +53,7 @@ IceInternal::LocatorManager::destroy()
_table.clear();
_tableHint = _table.end();
- _adapterTables.clear();
+ _locatorTables.clear();
}
LocatorInfoPtr
@@ -92,11 +92,11 @@ IceInternal::LocatorManager::get(const LocatorPrx& locator)
// have only one table per locator (not one per locator
// proxy).
//
- map<Identity, LocatorAdapterTablePtr>::iterator t = _adapterTables.find(locator->ice_getIdentity());
- if(t == _adapterTables.end())
+ map<Identity, LocatorTablePtr>::iterator t = _locatorTables.find(locator->ice_getIdentity());
+ if(t == _locatorTables.end())
{
- t = _adapterTables.insert(_adapterTables.begin(),
- make_pair(locator->ice_getIdentity(), new LocatorAdapterTable()));
+ t = _locatorTables.insert(_locatorTables.begin(),
+ make_pair(locator->ice_getIdentity(), new LocatorTable()));
}
_tableHint = _table.insert(_tableHint, make_pair(locator, new LocatorInfo(locator, t->second)));
@@ -109,16 +109,25 @@ IceInternal::LocatorManager::get(const LocatorPrx& locator)
return _tableHint->second;
}
-IceInternal::LocatorAdapterTable::LocatorAdapterTable()
+IceInternal::LocatorTable::LocatorTable()
{
}
+void
+IceInternal::LocatorTable::clear()
+{
+ IceUtil::Mutex::Lock sync(*this);
+
+ _adapterEndpointsMap.clear();
+ _objectMap.clear();
+}
+
bool
-IceInternal::LocatorAdapterTable::get(const string& adapter, ::std::vector<EndpointPtr>& endpoints) const
+IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, vector<EndpointPtr>& endpoints) const
{
IceUtil::Mutex::Lock sync(*this);
- std::map<std::string, std::vector<EndpointPtr> >::const_iterator p = _adapterEndpointsMap.find(adapter);
+ map<string, vector<EndpointPtr> >::const_iterator p = _adapterEndpointsMap.find(adapter);
if(p != _adapterEndpointsMap.end())
{
@@ -132,46 +141,81 @@ IceInternal::LocatorAdapterTable::get(const string& adapter, ::std::vector<Endpo
}
void
-IceInternal::LocatorAdapterTable::clear()
-{
- IceUtil::Mutex::Lock sync(*this);
-
- _adapterEndpointsMap.clear();
-}
-
-void
-IceInternal::LocatorAdapterTable::add(const string& adapter, const ::std::vector<EndpointPtr>& endpoints)
+IceInternal::LocatorTable::addAdapterEndpoints(const string& adapter, const vector<EndpointPtr>& endpoints)
{
IceUtil::Mutex::Lock sync(*this);
_adapterEndpointsMap.insert(make_pair(adapter, endpoints));
}
-::std::vector<EndpointPtr>
-IceInternal::LocatorAdapterTable::remove(const string& adapter)
+vector<EndpointPtr>
+IceInternal::LocatorTable::removeAdapterEndpoints(const string& adapter)
{
IceUtil::Mutex::Lock sync(*this);
- std::map<std::string, std::vector<EndpointPtr> >::iterator p = _adapterEndpointsMap.find(adapter);
+ map<string, vector<EndpointPtr> >::iterator p = _adapterEndpointsMap.find(adapter);
if(p == _adapterEndpointsMap.end())
{
- return std::vector<EndpointPtr>();
+ return vector<EndpointPtr>();
}
- std::vector<EndpointPtr> endpoints = p->second;
+ vector<EndpointPtr> endpoints = p->second;
_adapterEndpointsMap.erase(p);
return endpoints;
}
+bool
+IceInternal::LocatorTable::getProxy(const Identity& id, ObjectPrx& proxy) const
+{
+ IceUtil::Mutex::Lock sync(*this);
+
+ map<Identity, ObjectPrx>::const_iterator p = _objectMap.find(id);
+
+ if(p != _objectMap.end())
+ {
+ proxy = p->second;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
-IceInternal::LocatorInfo::LocatorInfo(const LocatorPrx& locator, const LocatorAdapterTablePtr& adapterTable) :
+void
+IceInternal::LocatorTable::addProxy(const Identity& id, const ObjectPrx& proxy)
+{
+ IceUtil::Mutex::Lock sync(*this);
+
+ _objectMap.insert(make_pair(id, proxy));
+}
+
+ObjectPrx
+IceInternal::LocatorTable::removeProxy(const Identity& id)
+{
+ IceUtil::Mutex::Lock sync(*this);
+
+ map<Identity, ObjectPrx>::iterator p = _objectMap.find(id);
+ if(p == _objectMap.end())
+ {
+ return 0;
+ }
+
+ ObjectPrx proxy = p->second;
+
+ _objectMap.erase(p);
+
+ return proxy;
+}
+
+IceInternal::LocatorInfo::LocatorInfo(const LocatorPrx& locator, const LocatorTablePtr& table) :
_locator(locator),
- _adapterTable(adapterTable)
+ _table(table)
{
assert(_locator);
- assert(_adapterTable);
+ assert(_table);
}
void
@@ -181,7 +225,7 @@ IceInternal::LocatorInfo::destroy()
_locator = 0;
_locatorRegistry = 0;
- _adapterTable->clear();
+ _table->clear();
}
bool
@@ -224,113 +268,176 @@ IceInternal::LocatorInfo::getLocatorRegistry()
return _locatorRegistry;
}
-std::vector<EndpointPtr>
+vector<EndpointPtr>
IceInternal::LocatorInfo::getEndpoints(const ReferencePtr& ref, bool& cached)
{
- ::std::vector<EndpointPtr> endpoints;
+ assert(ref->endpoints.empty());
- if(!ref->adapterId.empty())
- {
- cached = true;
+ vector<EndpointPtr> endpoints;
+ ObjectPrx object;
+ cached = true;
- if(!_adapterTable->get(ref->adapterId, endpoints))
+ try
+ {
+ if(!ref->adapterId.empty())
{
- cached = false;
-
- //
- // Search the adapter in the location service if we didn't
- // find it in the cache.
- //
- try
+ if(!_table->getAdapterEndpoints(ref->adapterId, endpoints))
{
- ObjectPrx object = _locator->findAdapterById(ref->adapterId);
+ cached = false;
+
+ object = _locator->findAdapterById(ref->adapterId);
if(object)
{
endpoints = object->__reference()->endpoints;
+
+ if(!endpoints.empty())
+ {
+ _table->addAdapterEndpoints(ref->adapterId, endpoints);
+ }
}
}
- catch(const AdapterNotRegisteredException&)
+ }
+ else
+ {
+ if(!_table->getProxy(ref->identity, object))
{
- if(ref->instance->traceLevels()->location >= 1)
- {
- Trace out(ref->instance->logger(), ref->instance->traceLevels()->locationCat);
- out << "adapter `" << ref->adapterId << "' is not registered";
- }
+ cached = false;
+
+ object = _locator->findObjectById(ref->identity);
}
- catch(const LocalException& ex)
+
+ if(object)
{
- //
- // Just trace the failure. The proxy will most likely get empty
- // endpoints and raise a NoEndpointException().
- //
- if(ref->instance->traceLevels()->location >= 1)
+ if(!object->__reference()->endpoints.empty())
+ {
+ endpoints = object->__reference()->endpoints;
+ }
+ else if(!object->__reference()->adapterId.empty())
{
- Trace out(ref->instance->logger(), ref->instance->traceLevels()->locationCat);
- out << "couldn't contact the locator to retrieve adapter endpoints\n";
- out << "adapter = " << ref->adapterId << "\n";
- out << "reason = " << ex;
+ endpoints = getEndpoints(object->__reference(), cached);
}
}
- //
- // Add to the cache.
- //
- if(!endpoints.empty())
+ if(!cached && !endpoints.empty())
{
- _adapterTable->add(ref->adapterId, endpoints);
+ _table->addProxy(ref->identity, object);
}
}
-
- if(!endpoints.empty())
+ }
+ catch(const AdapterNotFoundException&)
+ {
+ NotRegisteredException ex(__FILE__, __LINE__);
+ ex.kindOfObject = "object adapter";
+ ex.id = ref->adapterId;
+ throw ex;
+ }
+ catch(const ObjectNotFoundException&)
+ {
+ NotRegisteredException ex(__FILE__, __LINE__);
+ ex.kindOfObject = "object";
+ ex.id = identityToString(ref->identity);
+ throw ex;
+ }
+ catch(const NotRegisteredException&)
+ {
+ throw;
+ }
+ catch(const LocalException& ex)
+ {
+ if(ref->instance->traceLevels()->location >= 1)
{
- if(ref->instance->traceLevels()->location >= 1)
+ Trace out(ref->instance->logger(), ref->instance->traceLevels()->locationCat);
+ out << "couldn't contact the locator to retrieve adapter endpoints\n";
+ if(ref->adapterId.empty())
+ {
+ out << "object = " << identityToString(ref->identity) << "\n";
+ }
+ else
{
- Trace out(ref->instance->logger(), ref->instance->traceLevels()->locationCat);
- if(cached)
- {
- out << "found endpoints in locator table\n";
- }
- else
- {
- out << "retrieved endpoints from locator, adding to locator table\n";
- }
out << "adapter = " << ref->adapterId << "\n";
- const char* sep = endpoints.size() > 1 ? ":" : "";
- ostringstream o;
- transform(endpoints.begin(), endpoints.end(), ostream_iterator<string>(o, sep),
- ::Ice::constMemFun(&Endpoint::toString));
- out << "endpoints = " << o.str();
}
+ out << "reason = " << ex;
}
}
- else
+
+ if(ref->instance->traceLevels()->location >= 1 && !endpoints.empty())
{
- cached = false;
+ if(cached)
+ {
+ trace("found endpoints in locator table", ref, endpoints);
+ }
+ else
+ {
+ trace("retrieved endpoints from locator, adding to locator table", ref, endpoints);
+ }
}
return endpoints;
}
+void
+IceInternal::LocatorInfo::clearObjectCache(const ReferencePtr& ref)
+{
+ if(ref->adapterId.empty() && ref->endpoints.empty())
+ {
+ ObjectPrx object = _table->removeProxy(ref->identity);
+
+ if(ref->instance->traceLevels()->location >= 2 && object && !object->__reference()->endpoints.empty())
+ {
+ trace("removed endpoints from locator table", ref, object->__reference()->endpoints);
+ }
+ }
+}
+
void
IceInternal::LocatorInfo::clearCache(const ReferencePtr& ref)
{
if(!ref->adapterId.empty())
{
- std::vector<EndpointPtr> endpoints = _adapterTable->remove(ref->adapterId);
- if(!endpoints.empty())
+ vector<EndpointPtr> endpoints = _table->removeAdapterEndpoints(ref->adapterId);
+ assert(!endpoints.empty());
+ if(ref->instance->traceLevels()->location >= 2)
+ {
+ trace("removed endpoints from locator table", ref, endpoints);
+ }
+ }
+ else if(ref->endpoints.empty())
+ {
+ ObjectPrx object = _table->removeProxy(ref->identity);
+ if(object)
{
- if(ref->instance->traceLevels()->location >= 1)
+ if(!object->__reference()->adapterId.empty())
{
- Trace out(ref->instance->logger(), ref->instance->traceLevels()->locationCat);
- out << "removed endpoints from locator table\n";
- out << "adapter = " << ref->adapterId;
- const char* sep = endpoints.size() > 1 ? ":" : "";
- ostringstream o;
- transform(endpoints.begin(), endpoints.end(), ostream_iterator<string>(o, sep),
- ::Ice::constMemFun(&Endpoint::toString));
- out << "endpoints = " << o.str();
+ clearCache(object->__reference());
+ }
+ else if(!object->__reference()->endpoints.empty())
+ {
+ if(ref->instance->traceLevels()->location >= 2)
+ {
+ trace("removed endpoints from locator table", ref, object->__reference()->endpoints);
+ }
}
}
}
}
+void
+IceInternal::LocatorInfo::trace(const string& msg, const ReferencePtr& ref, const vector<EndpointPtr>& endpoints)
+{
+ Trace out(ref->instance->logger(), ref->instance->traceLevels()->locationCat);
+ out << msg << '\n';
+ if(ref->adapterId.empty())
+ {
+ out << "object = " << identityToString(ref->identity) << '\n';
+ }
+ else
+ {
+ out << "adapter = " << ref->adapterId << '\n';
+ }
+
+ const char* sep = endpoints.size() > 1 ? ":" : "";
+ ostringstream o;
+ transform(endpoints.begin(), endpoints.end(), ostream_iterator<string>(o, sep),
+ Ice::constMemFun(&Endpoint::toString));
+ out << "endpoints = " << o.str();
+}
diff --git a/cpp/src/Ice/LocatorInfo.h b/cpp/src/Ice/LocatorInfo.h
index 6bbce7cb6f2..adc0d944ec9 100644
--- a/cpp/src/Ice/LocatorInfo.h
+++ b/cpp/src/Ice/LocatorInfo.h
@@ -44,31 +44,36 @@ private:
std::map< ::Ice::LocatorPrx, LocatorInfoPtr> _table;
std::map< ::Ice::LocatorPrx, LocatorInfoPtr>::iterator _tableHint;
- std::map< ::Ice::Identity, LocatorAdapterTablePtr> _adapterTables;
+ std::map< ::Ice::Identity, LocatorTablePtr> _locatorTables;
};
-class LocatorAdapterTable : public ::IceUtil::Shared, public ::IceUtil::Mutex
+class LocatorTable : public ::IceUtil::Shared, public ::IceUtil::Mutex
{
public:
- LocatorAdapterTable();
+ LocatorTable();
void clear();
- bool get(const std::string&, ::std::vector<EndpointPtr>&) const;
- void add(const std::string&, const ::std::vector<EndpointPtr>&);
- ::std::vector<EndpointPtr> remove(const std::string&);
+ bool getAdapterEndpoints(const std::string&, ::std::vector<EndpointPtr>&) const;
+ void addAdapterEndpoints(const std::string&, const ::std::vector<EndpointPtr>&);
+ ::std::vector<EndpointPtr> removeAdapterEndpoints(const std::string&);
+
+ bool getProxy(const ::Ice::Identity&, ::Ice::ObjectPrx&) const;
+ void addProxy(const ::Ice::Identity&, const Ice::ObjectPrx&);
+ Ice::ObjectPrx removeProxy(const ::Ice::Identity&);
private:
std::map<std::string, std::vector<EndpointPtr> > _adapterEndpointsMap;
+ std::map<Ice::Identity, Ice::ObjectPrx > _objectMap;
};
class LocatorInfo : public ::IceUtil::Shared, public ::IceUtil::Mutex
{
public:
- LocatorInfo(const ::Ice::LocatorPrx&, const LocatorAdapterTablePtr&);
+ LocatorInfo(const ::Ice::LocatorPrx&, const LocatorTablePtr&);
void destroy();
@@ -81,12 +86,15 @@ public:
std::vector<EndpointPtr> getEndpoints(const ReferencePtr&, bool&);
void clearCache(const ReferencePtr&);
+ void clearObjectCache(const ReferencePtr&);
private:
+ void trace(const std::string&, const ReferencePtr&, const std::vector<EndpointPtr>&);
+
::Ice::LocatorPrx _locator; // Immutable.
::Ice::LocatorRegistryPrx _locatorRegistry;
- LocatorAdapterTablePtr _adapterTable; // Immutable.
+ LocatorTablePtr _table; // Immutable.
};
}
diff --git a/cpp/src/Ice/LocatorInfoF.h b/cpp/src/Ice/LocatorInfoF.h
index 72d8098f773..a8ac62447e2 100644
--- a/cpp/src/Ice/LocatorInfoF.h
+++ b/cpp/src/Ice/LocatorInfoF.h
@@ -30,10 +30,10 @@ void incRef(LocatorInfo*);
void decRef(LocatorInfo*);
typedef Handle<LocatorInfo> LocatorInfoPtr;
-class LocatorAdapterTable;
-void incRef(LocatorAdapterTable*);
-void decRef(LocatorAdapterTable*);
-typedef Handle<LocatorAdapterTable> LocatorAdapterTablePtr;
+class LocatorTable;
+void incRef(LocatorTable*);
+void decRef(LocatorTable*);
+typedef Handle<LocatorTable> LocatorTablePtr;
}
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index 111fc2413a7..1adf85d05d3 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -334,8 +334,8 @@ Ice::Object::ice_removeFacet(const string& name)
if(p == _activeFacetMapHint)
{
- _activeFacetMap.erase(p);
- _activeFacetMapHint = ++p;
+ _activeFacetMap.erase(p++);
+ _activeFacetMapHint = p;
}
else
{
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index b97cd286eda..2165d01d46b 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -85,7 +85,7 @@ Ice::ObjectAdapterI::activate()
{
_locatorInfo->getLocatorRegistry()->setAdapterDirectProxy(_id, newDirectProxy(ident));
}
- catch(const Ice::AdapterNotRegisteredException&)
+ catch(const Ice::AdapterNotFoundException&)
{
NotRegisteredException ex(__FILE__, __LINE__);
ex.kindOfObject = "object adapter";
@@ -94,8 +94,7 @@ Ice::ObjectAdapterI::activate()
}
catch(const Ice::AdapterAlreadyActiveException&)
{
- AlreadyRegisteredException ex(__FILE__, __LINE__);
- ex.kindOfObject = "object adapter";
+ ObjectAdapterIdInUseException ex(__FILE__, __LINE__);
ex.id = _id;
throw ex;
}
@@ -313,8 +312,8 @@ Ice::ObjectAdapterI::removeServantLocator(const string& prefix)
if(p == _locatorMapHint)
{
- _locatorMap.erase(p);
- _locatorMapHint = ++p;
+ _locatorMap.erase(p++);
+ _locatorMapHint = p;
}
else
{
diff --git a/cpp/src/Ice/ObjectFactoryManager.cpp b/cpp/src/Ice/ObjectFactoryManager.cpp
index 59021c4fa6d..0594530dbb9 100644
--- a/cpp/src/Ice/ObjectFactoryManager.cpp
+++ b/cpp/src/Ice/ObjectFactoryManager.cpp
@@ -75,8 +75,8 @@ IceInternal::ObjectFactoryManager::remove(const string& id)
if(p == _factoryMapHint)
{
- _factoryMap.erase(p);
- _factoryMapHint = ++p;
+ _factoryMap.erase(p++);
+ _factoryMapHint = p;
}
else
{
diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp
index c21eaf82824..0d98b89b9e0 100644
--- a/cpp/src/Ice/Proxy.cpp
+++ b/cpp/src/Ice/Proxy.cpp
@@ -576,6 +576,11 @@ IceProxy::Ice::Object::__handleException(const LocalException& ex, int& cnt)
_delegate = 0;
}
+ if(_reference->locatorInfo)
+ {
+ _reference->locatorInfo->clearObjectCache(_reference);
+ }
+
++cnt;
TraceLevelsPtr traceLevels = _reference->instance->traceLevels();
@@ -634,6 +639,11 @@ IceProxy::Ice::Object::__rethrowException(const LocalException& ex)
_delegate = 0;
+ if(_reference->locatorInfo)
+ {
+ _reference->locatorInfo->clearObjectCache(_reference);
+ }
+
ex.ice_throw();
}
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp
index cfb380110cd..991a9cb660c 100644
--- a/cpp/src/Ice/ReferenceFactory.cpp
+++ b/cpp/src/Ice/ReferenceFactory.cpp
@@ -496,9 +496,9 @@ IceInternal::ReferenceFactory::create(const string& str)
if(!decodeString(s, beg, end, adapter) || adapter.size() == 0)
{
- ProxyParseException ex(__FILE__, __LINE__);
- ex.str = str;
- throw ex;
+ ProxyParseException ex(__FILE__, __LINE__);
+ ex.str = str;
+ throw ex;
}
}
}
diff --git a/cpp/src/Ice/UserExceptionFactoryManager.cpp b/cpp/src/Ice/UserExceptionFactoryManager.cpp
index 7a086b560c5..1c5ef0fa78d 100644
--- a/cpp/src/Ice/UserExceptionFactoryManager.cpp
+++ b/cpp/src/Ice/UserExceptionFactoryManager.cpp
@@ -75,8 +75,8 @@ IceInternal::UserExceptionFactoryManager::remove(const string& id)
if(p == _factoryMapHint)
{
- _factoryMap.erase(p);
- _factoryMapHint = ++p;
+ _factoryMap.erase(p++);
+ _factoryMapHint = p;
}
else
{