public static void AddConnection(MongoConnection conn, bool updateCount) { lock (_availableConnections) { if (_availableConnections.Count < MAX_POOL_SIZE) { if (conn != null) { if (conn.Connected) { _availableConnections.Enqueue(conn); } else { conn.Close(); } } } else { conn.Close(); } } if (updateCount) Interlocked.Decrement(ref _checkedOut); }
// TODO add in replication support here for left/right/slave public static void Initialize() { if (_initialized) return; if (_availableConnections == null) _availableConnections = new Queue<MongoConnection>(); for (int i = 0; i < MIN_POOL_SIZE; i++) { MongoConnection conn = new MongoConnection(); AddConnection(conn); } _initialized = true; }
public static void AddConnection(MongoConnection conn) { AddConnection(conn, false); }
private static MongoConnection OpenConnection() { if (_checkedOut < MAX_POOL_SIZE) { MongoConnection conn = new MongoConnection(); AddConnection(conn, true); return conn; } throw new Exception("Connection pool has reached it's limit: " + MAX_POOL_SIZE); }