Пример #1
0
        static void Main(string[] args)
        {
            TcpChannel channel;

            if (args.Count() > 0)
            {
                channel = new TcpChannel(Int32.Parse(args[0].Split(':')[2].Split('/')[0]));
            }
            else
            {
                channel = new TcpChannel(8088);
            }

            ChannelServices.RegisterChannel(channel, false);

            TupleSpaceXL server = new TupleSpaceXL(args[0]);

            //Set min delay and max delay
            if (args.Length == 3)
            {
                server.MinDelay = Int32.Parse(args[1]);
                server.MaxDelay = Int32.Parse(args[2]);
            }

            RemotingServices.Marshal(server, args[0].Split('/')[3], typeof(TupleSpaceXL));

            System.Console.WriteLine(args[0].Split('/')[3] + ": DIDA-TUPLE-XL Server Started!");
            System.Console.WriteLine("---------------");
            System.Console.WriteLine("# of tuples: " + server.ItemCount());
            System.Console.WriteLine("---------------");
            System.Console.WriteLine("<Enter> to exit...");
            System.Console.ReadLine();
        }
Пример #2
0
        public TupleSpaceXL(String path)
        {
            _view       = new View();
            _tupleSpace = new List <Tuple>();
            _lockList   = new LockList();
            MinDelay    = 0;
            MaxDelay    = 0;

            myPath = path;
            bool obtainedView = false;


            try
            {
                string[] file = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "../../../config/serverListXL.txt"));

                foreach (string i in file)
                {
                    if (i != path)
                    {
                        ServerList.Add(i);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                System.Console.WriteLine("Server List not Found");
                System.Console.WriteLine("Aborting...");
                System.Environment.Exit(1);
            }

            List <List <Tuple> > allTupleSpaces = new List <List <Tuple> >();

            foreach (string s in ServerList)
            {
                try
                {
                    Console.WriteLine("Trying to get view acesss: " + s);
                    TupleSpaceXL otherServer = (TupleSpaceXL)Activator.GetObject(typeof(TupleSpaceXL), s);
                    View         currentView = otherServer.AddView(myPath);
                    allTupleSpaces.Add(otherServer.GetTupleSpace());
                    if (_view.Version < currentView.Version)
                    {
                        _view = currentView;
                    }

                    obtainedView = true;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    Console.WriteLine(s + " is not alive");
                }
            }

            _tupleSpace = Intersection(allTupleSpaces).ToList();
            List <string> serversCopy = _view.Servers.ToList();

            foreach (string s in serversCopy)
            {
                if (s != myPath)
                {
                    try
                    {
                        TupleSpaceXL otherServer = (TupleSpaceXL)Activator.GetObject(typeof(TupleSpaceXL), s);
                        otherServer.SetTupleSpace(_tupleSpace);
                        otherServer.SetOnUpdate(false);
                    } catch (System.Net.Sockets.SocketException)
                    {
                        Console.WriteLine("** SETTING TS: Server at: " + s + " is dead but is in my view!");
                        _view.Remove(s);
                    }
                }
            }
            //Already have the new tuple space. Update process is now complete. Inform the clients of the new view.
            this.SetOnUpdate(false);

            //If no one replies to the view then i create my own view
            if (obtainedView == false)
            {
                _view = new View();
                _view.Add(myPath);
            }
        }