예제 #1
0
        /// <summary>
        /// 指定配置文件以初始化新实例
        /// </summary>
        /// <param name="configName"></param>
        public QueueServerPool(string configName)
        {
            if (string.IsNullOrEmpty(configName) == true)
            {
                throw new ArgumentNullException("configName");
            }
            //
            string topic         = "";
            ushort commitTimeout = 30;
            ushort timeout       = 5;

            //
            PoolMember[] poolMembers    = null;
            int          memberPoolSize = 800;
            int          hash           = 0;
            //
            var configuration = ServerConfig.GetConfiguration(configName);

            if (configuration.FileExist == true)
            {
                topic          = configuration.GetAttr("topic");
                commitTimeout  = configuration.GetAttrAsUInt16("commitTimeout", commitTimeout);
                timeout        = configuration.GetAttrAsUInt16("timeout", timeout);
                memberPoolSize = configuration.GetAttrAsInt32("memberPoolSize", memberPoolSize);
                hash           = configuration.GetAttrAsInt32("hash", 0);
                //
                if (string.IsNullOrEmpty(topic) == true)
                {
                    throw new ConfigException("no config topic from " + configName + ".config");
                }
                //
                var members = configuration.GetItems();
                var ipcount = members.Length;
                poolMembers = new PoolMember[ipcount];
                for (int i = 0; i < ipcount; i++)
                {
                    poolMembers[i] = new PoolMember(members[i].Ip, members[i].Port, topic, timeout, commitTimeout);
                }
            }
            else
            {
                topic          = Adf.ConfigHelper.GetSetting(configName + "Topic");
                commitTimeout  = Adf.ConfigHelper.GetSettingAsUInt16(configName + "CommitTimeout", commitTimeout);
                timeout        = Adf.ConfigHelper.GetSettingAsUInt16(configName + "Timeout", timeout);
                memberPoolSize = Adf.ConfigHelper.GetSettingAsInt(configName + "MemberPoolSize", memberPoolSize);
                //
                if (string.IsNullOrEmpty(topic) == true)
                {
                    throw new ConfigException("no config topic from application config");
                }
                //
                var config = (IpGroupSection)System.Configuration.ConfigurationManager.GetSection(configName);
                if (config == null)
                {
                    throw new Adf.ConfigException("No find configSection" + configName + " or " + configName + ".config");
                }

                var ipcount = config.IpList.Count;
                poolMembers = new PoolMember[ipcount];
                for (int i = 0; i < ipcount; i++)
                {
                    poolMembers[i] = new PoolMember(config.IpList[i].Ip, config.IpList[i].Port, topic, timeout, commitTimeout);
                }

                hash = config.Hash;
            }
            //
            this.Name           = configName;
            this.Topic          = topic;
            this.Timeout        = timeout;
            this.CommitTimeout  = commitTimeout;
            this.MemberPoolSize = memberPoolSize;
            //
            this.Pool = new Pool <QueueServerClient>(memberPoolSize, poolMembers, hash);
        }