Esempio n. 1
0
 private void DestroyUnusedConnections(Object state)
 {
     lock (this) {
         bool hasDestroyedConnections = false;
         foreach (DictionaryEntry de in m_availableConnections)
         {
             IList list = (IList)de.Value;
             GiopClientConnection toDestroy = GetConToDestroy(list);
             if (toDestroy != null)
             {
                 list.Remove(toDestroy);
                 UnregisterConnection((string)de.Key, toDestroy);
                 try {
                     toDestroy.CloseConnection();
                 } catch (ThreadAbortException) {
                     throw;
                 } catch (Exception) {
                     // ignore
                 }
                 hasDestroyedConnections = true;
             }
         }
         if (hasDestroyedConnections)
         {
             Monitor.PulseAll(this); // inform all threads waiting on changes in connections
         }
     }
 }
Esempio n. 2
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);
        }