示例#1
0
        EndpointConnectionPool GetEndpointPool(TKey key, TimeSpan timeout)
        {
            EndpointConnectionPool result       = null;
            List <TItem>           itemsToClose = null;

            lock (ThisLock)
            {
                if (!endpointPools.TryGetValue(key, out result))
                {
                    itemsToClose = PruneIfNecessary();
                    result       = CreateEndpointConnectionPool(key);
                    endpointPools.Add(key, result);
                }
            }

            Fx.Assert(result != null, "EndpointPool must be non-null at this point");
            if (itemsToClose != null && itemsToClose.Count > 0)
            {
                // allocate half the remaining timeout for our g----ful shutdowns
                TimeoutHelper timeoutHelper = new TimeoutHelper(TimeoutHelper.Divide(timeout, 2));
                for (int i = 0; i < itemsToClose.Count; i++)
                {
                    result.CloseIdleConnection(itemsToClose[i], timeoutHelper.RemainingTime());
                }
            }

            return(result);
        }
示例#2
0
        private EndpointConnectionPool <TKey, TItem> GetEndpointPool(TKey key, TimeSpan timeout)
        {
            EndpointConnectionPool <TKey, TItem> pool = null;
            List <TItem> list = null;

            lock (this.ThisLock)
            {
                if (!this.endpointPools.TryGetValue(key, out pool))
                {
                    list = this.PruneIfNecessary();
                    pool = this.CreateEndpointConnectionPool(key);
                    this.endpointPools.Add(key, pool);
                }
            }
            if ((list != null) && (list.Count > 0))
            {
                TimeoutHelper helper = new TimeoutHelper(TimeoutHelper.Divide(timeout, 2));
                for (int i = 0; i < list.Count; i++)
                {
                    pool.CloseIdleConnection(list[i], helper.RemainingTime());
                }
            }
            return(pool);
        }