summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/SessionManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/SessionManager.cpp')
-rw-r--r--cpp/src/IceGrid/SessionManager.cpp93
1 files changed, 66 insertions, 27 deletions
diff --git a/cpp/src/IceGrid/SessionManager.cpp b/cpp/src/IceGrid/SessionManager.cpp
index 826195ed4ac..dcc4d500c2f 100644
--- a/cpp/src/IceGrid/SessionManager.cpp
+++ b/cpp/src/IceGrid/SessionManager.cpp
@@ -13,26 +13,14 @@
using namespace std;
using namespace IceGrid;
-SessionManager::SessionManager(const Ice::CommunicatorPtr& communicator) : _communicator(communicator)
+SessionManager::SessionManager(const Ice::CommunicatorPtr& communicator, const string& instanceName) :
+ _communicator(communicator), _instanceName(instanceName)
{
- if(communicator->getDefaultLocator())
+ Ice::LocatorPrx prx = communicator->getDefaultLocator();
+ if(prx)
{
- Ice::ObjectPrx prx = communicator->getDefaultLocator();
-
- //
- // Derive the query objects from the locator proxy endpoints.
- //
- Ice::EndpointSeq endpoints = prx->ice_getEndpoints();
- Ice::Identity id = prx->ice_getIdentity();
- id.name = "Query";
- QueryPrx query = QueryPrx::uncheckedCast(prx->ice_identity(id));
- for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p)
- {
- Ice::EndpointSeq singleEndpoint;
- singleEndpoint.push_back(*p);
- _queryObjects.push_back(QueryPrx::uncheckedCast(query->ice_endpoints(singleEndpoint)));
- }
-
+ Ice::Identity id;
+ id.category = instanceName;
id.name = "InternalRegistry-Master";
_master = InternalRegistryPrx::uncheckedCast(prx->ice_identity(id)->ice_endpoints(Ice::EndpointSeq()));
}
@@ -43,20 +31,68 @@ SessionManager::~SessionManager()
}
vector<QueryPrx>
-SessionManager::findAllQueryObjects()
+SessionManager::findAllQueryObjects(bool cached)
{
- vector<QueryPrx> queryObjects = _queryObjects;
- for(vector<QueryPrx>::const_iterator q = _queryObjects.begin(); q != _queryObjects.end(); ++q)
+ vector<QueryPrx> queryObjects;
{
- Ice::ConnectionPtr connection = (*q)->ice_getCachedConnection();
- if(connection)
+ Lock sync(*this);
+ if(cached && !_queryObjects.empty())
{
- try
+ return _queryObjects;
+ }
+ queryObjects = _queryObjects;
+ }
+
+ if(!cached)
+ {
+ for(vector<QueryPrx>::const_iterator q = queryObjects.begin(); q != queryObjects.end(); ++q)
+ {
+ Ice::ConnectionPtr connection = (*q)->ice_getCachedConnection();
+ if(connection)
+ {
+ try
+ {
+ connection->close(false);
+ }
+ catch(const Ice::LocalException&)
+ {
+ }
+ }
+ }
+ queryObjects.clear();
+ }
+
+ if(queryObjects.empty())
+ {
+ Ice::LocatorPrx locator = _communicator->getDefaultLocator();
+ if(locator)
+ {
+ Ice::Identity id;
+ id.category = _instanceName;
+ id.name = "Query";
+ QueryPrx query = QueryPrx::uncheckedCast(locator->ice_identity(id));
+ Ice::EndpointSeq endpoints = query->ice_getEndpoints();
+ if(endpoints.empty())
{
- connection->close(false);
+ try
+ {
+ Ice::ObjectPrx r = locator->findObjectById(id);
+ if(r)
+ {
+ endpoints = r->ice_getEndpoints();
+ }
+ }
+ catch(const Ice::Exception&)
+ {
+ // Ignore.
+ }
}
- catch(const Ice::LocalException&)
+
+ for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p)
{
+ Ice::EndpointSeq singleEndpoint;
+ singleEndpoint.push_back(*p);
+ queryObjects.push_back(QueryPrx::uncheckedCast(query->ice_endpoints(singleEndpoint)));
}
}
}
@@ -103,5 +139,8 @@ SessionManager::findAllQueryObjects()
}
}
while(proxies.size() != previousSize);
- return queryObjects;
+
+ Lock sync(*this);
+ _queryObjects.swap(queryObjects);
+ return _queryObjects;
}