Beispiel #1
0
        public Boolean distributedProcessDone(String iD)
        {
            NetworkBean data = new NetworkBean();

            data.setNoOfNodesFinishedOperation(data.getNoOfNodesFinishedOperation() + 1);
            return(true);
        }
        public void checkFinalString()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            while (stopwatch.Elapsed < TimeSpan.FromSeconds(20))
            {
            }
            String           message          = "";
            NetworkBean      data             = new NetworkBean();
            CsClient         client           = new CsClient();
            ServerOperations serveroperaation = new ServerOperations();

            Console.WriteLine("**************Reading The final String*******************");


            try
            {
                distribRead proxy = XmlRpcProxyGen.Create <distribRead>();
                proxy.Url = data.getMasterAddress();
                message   = proxy.distributedRead(data.getpId());
                Console.WriteLine("the final string is \n");
                Console.WriteLine(message + "\n");
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine("Could not send the message succesfully.. node denied connection");
                Console.WriteLine("No response from the master node");
                Console.WriteLine("Starting election to elect new master node ( Bully algorith)");
                client.removeNode(data.getMasterPid());
                data.getpId_Address().Remove(data.getMasterPid());
                client.bullyAlgorithm();
                Console.WriteLine(e.StackTrace);
            }
            Boolean wordFlag = true;

            foreach (String word in data.getAddedWords())
            {
                if (message.Contains(word))
                {
                    Console.WriteLine(word + " is present in the final string");
                }
                else
                {
                    Console.WriteLine(word + " is not present in the final string");
                    wordFlag = false;
                }
            }
            if (wordFlag)
            {
                Console.WriteLine("all the words are added to the string in master node");
            }
            //end//
            data.getAddedWords().Clear();
            data.setNoOfNodesFinishedOperation(0);
            data.setStartRicartAgarwala(false);
            data.setStartCME(false);
        }
Beispiel #3
0
        public void start(int port)
        {
            // for CookComputing.XmlRpcV2
            // RemotingConfiguration.Configure("SumAndDiff.exe.config", false);
            // for CookComputing.XmlRpc

            /*  try { RemotingConfiguration.Configure("C:\\Users\\UMAIR\\Documents\\Visual Studio 2015\\Projects\\Node1\\Node1\\App.config"); }
             * catch(Exception e)
             * {
             *    Console.WriteLine(e.Message);
             * }
             *
             * RemotingConfiguration.RegisterWellKnownServiceType(
             *  typeof(CsServer),
             *  "CsServer.rem",
             *  WellKnownObjectMode.Singleton);
             * Console.WriteLine("Press to shutdown");
             * Console.ReadLine();*/
            // system.("csc /r:system.web.dll /r:CookComputing.XmlRpcV2.dll /target:library CsServer.cs ");
            HttpListener listener = new HttpListener();
            string       ip       = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();

            String url = "http://" + ip + ":" + port + "/";

            Console.WriteLine(url);
            String      iD   = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            NetworkBean data = new NetworkBean();
            CentralisedMutualExclusion cme = new CentralisedMutualExclusion();
            Ricart_Agarwala            RA  = new Ricart_Agarwala();
            LamportClock clock             = new LamportClock();

            data.setAddress(url);
            //data.setpId(Long.parseLong(iD));
            data.setpId(iD);
            data.setPort(port);
            data.setMasterAddress(url);
            data.setMasterPid(iD);
            cme.setCRInUse(false);
            RA.setRequestCR(false);
            RA.setUsingCR(false);
            RA.setNumberOfNodesResponded(0);
            RA.setMyTimeStamp("0");
            data.setDistributedStringVariable("");
            data.setStartCME(false);
            data.setStartRicartAgarwala(false);
            data.setMessage("");
            clock.setC(1);
            data.setNoOfNodesFinishedOperation(0);
            data.setRnd();
            //Console.WriteLine(url+iD);
            listener.Prefixes.Add(url);
            try { listener.Start(); }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            while (true)
            {
                HttpListenerContext context = listener.GetContext();


                XmlRpcListenerService svc = new CsServer();

                svc.ProcessRequest(context);
                Thread.Sleep(1);
            }

            Console.WriteLine("server started");
        }