Beispiel #1
0
        public ConnectionPoolEntry GetConnection(string connectionString, AuthData authData)
        {
            var key = connectionString;

            ConnectionPoolEntry rv = null;

            avalableConnections.AddOrUpdate(key, k => new ConcurrentStack <ConnectionPoolEntry>(), (k, c) =>
            {
                while (c.TryPop(out var entry))
                {
                    //if we discover that the entry has expired, dispose of it
                    //this typically happens when the entry uses BEARER auth and its token
                    //has expired (or is about to).
                    if (entry.ValidTo > DateTime.Now.Subtract(TimeSpan.FromMinutes(1)))
                    {
                        entry.Connection.Dispose();
                        continue;
                    }

                    rv = entry;
                    break;
                }

                return(c);
            });
Beispiel #2
0
        public void ReturnConnection(ConnectionPoolEntry entry)
        {
            var key = entry.ConnectionString;

            entry.RecordCheckIn();
            avalableConnections[key].Push(entry);
        }