예제 #1
0
        public void ReturnConnection(TKey key, TItem connection, bool connectionIsStillGood, TimeSpan timeout)
        {
            TimeoutHelper          timeoutHelper = new TimeoutHelper(timeout);
            EndpointConnectionPool endpointPool  = GetEndpointPool(key, timeoutHelper.RemainingTime());

            endpointPool.ReturnConnection(connection, connectionIsStillGood, timeoutHelper.RemainingTime());
        }
예제 #2
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);
        }
예제 #3
0
        public void AddConnection(TKey key, TItem connection, TimeSpan timeout)
        {
            TimeoutHelper          timeoutHelper = new TimeoutHelper(timeout);
            EndpointConnectionPool endpointPool  = GetEndpointPool(key, timeoutHelper.RemainingTime());

            endpointPool.AddConnection(connection, timeoutHelper.RemainingTime());
        }
예제 #4
0
        public TItem TakeConnection(EndpointAddress address, Uri via, TimeSpan timeout, out TKey key)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            key = this.GetPoolKey(address, via);
            EndpointConnectionPool endpointPool = GetEndpointPool(key, timeoutHelper.RemainingTime());

            return(endpointPool.TakeConnection(timeoutHelper.RemainingTime()));
        }
예제 #5
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);
        }