Ejemplo n.º 1
0
        public void updateReplicas(IDictionary <string, List <List <Field> > > tupleSpace2)
        {
            List <string> serversDown = new List <string>();

            Console.WriteLine("IM OBJECT   " + uri.Port + "and im updating:------------");
            foreach (string s in urls.Keys)
            {
                Console.WriteLine("Server   " + s);
            }
            Console.WriteLine("--------------------------------------------------------");
            List <Task> TaskList = new List <Task>();
            Task        t        = null;

            foreach (string s in urls.Keys)
            {
                if (urls[s].Equals(uri))
                {
                    continue;
                }
                String            reference = "tcp://localhost:" + urls[s].Port + "/MyRemoteObjectName/" + s;
                MyRemoteInterface obj       = (MyRemoteInterface)Activator.GetObject(
                    typeof(MyRemoteInterface), reference);

                t = new Task(() =>
                {
                    try
                    {
                        obj.update(tupleSpace2);
                    }
                    catch (Exception e)
                    {
                        if (e is RemotingException || e is SocketException)
                        {
                            serversDown.Add(s);
                        }
                    }
                });
                t.Start();
                TaskList.Add(t);
            }
            Task.WaitAll(TaskList.ToArray());
            foreach (string down in serversDown)
            {
                urls.Remove(down);
            }
        }