Example #1
0
            private void Free(string serviceName, JsonRpcConnection connection)
            {
                using (_shutdownLock.DisposableRead())
                {
                    if (!_enableConnectionPool || _shutdown)
                    {
                        // pool is not being used or
                        // manager is already shutdown
                        connection.Dispose();
                        return;
                    }

                    // queue must exist
                    var queue = _pools[serviceName];
                    if (queue.Count >= _maxPoolConnections)
                    {
                        // let the connection actually go away
                        connection.Dispose();
                        return;
                    }

                    // pool the connection
                    queue.Enqueue(connection);
                }
            }
Example #2
0
                public bool TryAcquire(out JsonRpcConnection connection)
                {
                    if (_queue.TryDequeue(out connection))
                    {
                        connection.SetPoolReclamation(this);
                        return(true);
                    }

                    return(false);
                }
Example #3
0
 internal void Free(ConcurrentQueue <JsonRpcConnection> pool, JsonRpcConnection connection)
 {
     using (_shutdownLock.DisposableRead())
     {
         // There is a race between checking the current pool capacity i nthe condition and
         // and queueing connections to the pool in the else branch.
         // The amount of pooled connections may thus exceed the capacity at times,
         // or some connections might not end up returned into the pool and reused.
         if (_isDisposed || pool.Count >= _capacityPerService)
         {
             connection.Dispose();
         }
         else
         {
             pool.Enqueue(connection);
         }
     }
 }
Example #4
0
 public void Return(JsonRpcConnection connection)
 => _owner.Free(_queue, connection);
 public PooledConnection(ConnectionManager pools, string serviceName, JsonRpcConnection connection)
 {
     _connectionManager = pools;
     _serviceName       = serviceName;
     _connection        = connection;
 }
Example #6
0
 public bool TryAcquire(out JsonRpcConnection connection)
 => _queue.TryDequeue(out connection);