private void ModifyWeights( AggregatedClusterStatistic aggregatedClusterStatistic, IRelativeWeightCalculator relativeWeightCalculator, IWeightsNormalizer weightsNormalizer, IWeights weights) { var newWeights = new Dictionary <Uri, Weight>(aggregatedClusterStatistic.Replicas.Count); var statisticCollectedTimestamp = aggregatedClusterStatistic.Cluster.Timestamp; var relativeMaxWeight = 0d; foreach (var(replica, replicaStatistic) in aggregatedClusterStatistic.Replicas) { var previousWeight = weights.Get(replica, settings.WeightsTTL) ?? new Weight(settings.InitialWeight, statisticCollectedTimestamp - settings.WeightUpdatePeriod); var newReplicaWeight = relativeWeightCalculator .Calculate(aggregatedClusterStatistic.Cluster, replicaStatistic, previousWeight, settings); newWeights.Add(replica, newReplicaWeight); if (relativeMaxWeight < newReplicaWeight.Value) { relativeMaxWeight = newReplicaWeight.Value; } } weightsNormalizer.Normalize(newWeights, relativeMaxWeight); LogWeights(weights, newWeights); weights.Update(newWeights, settings); }
public ClusterState( IRelativeWeightCalculator relativeWeightCalculator = null, IRawClusterStatistic rawClusterStatistic = null, ITimeProvider timeProvider = null, IStatisticHistory statisticHistory = null, IWeightsNormalizer weightsNormalizer = null, IWeights weights = null) { IsUpdatingNow = new AtomicBoolean(false); TimeProvider = timeProvider ?? new TimeProvider(); RelativeWeightCalculator = relativeWeightCalculator ?? new RelativeWeightCalculator(); Weights = weights ?? new Weights(); WeightsNormalizer = weightsNormalizer ?? new WeightsNormalizer(); CurrentStatistic = rawClusterStatistic ?? new RawClusterStatistic(); StatisticHistory = statisticHistory ?? new StatisticsHistory(); LastUpdateTimestamp = TimeProvider.GetCurrentTime(); }