#include <connections.h>
Classes | |
struct | X |
Public Member Functions | |
unsigned long long | count (const string &ns) |
BSONObj | findOne (const string &ns, const Query &q, const BSONObj *fieldsToReturn=0, int queryOptions=0) |
bool | runCommand (const string &dbname, const BSONObj &cmd, BSONObj &info, int options=0) |
ScopedConn (string hostport) | |
void | setTimeout (double to) |
~ScopedConn () | |
Private Types | |
typedef map< string, ScopedConn::X * > | M |
Private Member Functions | |
DBClientConnection * | conn () |
Private Attributes | |
auto_ptr< scoped_lock > | connLock |
struct mongo::ScopedConn::X * | x |
Static Private Attributes | |
static M & | _map |
static mongo::mutex | mapMutex |
here we keep a single connection (with reconnect) for a set of hosts, one each, and allow one user at a time per host. if in use already for that host, we block. so this is an easy way to keep a 1-deep pool of connections that many threads can share.
thread-safe.
Example: { ScopedConn c("foo.acme.com:9999"); c->runCommand(...); }
throws exception on connect error (but fine to try again later with a new scopedconn object for same host).
Definition at line 43 of file connections.h.
typedef map<string,ScopedConn::X*> mongo::ScopedConn::M [private] |
Definition at line 77 of file connections.h.
mongo::ScopedConn::ScopedConn | ( | string | hostport | ) | [inline] |
throws assertions if connect failure etc.
Definition at line 82 of file connections.h.
mongo::ScopedConn::~ScopedConn | ( | ) | [inline] |
Definition at line 111 of file connections.h.
DBClientConnection* mongo::ScopedConn::conn | ( | ) | [inline, private] |
Definition at line 79 of file connections.h.
unsigned long long mongo::ScopedConn::count | ( | const string & | ns | ) | [inline] |
Definition at line 57 of file connections.h.
BSONObj mongo::ScopedConn::findOne | ( | const string & | ns, | |
const Query & | q, | |||
const BSONObj * | fieldsToReturn = 0 , |
|||
int | queryOptions = 0 | |||
) | [inline] |
Definition at line 60 of file connections.h.
bool mongo::ScopedConn::runCommand | ( | const string & | dbname, | |
const BSONObj & | cmd, | |||
BSONObj & | info, | |||
int | options = 0 | |||
) | [inline] |
Definition at line 54 of file connections.h.
void mongo::ScopedConn::setTimeout | ( | double | to | ) | [inline] |
Definition at line 63 of file connections.h.
M& mongo::ScopedConn::_map [static, private] |
Definition at line 78 of file connections.h.
auto_ptr<scoped_lock> mongo::ScopedConn::connLock [private] |
Definition at line 68 of file connections.h.
mongo::mutex mongo::ScopedConn::mapMutex [static, private] |
Definition at line 69 of file connections.h.
struct mongo::ScopedConn::X * mongo::ScopedConn::x [private] |