Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        // 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;
        }
Exemplo n.º 3
0
 public static void AddConnection(MongoConnection conn)
 {
     AddConnection(conn, false);
 }
Exemplo n.º 4
0
        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);
        }