public void ReleaseConnection(AbstractAdapter _adapter)
 {
     lock (connections)
     {
         if (connections.ContainsKey(_adapter.Guid))
         {
             PoolableConnection pc = connections[_adapter.Guid];
             pc.Release();
         }
         else
         {
             throw new Exception("Unknown adapter for this pool: GUID=" + _adapter.Guid.ToString());
         }
     }
 }
 private AbstractAdapter GetFreeConnection(bool _doLock)
 {
     foreach (Guid guid in connections.Keys)
     {
         PoolableConnection pc = connections[guid];
         if (pc.IsFree())
         {
             if (_doLock)
             {
                 pc.Lock();
             }
             if (pc.UsingCounter > 30)
             {
                 logger.Info("Recreate connection: " + Name);
                 pc.Adapter.Done();
                 pc.Adapter.Init();
                 pc.UsingCounter = 0;
             }
             pc.incUsingCounter();
             return(pc.Adapter);
         }
     }
     return(null);
 }
        public void Init()
        {
            if (!Parameters.ContainsKey(PoolSizeParam))
            {
                throw new Exception("" + PoolSizeParam + " parameter not found");
            }
            else
            {
                poolSize = Convert.ToInt32(Parameters[PoolSizeParam]);
            }
            if (!Parameters.ContainsKey(NameParam))
            {
                throw new Exception("" + NameParam + " parameter not found");
            }
            else
            {
                name = Parameters[NameParam];
            }
            if (!Parameters.ContainsKey(NameParam))
            {
                throw new Exception("" + AdapterTypeParam + " parameter not found");
            }
            else
            {
                adapterType = Type.GetType(Parameters[AdapterTypeParam]);
            }

            if (!Parameters.ContainsKey(PoolUserNameParam))
            {
                throw new Exception("" + PoolUserNameParam + " parameter not found");
            }
            else
            {
                poolUserName = Parameters[PoolUserNameParam];
            }

            if (!Parameters.ContainsKey(PoolPasswordParam))
            {
                throw new Exception("" + PoolPasswordParam + " parameter not found");
            }
            else
            {
                poolPassword = Parameters[PoolPasswordParam];
            }

            /*Поднимем соедиения для пула*/
            for (int i = 0; i < poolSize; i++)
            {
                AbstractAdapter adapter = (AbstractAdapter)Activator.CreateInstance(adapterType);
                adapter.Parameters = Parameters;
                PoolableConnection pc = new PoolableConnection();
                pc.Adapter = adapter;

                connections.Add(adapter.Guid, pc);

                adapter.Init();
            }

            /*Запустим обработчик очереди ожидания*/
            waitQueueProcessor          = new Thread(new ThreadStart(this.ProcessWaitQueue));
            waitQueueProcessor.Priority = ThreadPriority.AboveNormal;
            waitQueueProcessor.Name     = "WaitQueueProcessor";
            waitQueueProcessor.Start();
        }