void NodeSessionManager::replicaInit(const InternalRegistryPrxSeq& replicas) { Lock sync(*this); if(_destroyed) { return; } // // Initialize the set of replicas known by the master. // _replicas.clear(); for(InternalRegistryPrxSeq::const_iterator p = replicas.begin(); p != replicas.end(); ++p) { _replicas.insert((*p)->ice_getIdentity()); addReplicaSession(*p)->tryCreateSession(false); } }
void NodeSessionManager::createdSession(const NodeSessionPrx& session) { bool activated; { Lock sync(*this); activated = _activated; } // // Synchronize the servers if the session is active and if the // node adapter has been activated (otherwise, the servers will be // synced after the node adapter activation, see activate()). // // We also set the replica observer to receive notifications of // replica addition/removal. // if(session && activated) { try { session->setReplicaObserver(_node->getProxy()); syncServers(session); } catch(const Ice::LocalException&) { } return; } // // If there's no master session or if the node adapter isn't // activated yet, we retrieve a list of the replicas either from // the master or from the known replicas (the ones configured with // Ice.Default.Locator) and we try to establish connections to // each of the replicas. // InternalRegistryPrxSeq replicas; if(session) { assert(!activated); // The node adapter isn't activated yet so // we're not subscribed yet to the replica // observer topic. try { replicas = _thread->getRegistry()->getReplicas(); } catch(const Ice::LocalException&) { } } else { vector<Ice::AsyncResultPtr> results; for(vector<QueryPrx>::const_iterator q = _queryObjects.begin(); q != _queryObjects.end(); ++q) { results.push_back((*q)->begin_findAllObjectsByType(InternalRegistry::ice_staticId())); } map<Ice::Identity, Ice::ObjectPrx> proxies; for(vector<Ice::AsyncResultPtr>::const_iterator p = results.begin(); p != results.end(); ++p) { QueryPrx query = QueryPrx::uncheckedCast((*p)->getProxy()); if(isDestroyed()) { return; } try { Ice::ObjectProxySeq prxs = query->end_findAllObjectsByType(*p); for(Ice::ObjectProxySeq::const_iterator q = prxs.begin(); q != prxs.end(); ++q) { // // NOTE: We might override a good proxy here! We could improve this to make // sure that we don't override the proxy for replica N if that proxy was // obtained from replica N. // proxies[(*q)->ice_getIdentity()] = *q; } } catch(const Ice::LocalException&) { // IGNORE } } for(map<Ice::Identity, Ice::ObjectPrx>::const_iterator q = proxies.begin(); q != proxies.end(); ++q) { replicas.push_back(InternalRegistryPrx::uncheckedCast(q->second)); } } vector<NodeSessionKeepAliveThreadPtr> sessions; { Lock sync(*this); if(_destroyed) { return; } // // If the node adapter was activated since we last check, we don't need // to initialize the replicas here, it will be done by replicaInit(). // if(!session || !_activated) { _replicas.clear(); for(InternalRegistryPrxSeq::const_iterator p = replicas.begin(); p != replicas.end(); ++p) { if((*p)->ice_getIdentity() != _master->ice_getIdentity()) { _replicas.insert((*p)->ice_getIdentity()); NodeSessionKeepAliveThreadPtr session = addReplicaSession(*p); session->tryCreateSession(false); sessions.push_back(session); } } } } // // Wait for the creation. It's important to wait to ensure that // the replica sessions are created before the node adapter is // activated. // IceUtil::Time before = IceUtil::Time::now(); for(vector<NodeSessionKeepAliveThreadPtr>::const_iterator p = sessions.begin(); p != sessions.end(); ++p) { if(isDestroyed()) { return; } IceUtil::Time timeout = IceUtil::Time::seconds(5) - (IceUtil::Time::now() - before); if(timeout <= IceUtil::Time()) { break; } (*p)->tryCreateSession(true, timeout); } }