コード例 #1
0
        private void AddToHoldQueue(string id, int nr, string req, List <string> tuple)
        {
            /*Object[] queue = new Object[5];
             * //Action a;
             * queue[0] = req;
             * queue[1] = nr;
             * queue[2] = id;
             * queue[3] = false;
             * queue[4] = tuple;   */
            XlObj queue = new XlObj(req, nr, id, false, tuple);

            CheckPosition(nr, queue);
        }
コード例 #2
0
        public List <string> XlConfirmation(string id, int nr)
        {
            if (a != nr)
            {
                a = Math.Max(nr, a);
            }

            CheckChange(id, nr);

            while (true)
            {
                if (((XlObj)holdBackQueue[0]).Agreed && nr == ((XlObj)holdBackQueue[0]).Nr)
                {
                    deliverQueue.Enqueue(holdBackQueue[0]);
                    holdBackQueue.Remove(holdBackQueue[0]);
                    break;
                }
            }

            List <string> result = null;
            XlObj         aux1   = (XlObj)deliverQueue.Peek();

            while (!id.Equals(aux1.Id) || nr != aux1.Nr)
            {
                aux1 = (XlObj)deliverQueue.Peek();
            }

            List <string> aux;

            if ((((XlObj)deliverQueue.Peek()).Req).Equals("Add"))
            {
                aux = ((XlObj)deliverQueue.Dequeue()).Tuple;
                Add(aux);
            }
            else if ((((XlObj)deliverQueue.Peek()).Req).Equals("Read"))
            {
                aux    = ((XlObj)deliverQueue.Dequeue()).Tuple;
                result = Read(aux);
            }
            else if ((((XlObj)deliverQueue.Peek()).Req).Equals("Take"))
            {
                aux    = ((XlObj)deliverQueue.Dequeue()).Tuple;
                result = Take(aux);
            }

            return(result);
        }
コード例 #3
0
        private void CheckPosition(int nr, XlObj queue)
        {
            int aux = 0;

            foreach (XlObj obj in holdBackQueue)
            {
                if (obj.Nr < nr)
                {
                    holdBackQueue.Insert(aux, queue);
                    break;
                }
                else if (obj.Nr == nr)
                {
                    if (String.CompareOrdinal(obj.Id, queue.Id) > 0) //compares id for tiebreaker
                    {
                        holdBackQueue.Insert(aux, queue);
                        break;
                    }
                }
                aux++;
            }/*
              * int i = 0;
              * for(i = 0; i < holdBackQueue.Count; i++)
              * {
              * if ((int)holdBackQueue[i][1] < nr)
              * {
              *     holdBackQueue.Insert(i, queue);
              *     break;
              * }
              * else if ((int)holdBackQueue[i][1] == nr)
              * {
              *     if (String.CompareOrdinal((string)holdBackQueue[0][2], (string)queue[2]) > 0) //compares id for tiebreaker
              *     {
              *         holdBackQueue.Insert(i, queue);
              *         break;
              *     }
              * }
              * //aux++;
              * }*/

            if (aux == holdBackQueue.Count)
            {
                holdBackQueue.Add(queue);
            }
        }
コード例 #4
0
        private void CheckChange(string id, int nr)
        {
            XlObj aux = null;

            foreach (XlObj obj in holdBackQueue)
            {
                if (obj.Id.Equals(id))
                {
                    obj.Agreed = true;
                    if (obj.Nr != nr)
                    {
                        aux = obj;
                        holdBackQueue.Remove(obj);
                    }
                    break;
                }
            }

            /*
             * for(int i = 0; i < holdBackQueue.Count; i++)
             * {
             *  if (((string)holdBackQueue[i][2]).Equals(id))
             *  {
             *      holdBackQueue[i][3] = true;
             *      if ((int)holdBackQueue[i][1] != nr)
             *      {
             *          aux = holdBackQueue[i];
             *          holdBackQueue.Remove(holdBackQueue[i]);
             *      }
             *      break;
             *  }
             * }*/
            if (aux != null)
            {
                CheckPosition(nr, aux);
            }
        }