private void InitializeFromConfig(string configFilePath) { string message; LoadBalancerSection section; int[] weights = null; if (!ConfigurationLoader.TryLoadFromFile(configFilePath, out section, out message)) { log.WarnFormat( "Could not initialize LoadBalancer from configuration: Invalid configuration file {0}. Using default settings... ({1})", configFilePath, message); } if (section != null) { this.ReserveRatio = section.ReserveRatio; this.priorityDownThreshold = section.ValueDown; if (section.ValueDown == FeedbackLevel.Highest) { this.priorityDownThreshold = section.ValueUp == 0 ? section.ValueUp : section.ValueUp - 1; } this.PriorityUpThreshold = section.ValueUp; // load weights from config file & sort: var dict = new SortedDictionary <int, int>(); foreach (LoadBalancerWeight weight in section.LoadBalancerWeights) { dict.Add((int)weight.Level, weight.Value); } if (dict.Count == (int)FeedbackLevel.Highest + 1) { weights = new int[dict.Count]; dict.Values.CopyTo(weights, 0); log.InfoFormat("Initialized Load Balancer from configuration file: {0}", configFilePath); } else { log.WarnFormat( "Could not initialize LoadBalancer from configuration: {0} is invalid - expected {1} entries, but found {2}. Using default settings...", configFilePath, (int)FeedbackLevel.Highest + 1, dict.Count); } } if (weights == null) { weights = DefaultConfiguration.GetDefaultWeights(); } this.loadLevelWeights = weights; }
/// <summary> /// Initializes a new instance of the <see cref = "LoadBalancer{TServer}" /> class. Use default weights for each load level. /// </summary> public LoadBalancer() { this.random = new Random(); this.serverList = new Dictionary <TServer, ServerState>(); this.loadLevelWeights = DefaultConfiguration.GetDefaultWeights(); }
/// <summary> /// Initializes a new instance of the <see cref = "LoadBalancer{TServer}" /> class. Use default weights for each load level. /// </summary> public LoadBalancer() { this.random = new Random(); this.servers = new SortedDictionary <int, ServerBunch <TServer> >(); this.loadLevelWeights = DefaultConfiguration.GetDefaultWeights(); }