예제 #1
0
파일: RBN.cs 프로젝트: rozh1/cluster_emul
 /// <summary>
 /// Размещает запросы в очереди по серверам
 /// </summary>
 /// <param name="k">Количество мест в очереди сервера</param>
 void QueueAllocation(int k)
 {
     for (int j = 0; j < k; j++)
     {
         for (int i = 0; i < Clusters.Count; i++)
         {
             cluster cl = (cluster)Clusters[i];
             if ((cl.GetQueueCount() < 2) && local_queue.Count > 0)
             {
                 int[] arr = (int[])local_queue.Peek();
                 //если запрос из своего региона
                 if (arr[2] == Region_num)
                 {
                     cluster_client cl_w = (cluster_client)Clients[arr[1]];
                     if (CURENT_TOTAL_W > 0)
                     {
                         CURENT_TOTAL_W -= cl_w.GetWieghtQuery();
                     }
                 }
                 else
                 {
                     if (CURENT_TOTAL_W > 0)
                     {
                         CURENT_TOTAL_W -=
                             cluster_query.GetQueryWeightByNum(arr[0]);
                     }
                 }
                 cl.QueueAdd((int[])local_queue.Dequeue());
                 cl.SetQueryTime();
             }
         }
     }
 }
예제 #2
0
파일: RBN.cs 프로젝트: rozh1/cluster_emul
 int kol_iterations = 1; //Количество итераций вызова функции QueueRecive()
 /// <summary>
 /// Получение новых запросов от клиентов и запись в очередь РБН
 /// </summary>
 void QueueRecive()
 {
     for (int i = last_client_num; i < Clients.Count; i++, last_client_num++)
     {
         cluster_client cl = (cluster_client)Clients[i];
         if (!cl.request_sended && local_queue.Count < local_queue_length)
         {
             cl.NewRequest(time);
             CURENT_TOTAL_W += cl.GetWieghtQuery();
             local_queue.Enqueue(cl.GetParametrs());
         }
         if (QueueIsFull())
         {
             break;
         }
     }
     if (last_client_num == Clients.Count)
     {
         last_client_num = 0;
         if (kol_iterations++ <= 2)
         {
             QueueRecive();
         }
         else
         {
             kol_iterations = 1;
         }
     }
 }
예제 #3
0
파일: RBN.cs 프로젝트: rozh1/cluster_emul
 /// <summary>
 /// Отправляет первый элемент очереди РБН
 /// </summary>
 /// <returns>массив с информацией о запросе и клиенте</returns>
 public int[] GetQueryFromQueue()
 {
     int[] arr = (int[])local_queue.Peek();
     if (arr[2] == Region_num)
     {
         cluster_client cl_w = (cluster_client)Clients[arr[1]];
         if (CURENT_TOTAL_W > 0)
         {
             CURENT_TOTAL_W -= cl_w.GetWieghtQuery();
         }
     }
     else
     {
         if (CURENT_TOTAL_W > 0)
         {
             CURENT_TOTAL_W -= cluster_query.GetQueryWeightByNum(arr[0]);
         }
     }
     return((int[])local_queue.Dequeue());
 }
예제 #4
0
파일: RBN.cs 프로젝트: rozh1/cluster_emul
        /// <summary>
        /// Отправляет последний элемент очереди РБН
        /// </summary>
        /// <returns>>массив с информацией о запросе и клиенте</returns>
        public int[] GetLastQueryFromQueue()
        {
            object first   = local_queue.Peek();
            object current = null;

            while (true)
            {
                current = local_queue.Dequeue();
                if (local_queue.Count == 0)
                {
                    break;
                }
                if (local_queue.Peek() == first)
                {
                    break;
                }
                local_queue.Enqueue(current);
            }

            int[] arr = (int[])current;
            if (arr[2] == Region_num)
            {
                cluster_client cl_w = (cluster_client)Clients[((int[])current)[1]];
                if (CURENT_TOTAL_W > 0)
                {
                    CURENT_TOTAL_W -= cl_w.GetWieghtQuery();
                }
            }
            else
            {
                if (CURENT_TOTAL_W > 0)
                {
                    CURENT_TOTAL_W -= cluster_query.GetQueryWeightByNum(arr[0]);
                }
            }
            return((int[])current);
        }