Exemplo n.º 1
0
        public static IModelWrapper GetOrCreateChannel(ConnectionFactory connFactory)
        {
            if (connFactory == null)
            {
                throw new ArgumentNullException("参数connFactory不能为空,请检查参数");
            }

            GetConnlockObj.EnterUpgradeableReadLock();///若线程用光了,得写一个连接线程,所以这里用可升级锁
            IModelWrapper model = null;

            try
            {
                foreach (var item in ConnList)
                {
                    model = item.GetOrCreateChannel();
                    if (model != null)
                    {
                        return(model);
                    }
                }
                if (model == null)
                {
                    //创建connection对象
                    ConnectionWrapper conn = CreateConnection(connFactory);
                    return(conn.GetOrCreateChannel());
                }
            }
            finally
            {
                GetConnlockObj.ExitUpgradeableReadLock();
            }
            return(null);
        }
Exemplo n.º 2
0
        public IModelWrapper GetOrCreateChannel()
        {
            GetChannellockObj.EnterUpgradeableReadLock();///若线程用光了,得写一个连接线程,所以这里用可升级锁
            try
            {
                IModelWrapper Channel = ListChannel.Find(p => p.IsBusy == false);

                if (Channel != null)
                {
                    Channel.IsBusy = true;
                    return(Channel);
                }
                else if (Channel == null && ListChannel.Count < Conn.ChannelMax)
                {
                    return(CreateChannel());
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                GetChannellockObj.ExitUpgradeableReadLock();
            }
        }
Exemplo n.º 3
0
        public IModelWrapper GetOrCreateChannel()
        {
            IModelWrapper result = this.ChannelPool.GetOrCreateChannel();

            if (result != null)
            {
                IdleTime = default(DateTime);
            }

            return(result);
        }
Exemplo n.º 4
0
        internal void InnerRemove(IModelWrapper item)
        {
            GetChannellockObj.EnterWriteLock();
            try
            {
                ListChannel.Remove(item);

                item.Dispose();
            }
            finally
            {
                GetChannellockObj.ExitWriteLock();
            }
        }
Exemplo n.º 5
0
        private IModelWrapper CreateChannel()
        {
            GetChannellockObj.EnterWriteLock();
            try
            {
                IModel channel = Conn.CreateModel();

                IModelWrapper ModelWrapper = new IModelWrapper(channel);

                ListChannel.Add(ModelWrapper);

                return(ModelWrapper);
            }
            finally
            {
                GetChannellockObj.ExitWriteLock();
            }
        }