Esempio n. 1
0
        public ServerApiSmr(string id, string url, int minDelay, int maxDelay, List <string> serversUrls)
        {
            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();

            this.Id = id;
            Hashtable props = new Hashtable();
            int       port  = DU.ExtractPortFromUrl(url);

            props["port"]    = port;
            props["timeout"] = 1000;
            Channel          = new TcpChannel(props, null, provider);
            Nodes            = new List <Node>();

            ChannelServices.RegisterChannel(Channel, false);

            foreach (string serverUrl in serversUrls)
            {
                if (port != DU.ExtractPortFromUrl(serverUrl))
                {
                    Nodes.Add((Node)Activator.GetObject(typeof(Node), serverUrl));
                }
            }

            Node node = new Node(id, url, Nodes, minDelay, maxDelay);

            RemotingServices.Marshal(node, DU.ExtractObjectNameFromUrl(url));
        }
Esempio n. 2
0
        //TODO: change this url. it should be the client's
        public ClientSmrApi(string id, string url, string scriptFile, List <string> serversUrls)
        {
            this.Id  = id;
            this.Seq = 0;
            int port = DU.ExtractPortFromUrl(url);

            Channel = new TcpChannel(port);
            Nodes   = new Dictionary <string, Node>();
            urls    = new List <string>();

            ChannelServices.RegisterChannel(Channel, false);
            Console.WriteLine(scriptFile);
            Dictionary <int, Pingable> ping = new Dictionary <int, Pingable>();
            int i = 0;

            foreach (string serverUrl in serversUrls)
            {
                Nodes[serverUrl] = ((Node)Activator.GetObject(
                                        typeof(Node),
                                        serverUrl));
                urls.Add(serverUrl);
                ping.Add(i, Nodes[serverUrl]);
                i++;
            }
            manager = new ViewManager(ping);
            manager.Start();
        }
Esempio n. 3
0
        //TODO: change this url. it should be the client's
        public ClientSmrApi(string id, string url, string scriptFile, List <string> serversUrls)
        {
            this.Id  = id;
            this.Seq = 0;
            int port = DU.ExtractPortFromUrl(url);

            Channel = new TcpChannel(port);
            Nodes   = new Dictionary <string, Node>();
            urls    = new List <string>();

            ChannelServices.RegisterChannel(Channel, false);
            Console.WriteLine(scriptFile);

            foreach (string serverUrl in serversUrls)
            {
                Nodes[serverUrl] = ((Node)Activator.GetObject(
                                        typeof(Node),
                                        serverUrl));
                //String.Format("tcp://{0}/Node", serverUrl)));
                urls.Add(serverUrl);
            }


            //System.Console.ReadLine();
        }
Esempio n. 4
0
        public void NewServer(string id, string url, int minDelay, int maxDelay)
        {
            string  domain = DU.ExtractDomainFromUrl(url, true);
            Process p      = Process.Start(serverLocation, String.Format("{0} {1} {2} {3}", id, url, minDelay, maxDelay));

            Processes.Add(id, p);



            Servers.Add(id, (IManageable)Activator.GetObject(typeof(IManageable), url));

            Console.WriteLine("Server Added");
        }
Esempio n. 5
0
        //TODO: change this url. it should be the client's
        public ClientApi(string id, string url, string scriptFile, List <string> serversUrls)
        {
            this.Id  = id;
            this.Seq = 0;
            //TODO: REMOVE Channel = new TcpChannel(Int32.Parse(url.Split(':')[1]));
            Channel = new TcpChannel(DU.ExtractPortFromUrl(url));

            ChannelServices.RegisterChannel(Channel, false);
            Console.WriteLine(scriptFile);

            for (int i = 0; i < serversUrls.Count; i++)
            {
                TupleSpaces.Add(serversUrls[i], (Pingable)Activator.GetObject(typeof(TupleSpace), serversUrls[i]));
            }
        }
Esempio n. 6
0
        public List <string> RequestView()
        {
            CheckOnlyFreeze();
            List <string> view = viewManager.RequestView();

            foreach (string url in view)
            {
                if (DU.ExtractPortFromUrl(url) < DU.ExtractPortFromUrl(selfUrl))
                {
                    return(null);
                }
            }
            view.Add(selfUrl);
            return(view);
        }
Esempio n. 7
0
        public ServerApi(string id, string url, int minDelay, int maxDelay, List <String> urls)
        {
            int        port    = DU.ExtractPortFromUrl(url);
            TcpChannel Channel = new TcpChannel(DU.ExtractPortFromUrl(url));

            ChannelServices.RegisterChannel(Channel, false);

            Dictionary <string, Pingable> TupleSpaces = new Dictionary <string, Pingable>();
            string selfURL = "";

            foreach (string serverUrl in urls)
            {
                if (port != DU.ExtractPortFromUrl(serverUrl))
                {
                    Console.WriteLine(serverUrl);
                    TupleSpaces.Add(serverUrl, (TupleSpace)Activator.GetObject(typeof(TupleSpace), serverUrl));
                }
                else
                {
                    selfURL = serverUrl;
                }
            }

            TupleSpace tupleSpace = new TupleSpace(selfURL, minDelay, maxDelay, TupleSpaces);

            RemotingServices.Marshal(tupleSpace, DU.ExtractObjectNameFromUrl(url));
            tupleSpace.Stopped = true;
            List <TupleSpace> tupleSpaces = new List <TupleSpace>();

            foreach (var entry in TupleSpaces)
            {
                tupleSpaces.Add((TupleSpace)entry.Value);
            }
            tupleSpace.Update();
            tupleSpace.Stopped = false;
            Console.WriteLine("Enter to exit");
            Console.ReadLine();
        }
Esempio n. 8
0
        static async void ExecuteCommand(string command)
        {
            string[]       args = command.Split(null);
            ProcessManager pcs;
            string         url;

            switch (args[0])
            {
            case "Server":
                Console.WriteLine("Creating new Server");
                url = DU.ExtractDomainFromUrl(args[2]);
                pcs = Pcss[url];
                idPcs.Add(args[1], url);
                await Task.Run(() =>
                {
                    pcs.NewServer(args[1], args[2], Int32.Parse(args[3]), Int32.Parse(args[4]));
                });

                Console.WriteLine("Server Created " + args[2]);
                break;

            case "Client":
                Console.WriteLine("Creating new Client");
                url = DU.ExtractDomainFromUrl(args[2]);
                pcs = Pcss[url];
                idPcs.Add(args[1], url);
                await Task.Run(() =>
                {
                    pcs.NewClient(args[1], args[2], args[3]);
                });

                Console.WriteLine("Client Created " + args[2]);
                break;

            case "Status":
                foreach (KeyValuePair <string, ProcessManager> pm in Pcss)
                {
                    await Task.Run(() =>
                    {
                        pm.Value.Status();
                    });
                }
                break;

            case "Crash":
                url = idPcs[args[1]];
                pcs = Pcss[url];
                Console.WriteLine("Crashing Process " + args[1]);
                await Task.Run(() =>
                {
                    pcs.Crash(args[1]);
                });

                break;

            case "Freeze":
                url = idPcs[args[1]];
                pcs = Pcss[url];

                await Task.Run(() =>
                {
                    pcs.Freeze(args[1]);
                });

                Console.WriteLine("Freezing Process ", args[1]);
                break;

            case "Unfreeze":
                url = idPcs[args[1]];
                pcs = Pcss[url];
                await Task.Run(() =>
                {
                    pcs.Unfreeze(args[1]);
                });

                Console.WriteLine("Unfreezing Process ", args[1]);
                break;

            case "Wait":
                Thread.Sleep(Int32.Parse(args[1]));
                break;

            default:
                Console.WriteLine("Invalid command");
                break;
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            TcpChannel Channel = new TcpChannel();

            ChannelServices.RegisterChannel(Channel, false);

            string[] lines = File.ReadAllLines(configlocation);
            Console.WriteLine("Reading cfgfile.txt = ");
            foreach (string line in lines)
            {
                if (line.StartsWith(@"//"))
                {
                    continue;
                }

                Console.WriteLine("\t Creating reference for remote object at: " + line);
                ProcessManager pcs = (ProcessManager)Activator.GetObject(
                    typeof(ProcessManager),
                    line);
                if (pcs == null)
                {
                    Console.WriteLine("Could not locate server at " + line);
                }
                else
                {
                    Pcss.Add(DU.ExtractDomainFromUrl(line), pcs);
                    Console.WriteLine("\t reference added");
                }
            }

            Console.WriteLine();

            if (File.Exists(scriptlocation))
            {
                Console.WriteLine("Executing Script");
                lines = File.ReadAllLines(scriptlocation);
                foreach (string line in lines)
                {
                    if (line.StartsWith("//"))
                    {
                        continue;
                    }
                    Console.WriteLine("\t Executing Command: " + line);
                    ExecuteCommand(line);
                }
            }

            Console.WriteLine("Write command manually, Exit to quit");
            bool exit = false;

            while (!exit)
            {
                string command = Console.ReadLine();
                if (command.StartsWith("//"))
                {
                    continue;
                }
                if (command != "Exit")
                {
                    ExecuteCommand(command);
                }
                else
                {
                    exit = true;
                }
            }
        }
Esempio n. 10
0
 public ClientSMR(string id, string url, string scriptFileName)
 {
     ScriptFileName = DU.JoinPaths(DS.ClientResources, scriptFileName);
     string[] lines = File.ReadAllLines(ServersListLocation);
     Api = new ClientSmrApi(id, url, ScriptFileName, new List <string>(lines));
 }