Example #1
0
        private void Multicast(string subject, AsyncCallback asyncCallback, string operation)
        {
            List <string> servers = TSMan.ServerView.GetUrls();;

            foreach (string serverUrl in servers)
            {
                TSpaceAdvServerXL server = (TSpaceAdvServerXL)Activator.GetObject(typeof(ITSpaceServer), serverUrl);
                try
                {
                    if (operation.Equals("AddToView"))
                    {
                        UpdateViewDel remoteDel = new UpdateViewDel(server.AddToView);
                        remoteDel.BeginInvoke(subject, asyncCallback, null);
                    }

                    else if (operation.Equals("RemoveFromView"))
                    {
                        UpdateViewDel remoteDel = new UpdateViewDel(server.RemoveFromView);
                        remoteDel.BeginInvoke(subject, asyncCallback, null);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to send");
                }
            }
        }
Example #2
0
        private void TryRemoveFromView(string deadURL)
        {
            lock (SuspectedDead)
            {
                if (SuspectedDead.ContainsKey(deadURL) || !TSMan.ServerView.Contains(deadURL))
                {
                    return;
                }
                SuspectedDead.Add(deadURL, 0);
                TSpaceAdvManager.RWL.AcquireWriterLock(Timeout.Infinite);
            }
            Console.WriteLine("Suspected dead " + deadURL);
            List <string> servers = new List <string>();

            for (int i = 0; i < TSMan.ServerView.GetUrls().Count; i++)
            {
                servers.Add(TSMan.ServerView.GetUrls()[i]);
            }

            Monitor.Enter(SuspectedDead);
            while (SuspectedDead.ContainsKey(deadURL) &&
                   (SuspectedDead[deadURL] < TSMan.Quorum(TSMan.ServerView.GetUrls().Count)))
            {
                TSpaceAdvServerXL server;
                DeleteFromViewDel del;
                AsyncCallback     callback = new AsyncCallback(TryRemoveFromViewCallback);
                foreach (string serverUrl in servers)
                {
                    server = (TSpaceAdvServerXL)Activator.GetObject(typeof(ITSpaceServer), serverUrl);
                    del    = new DeleteFromViewDel(server.TryConnection);
                    try
                    {
                        del.BeginInvoke(deadURL, false, callback, deadURL);
                    }
                    catch (Exception) { }
                }
                //Releases until it acquires the lock or timeout elapses
                Monitor.Wait(SuspectedDead, 2000);
            }
            Monitor.Exit(SuspectedDead);

            Console.WriteLine("Confirmed Dead " + deadURL);

            lock (SuspectedDead)
            {
                //Already has been removed
                if (!SuspectedDead.ContainsKey(deadURL))
                {
                    Console.WriteLine("Already has been removed");
                    TSpaceAdvManager.RWL.ReleaseWriterLock();
                    return;
                }
            }


            //TODO add variable refering current remove
            //Only inc ack if in that remove
            Console.WriteLine("Entering wait");
            Monitor.Enter(RemoveFromViewLock);
            UpdateViewCounter = 0;
            while (UpdateViewCounter < TSMan.Quorum(servers.Count))
            {
                TSpaceAdvServerXL server;
                UpdateViewDel     del;

                AsyncCallback callback = new AsyncCallback(RemoveFromViewCallback);

                List <string> testServers = new List <string>(servers);
                foreach (string serverUrl in testServers)
                {
                    server = (TSpaceAdvServerXL)Activator.GetObject(typeof(ITSpaceServer), serverUrl);
                    del    = new UpdateViewDel(server.RemoveFromView);
                    try
                    {
                        del.BeginInvoke(deadURL, callback, serverUrl);
                    }
                    catch (Exception) { }
                }

                Monitor.Wait(RemoveFromViewLock, 2000);
            }
            Monitor.Exit(RemoveFromViewLock);

            TSpaceAdvManager.RWL.ReleaseWriterLock();
            Console.WriteLine("Confirm remove of server " + deadURL + " => " + UpdateViewCounter);
        }