public void Dispose()
 {
     if (_singleton != null)
     {
         Exception firstexp = null;
         foreach (var item in Pool)
         {
             try
             {
                 if (item.Value != null)
                 {
                     item.Value.Dispose();
                 }
             }
             catch (Exception exp)
             {
                 if (firstexp == null)
                 {
                     firstexp = exp;
                 }
             }
         }
         Pool       = new Dictionary <string, ProducterProvider>();
         _singleton = null;
         if (firstexp != null)
         {
             throw firstexp;
         }
     }
 }
        /// <summary>
        /// 从连接池中获取生产者
        /// </summary>
        /// <param name="config"></param>
        /// <param name="mqpath"></param>
        /// <returns></returns>
        public static ProducterProvider GetPool(BusinessMQConfig config, string mqpath)
        {
            //创建单例
            if (_singleton == null)
            {
                lock (_singletonlock)
                {
                    if (_singleton == null)
                    {
                        _singleton = new ProducterPoolHelper();
                        AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
                        AppDomain.CurrentDomain.ProcessExit  += CurrentDomain_ProcessExit;
                    }
                }
            }
            //查找生产者
            ProducterProvider provider = null; mqpath = mqpath.ToLower();

            if (Pool.ContainsKey(mqpath))
            {
                provider = Pool[mqpath];
            }
            if (provider == null)
            {
                lock (_poollock)
                {
                    if (Pool.ContainsKey(mqpath))
                    {
                        provider = Pool[mqpath];
                    }
                    if (provider == null)
                    {
                        var pt = new ProducterProvider();
                        pt.Config = config; pt.MQPath = mqpath;
                        pt.Open();
                        Pool.Add(mqpath, pt);
                        provider = Pool[mqpath];
                    }
                }
            }
            return(provider);
        }
Example #3
0
 /// <summary>
 /// 从连接池中获取生产者
 /// </summary>
 /// <param name="config"></param>
 /// <param name="mqpath"></param>
 /// <returns></returns>
 public static ProducterProvider GetPool(BusinessMQConfig config, string mqpath)
 {
     //创建单例
     if (_singleton == null)
     {
         lock (_singletonlock)
         {
             if (_singleton == null)
             {
                 _singleton = new ProducterPoolHelper();
                 AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
                 AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
             }
         }
     }
     //查找生产者
     ProducterProvider provider = null; mqpath = mqpath.ToLower();
     if (Pool.ContainsKey(mqpath))
     {
         provider = Pool[mqpath];
     }
     if (provider == null)
     {
         lock (_poollock)
         {
             if (Pool.ContainsKey(mqpath))
             {
                 provider = Pool[mqpath];
             }
             if (provider == null)
             {
                 var pt = new ProducterProvider();
                 pt.Config = config; pt.MQPath = mqpath;
                 pt.Open();
                 Pool.Add(mqpath, pt);
                 provider = Pool[mqpath];
             }
         }
     }
     return provider;
 }
Example #4
0
 public void Dispose()
 {
     if (_singleton != null)
     {
         Exception firstexp = null;
         foreach (var item in Pool)
         {
             try
             {
                 if (item.Value != null)
                     item.Value.Dispose();
             }
             catch (Exception exp)
             {
                 if (firstexp == null)
                     firstexp = exp;
             }
         }
         Pool = new Dictionary<string, ProducterProvider>();
         _singleton = null;
         if (firstexp != null)
             throw firstexp;
     }
 }