Exemplo n.º 1
0
        /// <summary>checks, if availabe connections contain one, which is usable. If yes, removes the connection
        /// from the available and returns it. </summary>
        /// <remarks>If unusable connections are found, closes and removes them from available and all connections.</remarks>
        /// <returns>the connection, if found, otherwise null.</returns>
        protected virtual GiopClientConnection GetFromAvailable(string connectionKey)
        {
            GiopClientConnection result = null;
            IList available             = (IList)m_availableConnections[connectionKey];

            while ((available != null) && (available.Count > 0))
            {
                GiopClientConnection con = (GiopClientConnection)available[available.Count - 1];
                available.RemoveAt(available.Count - 1);
                if (con.CanBeUsedForNextRequest())
                {
                    result = con;
                    break;
                }
                else
                {
                    try {
                        if (con.CanCloseConnection())
                        {
                            con.CloseConnection();
                        }
                    } catch (Exception) {
                    } finally {
                        UnregisterConnection(connectionKey, con);
                    }
                }
            }
            return(result);
        }