/// <summary>
        /// Implement Ordering and In Order Proping Limit
        /// SelfNote: Cannot remember this function
        /// </summary>
        /// <param name="state"></param>
        /// <param name="senderId"></param>
        /// <returns></returns>
        public List <int> GetCandidateHosts(UtilizationStates state, int senderId)
        {
            lock (_lock)
            {
                var initial = _utilization
                              .Where(x => x.Value == state && x.Key != senderId)
                              .Select(x => x.Key)
                              .ToList();
                var    result = new Dictionary <int, int>();
                Random rand   = new Random();

                for (int i = 0; i < initial.Count; i++)
                {
                    int r = rand.Next(0, 100000);
                    if (result.ContainsKey(r))
                    {
                        i--;
                    }
                    else
                    {
                        result.Add(r, initial[i]);
                    }
                }
                return(result.OrderBy(x => x.Key).Select(x => x.Value).ToList());
                //return initial;
            }
        }
 public void SetUtilization(int id, UtilizationStates state)
 {
     lock (_lock)
     {
         _utilization[id] = state;
     }
 }
 protected override void TryToChangeSystemState(UtilizationStates hostState)
 {
     if (hostState == UtilizationStates.OverUtilization)
     {
         SendPushRequest();
     }
     else if (hostState == UtilizationStates.UnderUtilization)
     {
         SendPullRequest();
     }
 }
Пример #4
0
 protected override void TryToChangeSystemState(UtilizationStates hostState)
 {
     if (hostState == UtilizationStates.OverUtilization && _currentActionType == StrategyActionType.PushAction)
     {
         SendPushRequest();
     }
     else if (hostState == UtilizationStates.UnderUtilization && _currentActionType == StrategyActionType.PullAction)
     {
         SendPullRequest();
     }
 }
        /// <summary>
        /// Should Indicate the load of the host to be either High, Normal or Under
        /// Use Only CPU Time
        /// </summary>
        /// <returns></returns>
        public UtilizationStates CalculateTotalUtilizationState(double min, double max)
        {
            UtilizationStates cpu = GetFloatState(Volume, min, max);

            return(cpu);
        }
 public HostStateChange(int target, int sender, UtilizationStates state, double volume) :
     base(target, sender, MessageTypes.UtilizationStateChange)
 {
     State  = state;
     Volume = volume;
 }
Пример #7
0
        private void ReportUtilizationStateChange(UtilizationStates hoststate, double util)
        {
            HostStateChange change = new HostStateChange(0, this.MachineId, hoststate, util);

            _networkCard.SendMessage(change);
        }
 protected abstract void TryToChangeSystemState(UtilizationStates hostState);