Exemple #1
0
        /// <summary>
        /// Gets the tuple space state
        /// </summary>
        /// <param name="Url">url of the server requesting the state</param>        /// <returns></returns>
        public TSpaceState GetTSpaceState(string Url)
        {
            TSpaceState smr = new TSpaceState();
            //Create operationID
            string id = TSMan.URL + "_" + (ViewUpdateCounter++);

            int seqNum;

            lock (AddingToView)
            {
                seqNum = GetSequenceNumber(id, null);
                AddingToView.Add(Url, seqNum);
            }


            //Wait to be head of queue
            WaitTurn(id);

            TSpaceAdvManager.RWL.AcquireWriterLock(Timeout.Infinite);

            //Get current list of servers
            List <string> serversUrl = TSMan.ServerView.DeepUrlsCopy();

            //Copy state

            smr.SequenceNumber = SequenceNumber;


            //its static, cant be accessed with instance
            smr.ProcessedRequests = TSpaceAdvManager.ProcessedRequests;
            smr.TupleSpace        = TSMan.GetTuples();

            //Send update view to all servers
            UpdateView(Url, id, serversUrl, AddingToView[Url], true);


            RemoveFromQueue(id);

            smr.MessageQueue = new List <Message>();

            foreach (Message msg2 in MessageQueue)
            {
                smr.MessageQueue.Add(Message.DeepClone(msg2));
            }

            TSMan.AddToView(Url);
            smr.ServerView = TSMan.GetTotalView();

            AddingToView.Remove(Url);
            TSpaceAdvManager.RWL.ReleaseWriterLock();

            return(smr);
        }