DBClientBase* DBConnectionPool::_finishCreate( const string& host , DBClientBase* conn ){ { scoped_lock L(_mutex); PoolForHost& p = _pools[host]; p.createdOne(); } onCreate( conn ); onHandedOut( conn ); return conn; }
DBClientBase* DBConnectionPool::get(const ConnectionString& url) { DBClientBase * c = _get( url.toString() ); if ( c ){ onHandedOut( c ); return c; } string errmsg; c = url.connect( errmsg ); uassert( 13328 , _name + ": connect failed " + url.toString() + " : " + errmsg , c ); return _finishCreate( url.toString() , c ); }
DBClientBase* DBConnectionPool::get(const string& host) { DBClientBase * c = _get( host ); if ( c ){ onHandedOut( c ); return c; } string errmsg; ConnectionString cs = ConnectionString::parse( host , errmsg ); uassert( 13071 , (string)"invalid hostname [" + host + "]" + errmsg , cs.isValid() ); c = cs.connect( errmsg ); uassert( 11002 , _name + ": connect failed " + host + " : " + errmsg , c ); return _finishCreate( host , c ); }
DBClientBase* DBConnectionPool::get(const string& host) { DBClientBase * c = _get( host ); if ( c ) { onHandedOut( c ); return c; } string errmsg; ConnectionString cs = ConnectionString::parse( host , errmsg ); uassert( 13071 , (string)"invalid hostname [" + host + "]" + errmsg , cs.isValid() ); c = cs.connect( errmsg ); if ( ! c ) throw SocketException( SocketException::CONNECT_ERROR , host , 11002 , str::stream() << _name << " error: " << errmsg ); return _finishCreate( host , c ); }
DBClientBase* DBConnectionPool::_finishCreate( const string& host , double socketTimeout , DBClientBase* conn ) { { scoped_lock L(_mutex); PoolForHost& p = _pools[PoolKey(host,socketTimeout)]; p.createdOne( conn ); } try { onCreate( conn ); onHandedOut( conn ); } catch ( std::exception& e ) { delete conn; throw; } return conn; }
DBClientBase* DBConnectionPool::get(const ConnectionString& url, double socketTimeout) { DBClientBase * c = _get( url.toString() , socketTimeout ); if ( c ) { try { onHandedOut( c ); } catch ( std::exception& ) { delete c; throw; } return c; } string errmsg; c = url.connect( errmsg, socketTimeout ); uassert( 13328 , _name + ": connect failed " + url.toString() + " : " + errmsg , c ); return _finishCreate( url.toString() , socketTimeout , c ); }
DBClientBase* DBConnectionPool::get(const string& host) { boostlock L(poolMutex); PoolForHost *&p = pools[host]; if ( p == 0 ) p = new PoolForHost(); if ( p->pool.empty() ) { string errmsg; DBClientBase *c; if( host.find(',') == string::npos ) { DBClientConnection *cc = new DBClientConnection(true); log(2) << "creating new connection for pool to:" << host << endl; if ( !cc->connect(host.c_str(), errmsg) ) { delete cc; uassert( (string)"dbconnectionpool: connect failed" + host , false); return 0; } c = cc; onCreate( c ); } else { DBClientPaired *p = new DBClientPaired(); if( !p->connect(host) ) { delete p; uassert( (string)"dbconnectionpool: connect failed [2] " + host , false); return 0; } c = p; } return c; } DBClientBase *c = p->pool.top(); p->pool.pop(); onHandedOut( c ); return c; }