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);
        }
        //
        public void startDistributedOpeartion(String approach)
        {
            // TODO Auto-generated method stub
            // call all the nodes to start operation (CME).
            NetworkBean      data            = new NetworkBean();
            ServerOperations serveroperation = new ServerOperations();



            foreach (KeyValuePair <string, string> entries in data.getpId_Address())
            {
                String sendAddress = entries.Value;
                String sendiD      = entries.Key;
                try
                {
                    strtDistributedOperations proxy = XmlRpcProxyGen.Create <strtDistributedOperations>();
                    proxy.Url = sendAddress;
                    proxy.startDistributedOperations(approach);
                }


                catch (Exception e)
                {
                    // TODO Auto-generated catch block
                    //   removeNode(sendiD);
                    //  data.getpId_Address().Remove(sendiD);
                    //  if (sendiD.Equals(data.getMasterPid()))
                    // { bullyAlgorithm(); }
                    //   Console.WriteLine(e.StackTrace);
                }
            }



            if (approach.Equals("CME"))
            {
                AutomatedDistributedOperation ADO = new AutomatedDistributedOperation();
                Thread thread = new Thread(() => ADO.startDistributedCME());
                thread.Start();
                data.setStartCME(true);
            }
            if (approach.Equals("RA"))
            {
                AutomatedDistributedOperation ADO = new AutomatedDistributedOperation();
                Thread thread = new Thread(() => ADO.startDistributedRicartAndAgarwala());
                thread.Start();
                data.setStartRicartAgarwala(true);
            }
        }
Esempio n. 3
0
        public Boolean startDistributedOperations(String approach)
        {
            NetworkBean data = new NetworkBean();

            if (approach.Equals("CME"))
            {
                AutomatedDistributedOperation ADO = new AutomatedDistributedOperation();
                Thread thread = new Thread(() => ADO.startDistributedCME());
                thread.Start();
                data.setStartCME(true);
            }
            if (approach.Equals("RA"))
            {
                AutomatedDistributedOperation ADO = new AutomatedDistributedOperation();
                Thread thread = new Thread(() => ADO.startDistributedRicartAndAgarwala());
                thread.Start();

                data.setStartRicartAgarwala(true);
                //data.setStartRicartAgarwala(true);
            }
            return(true);
        }
Esempio n. 4
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");
        }