Exemplo n.º 1
0
 public void sendEachRequest(XElement request,TestExec clnt, Message msg, Sender sndr, Receiver rcvr, MessageMaker testExecInput)
 {//send each request to construct xml request message and send it to the server
     msg = new Message();
     msg = testExecInput.makeMessage(clnt.localUrl, clnt.remoteUrl, request);
     if (!sndr.Connect(msg.toUrl))
     {
         Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
         sndr.shutdown();
         rcvr.shutDown();
         return;
     }
     while (true)
     {
         //msg.content = "Message #" + (++counter).ToString();
         Console.Write("\n============Start of the Message==========\n");
         Console.Write("\n  Sending Message:");
         Console.Write("\n==========================\n");
         Console.WriteLine(msg.content);
         Console.WriteLine("==================End of Message===============");
         if (!sndr.sendMessage(msg))
             return;
         Thread.Sleep(100);
         break;
     }
 }
Exemplo n.º 2
0
 public void startRcvrService(Receiver rcvr)
 {   //start receiver service
     if (rcvr.StartService())
     {
         rcvr.doService(rcvr.defaultServiceAction());
     }
 }
Exemplo n.º 3
0
    static void Main(string[] args)
    {
      Util.verbose = false;
      Server srvr = new Server();
      srvr.ProcessCommandLine(args);
      
      Console.Title = "Server: " + srvr.port.ToString();
      Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
      Console.Write("\n ====================================================\n");

      Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
      //Sender sndr = new Sender();
      Receiver rcvr = new Receiver(srvr.port, srvr.address);
      // - serviceAction defines what the server does with received messages
      // - This serviceAction just announces incoming messages and echos them
      //   back to the sender.  
      // - Note that demonstrates sender routing works if you run more than
      //   one client.
      
      if (rcvr.StartService())
      {
        rcvr.doService(doserviceAction(sndr, rcvr, srvr)); // This serviceAction is asynchronous,
      }
      // so the call doesn't block.
      Util.waitForUser(); 
    }
 static void Main(string[] args)
 {
   Console.Write("\n  starting CommService client");
   Console.Write("\n =============================\n");
   Client clnt = new Client();
   clnt.processCommandLine(args);
   string localPort = Util.urlPort(clnt.localUrl);
   string localAddr = Util.urlAddress(clnt.localUrl);
   Receiver rcvr = new Receiver(localPort, localAddr);
   Console.Title = "Read Client: " + localPort;
   if (rcvr.StartService())
   {
     rcvr.doService(doserviceAction(rcvr, clnt));
   }
   Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
   Message msg = new Message();
   msg.fromUrl = clnt.localUrl;
   msg.toUrl = clnt.remoteUrl;
   Console.Write("\n  sender's url is {0}", msg.fromUrl);
   Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);
   if (!sndr.Connect(msg.toUrl))
   {
     Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
     shutdown(rcvr, sndr);
     return;
   }
   "Reading read1.xml file".title();
   string path = Path.GetFullPath("../../../Read Client/bin/Debug/read1.xml");
   XDocument newDoc = XDocument.Load(path);
   Parser p = new Parser();
   clnt.read_client_latency.Start();
   p.parse(newDoc, ref msg, sndr);
   Message msg1 = new Message();
   msg1.fromUrl = clnt.localUrl;
   msg1.toUrl = clnt.remoteUrl;
   msg1.content = "done";
   sndr.sendMessage(msg1);
   while (clnt.flag) ; //wait till last message is received from server
   Message msg2 = new Message();
   msg2.fromUrl = clnt.localUrl;
   msg2.toUrl = clnt.remoteUrl;
   msg2.content = "read-client," + clnt.read_client_latency.ElapsedMicroseconds;
   sndr.sendMessage(msg2);
   // Wait for user to press a key to quit.
   // Ensures that client has gotten all server replies.
   Util.waitForUser();
   // shut down this client's Receiver and Sender by sending close messages
   shutdown(rcvr, sndr);
   Console.Write("\n\n");
 }
Exemplo n.º 5
0
 static void Main(string[] args) { 
     Console.Write("\n  starting CommService client");
     Console.Write("\n =============================\n");
     HiResTimer timerReader = new HiResTimer();
     Client clnt = new Client();
     clnt.processCommandLine(args);
     string localPort = args[0];
     clnt.localUrl = "http://localhost:" + localPort + "/CommService";
     string localAddr = Util.urlAddress(clnt.localUrl);
     Receiver rcvr = new Receiver(localPort, localAddr);
     rcvr.setTimerFromClient(timerReader);
     clnt.startRcvrService(rcvr);
     Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
     MessageMaker readerInput = new MessageMaker();
     string fileName = ".\\ReaderClientInput.xml";
     Message msg = new Message();
     int numRequests = Convert.ToInt32(args[1]);
     XDocument xmldoc = XDocument.Load(fileName);
     var requests = xmldoc.Descendants("Request");
     int requestCount = 0, i = 0; List<XElement> totalrequest = new List<XElement>();
     while (i < numRequests) {    //set the specified number of requests to send
         totalrequest.Add(requests.ElementAt(i)); i++;}
     timerReader.Start();
     foreach (var request in totalrequest) {   //send each request to the message maker to create a message
         msg = new Message();
         msg = readerInput.makeMessage(clnt.localUrl, clnt.remoteUrl, request);
         Console.Title = "Reader Client to query the NoSQl database: Querying " + (++requestCount) + " requests";
         if (!sndr.Connect(msg.toUrl)) {      //send url of the destination to the sender
             Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
             sndr.shutdown();
             rcvr.shutDown();
             return;
         }
         Thread.Sleep(700);
         while (true) {
                 clnt.printMessage(msg);         //print the message contents
                 if (!sndr.sendMessage(msg))     // send the message to the sender
                     return;
                 Thread.Sleep(100);
                 break;}
     sndr.sendLatencyReader(rcvr.avgLatency);}
     Console.Write("\n  Sender's url is {0}", msg.fromUrl);
     Console.Write("\n  Attempting to connect to {0}\n", msg.toUrl);
     msg.content = "done";
     sndr.sendMessage(msg);
     Util.waitForUser();
     rcvr.shutDown();
     sndr.shutdown();
 } } }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();
            DBEngine<string, DBElement<string, List<string>>> testDict = new DBEngine<string, DBElement<string, List<string>>>();
            srvr.ProcessCommandLine(args);
            double timeTaken = 0, totalTime = 0, insCount = 0;
            srvr.printMessage(srvr);
            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
            Receiver rcvr = new Receiver(srvr.port, srvr.address);
            StringBuilder sb = new StringBuilder();
            Action serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    HiResTimer hiResTimer = new HiResTimer();
                    hiResTimer.Start();
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages            
                    srvr.printMessage(msg);
                    if (msg.content == "connection start message") continue; // don't send back start message
                    if (msg.fromUrl == "http://localhost:8080/CommService") continue;
                    if (msg.content == "done")
                    { Console.Write("\n  client has {0} finished\n",msg.fromUrl); continue; }
                    if (msg.content == "closeServer")
                    { Console.Write("received closeServer"); break; }
                    msg.content = srvr.readOperations(testDict, msg);
                    Util.swapUrls(ref msg);                     // swap urls for outgoing message
#if (TEST_WPFCLIENT)
                    Message testMsg = new Message();
                    testMsg.toUrl = msg.toUrl;
                    testMsg.fromUrl = msg.fromUrl;
                    testMsg.content = msg.content;
                    sndr.sendMessage(testMsg);
                    hiResTimer.Stop();
                    double diffTime = hiResTimer.ElapsedTimeSpan.TotalSeconds;
                    totalTime = totalTime + diffTime;
                    timeTaken = totalTime / (++insCount);
                    Console.Title = "Server client handling " + (insCount) + " requests";
                    srvr.printServerThroughput(timeTaken);
                    sndr.sendServerThroughput((1 / timeTaken));
#else
                              sndr.sendMessage(msg);
#endif
                }
            };
            if (rcvr.StartService())
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            Util.waitForUser(); // so the call doesn't block.
        }
 //--------< Define action to be performed on receiving message >------
 private static Action doserviceAction(Receiver rcvr)
 {
   Action serviceAction = () =>
   {
     if (Util.verbose)
       Console.Write("\n  starting Receiver.defaultServiceAction");
     Message msg1 = null;
     while (true)
     {
       msg1 = rcvr.getMessage();   // note use of non-service method to deQ messages
       Console.Write("\n  Received message:");
       Console.Write("\n  sender is {0}", msg1.fromUrl);
       Console.Write("\n  content is {0}\n", msg1.content);
       if (msg1.content == "closeReceiver")
         break;
     }
   };
   return serviceAction;
 }
        //----< get Receiver and Sender running >----------------------------
        void setupChannel()
        {
            rcvr = new Receiver(localPort, localAddress);
              Action serviceAction = () =>
              {
            try
            {
              Message rmsg = null;
              while (true)
              {
            rmsg = rcvr.getMessage();
            Action act = () => { postRcvMsg(rmsg.content); };
            Dispatcher.Invoke(act, System.Windows.Threading.DispatcherPriority.Background);
              }
            }
            catch (Exception ex)
            {
              Action act = () => { lStat.Text = ex.Message; };
              Dispatcher.Invoke(act);
            }
              };
              if (rcvr.StartService())
              {
            rcvr.doService(serviceAction);
              }

              sndr = new wpfSender(lStat, this.Dispatcher);
        }
Exemplo n.º 9
0
        //----< retrieve urls from the CommandLine if there are any >--------

        public Action define_receive_action(Receiver rcvr, bool log_messages)
        {
            Action client_receive_action = () =>
            {
                Message rcv_msg = null;
                while (true)
                {
                    rcv_msg = rcvr.getMessage();
                    if (rcv_msg.content == "closeReceiver")
                    {
                        break;
                    }
                    if (rcv_msg.content == "connection start message")
                    {
                        continue;
                    }
                    if (rcv_msg.content == "done")
                    {
                        Console.WriteLine("\n  ********************************\n  All responses received from server.");
                        Console.WriteLine("  Enter any key on the TestExecutive window to launch all the readers and writers.");
                        Console.WriteLine("  Enter any key on this window to close sender and receiver of this Demo Client.");
                        continue;
                    }
                    try
                    {
                        XElement response_msg = XElement.Parse(rcv_msg.content);
                        Console.WriteLine("\n  Received response for Request with ID = {0}", response_msg.Element("Request_ID").Value);
                        DateTime tm_start = DateTime.Parse(response_msg.Element("Request_Time_Stamp").Value);
                        DateTime tm_now   = DateTime.Now;
                        TimeSpan lat_ts   = tm_now - tm_start;
                        Console.WriteLine("  Latency time for the Request = {0} milli seconds", lat_ts.TotalMilliseconds);
                        if (response_msg.Element("Query_Response") != null)
                        {
                            XElement query_response = response_msg.Element("Query_Response");
                            Console.WriteLine("  Query type = {0}", query_response.Element("Query_Type").Value);
                            if (query_response.Element("Result").Value != "Success")
                            {
                                Console.WriteLine("  Result of request:\n  {0}", query_response.Element("Result").Value);
                            }
                            if (query_response.Element("Partial") != null)
                            {
                                Console.WriteLine(query_response.Element("Partial").Value);
                            }
                            if (query_response.Element("Complete") != null)
                            {
                                Console.WriteLine(query_response.Element("Complete").Value);
                            }
                        }
                        else
                        {
                            Console.WriteLine("  Result of request:\n  {0}", response_msg.Element("Result").Value);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("\n  XML format of response message is not in the expected format. A particular tag could not be found.");
                    }
                }
            };

            return(client_receive_action);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);

            Console.Title = "Server";
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");

            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
            //Sender sndr = new Sender();
            Receiver rcvr = new Receiver(srvr.port, srvr.address);

            // - serviceAction defines what the server does with received messages
            // - This serviceAction just announces incoming messages and echos them
            //   back to the sender.
            // - Note that demonstrates sender routing works if you run more than
            //   one client.

            Action serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    msg = rcvr.getMessage(); // note use of non-service method to deQ messages
                    Console.Write("\n  Received message:");
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    Console.Write("\n  content is {0}\n", msg.content);

                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n");
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    msg.content = "received " + msg.content + " from " + msg.fromUrl;

                    // swap urls for outgoing message
                    Util.swapUrls(ref msg);

#if (TEST_WPFCLIENT)
                    /////////////////////////////////////////////////
                    // The statements below support testing the
                    // WpfClient as it receives a stream of messages
                    // - for each message received the Server
                    //   sends back 1000 messages
                    //
                    int count = 0;
                    for (int i = 0; i < 1000; ++i)
                    {
                        Message testMsg = new Message();
                        testMsg.toUrl   = msg.toUrl;
                        testMsg.fromUrl = msg.fromUrl;
                        testMsg.content = String.Format("test message #{0}", ++count);
                        Console.Write("\n  sending testMsg: {0}", testMsg.content);
                        sndr.sendMessage(testMsg);
                    }
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
                    sndr.sendMessage(msg);
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.
            Util.waitForUser();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);
            Console.Title = "Server";
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");

            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));

            Receiver rcvr = new Receiver(srvr.port, srvr.address);

            // - serviceAction defines what the server does with received messages
            // - This serviceAction just announces incoming messages and echos them
            //   back to the sender.
            // - Note that demonstrates sender routing works if you run more than
            //   one client.

            Action serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    Console.Write("\n  Received message:");
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    //Console.Write("\n  content is {0}\n", msg.content);

                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n");
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    if (msg.content.Contains("Writer"))
                    {
                        int     avg      = srvr.Ttime.Sum() / srvr.Ttime.Count();
                        string  lat      = string.Join(null, System.Text.RegularExpressions.Regex.Split(msg.content, "[^\\d]"));
                        Message msgToWpf = new Message();
                        msgToWpf.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf.content = msg.content + " microseconds for Client: " + msg.fromUrl.ToString();
                        sndr.sendMessage(msgToWpf);
                        Message msgToWpf1 = new Message();
                        msgToWpf1.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf1.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf1.content = "Server ThroughPut(Avg Time) for " + srvr.Ttime.Count().ToString() + " Write Operations = " + avg.ToString() + " microseconds";
                        sndr.sendMessage(msgToWpf1);
                        continue;
                    }
                    if (msg.content.Contains("Reader"))
                    {
                        int     avg1     = srvr.Ttime1.Sum() / srvr.Ttime1.Count();
                        string  lat      = string.Join(null, System.Text.RegularExpressions.Regex.Split(msg.content, "[^\\d]"));
                        Message msgToWpf = new Message();
                        msgToWpf.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf.content = msg.content + " microseconds for Client: " + msg.fromUrl.ToString();
                        sndr.sendMessage(msgToWpf);
                        Message msgToWpf1 = new Message();
                        msgToWpf1.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf1.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf1.content = "Server ThroughPut(Avg Time) for " + srvr.Ttime1.Count().ToString() + " Read Operations = " + avg1.ToString() + " microseconds";
                        sndr.sendMessage(msgToWpf1);
                        continue;
                    }
                    try
                    {
                        XDocument xdoc            = XDocument.Parse(msg.content);
                        string    operationCalled = getOperationType(xdoc);
                        if (operationCalled == "add")
                        {
                            Console.WriteLine("\nAdd Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processAddMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "delete")
                        {
                            Console.WriteLine("\nDelete Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processDelMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }

                        else if (operationCalled == "edit")
                        {
                            Console.WriteLine("\nEdit Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processEditMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }

                        else if (operationCalled == "query1")
                        {
                            Console.WriteLine("\nQuery1 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery1(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "query2")
                        {
                            Console.WriteLine("\nQuery2 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery2(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                            Util.swapUrls(ref msg);
                            msg.content = "-----Query2 operation performed-----";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query3")
                        {
                            Console.WriteLine("\nQuery3 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery3(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                            Util.swapUrls(ref msg);
                            msg.content = "-----Query3 operation performed-----";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query4")
                        {
                            Console.WriteLine("\nQuery4 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery4(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "query5")
                        {
                            Console.WriteLine("\nQuery5 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery5(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                            Util.swapUrls(ref msg);
                            msg.content = "-----Query5 operation performed-----";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "persist")
                        {
                            Console.WriteLine("\nPersist Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processPersistMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "augment")
                        {
                            Console.WriteLine("\nAugment Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processAugmentedMsg(xdoc, sndr, msg, srvr);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                    }

                    catch { }



#if (TEST_WPFCLIENT)
                    /////////////////////////////////////////////////
                    // The statements below support testing the
                    // WpfClient as it receives a stream of messages
                    // - for each message received the Server
                    //   sends back 1000 messages
                    //
                    int count = 0;
                    for (int i = 0; i < 2; ++i)
                    {
                        Message testMsg = new Message();
                        testMsg.toUrl   = msg.toUrl;
                        testMsg.fromUrl = msg.fromUrl;
                        testMsg.content = String.Format("test message #{0}", ++count);
                        Console.Write("\n  sending testMsg: {0}", testMsg.content);
                        sndr.sendMessage(testMsg);
                    }
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.
            Util.waitForUser();
        }
Exemplo n.º 12
0
 static void Main(string[] args)
 {
  try
     {
         Util.verbose = false;
         Server srvr = new Server();
         srvr.ProcessCommandLine(args);
         Console.Title = "Server";
         Console.Write(String.Format("\nStarting CommService server listening on port {0}", srvr.port));
         Console.WriteLine("\nServer Address is {0}", Util.makeUrl(srvr.address, srvr.port));
         Console.Write("\n ====================================================\n");
         Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
         Receiver rcvr = new Receiver(srvr.port, srvr.address);
         Action serviceAction = DefineServiceAction(srvr, sndr, rcvr);
         if (rcvr.StartService())
         {
             rcvr.doService(serviceAction); // This serviceAction is asynchronous, // so the call doesn't block.
         }
         Util.waitForUser();
     }
     catch (CustomException ex)
     {
         Console.WriteLine("Error occured in Server.cs{0}", ex);
     }
 }
Exemplo n.º 13
0
 private static Action DefineServiceAction(Server srvr, Sender sndr, Receiver rcvr)
 {
     Action serviceAction = () =>
     {
         Message msg = null; string msgid = "";
         while (true)
         {
             msg = rcvr.getMessage();   // note use of non-service method to deQ messages
             Console.Write("\nReceived message:");
             Console.Write("\nSender is {0}", msg.fromUrl);
             if (msg.content == "connection start message")
             {
                 Console.Write("\nConnection start message recieved\n");
                 continue; //Don't Send back Start message
             }
             else if (msg.content == "done")
             {
                 msg = FinalMessageServe(srvr, sndr, msg);
                 continue;
             }
             else if (msg.content == "closeServer")
             {
                 Console.Write("Received closeServer");
                 break;
             }
             else
             {
                 ProcessResponse(srvr, sndr, ref msg, ref msgid);
             }
         }
     };
     return serviceAction;
 }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.Write("\n  starting CommService reader client");
            Console.Write("\n =======================================\n");
            Console.Write("\n XML for Reading template is XMLReader.xml");
            Console.Write("\n =======================================\n");
            Console.Write("\n If Verbose switch is off, then all logs are logged into WPF Client/GUI.");
            Console.Write("\n =====================================================================\n");
            Console.Title = "Client #2";
            Console.Write("\n Demonstrating Requirement #4 by querying all type of queries from reader client to server.");
            Console.Write("\n Demonstrating Requirement #7 and #8 by taking format of request from XML and showing performance on GUI as well as on Console.(If logging switch is on)");
            Client clnt = new Client();

            clnt.processCommandLine(args);

            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }

            Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message

            Message msg = new Message();

            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;

            Console.Write("\n  sender's url is {0}", msg.fromUrl);
            Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);

            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }
            clnt.hrt.Start();
            clnt.readMessageTemplates("XMLReader.xml", sndr);
            rcvr.setTotalMessageSize(clnt.getMessageSize() + 1);
            while (true)
            {
                if (rcvr.getLastFlag())
                {
                    clnt.hrt.Stop();
                    break;
                }
            }
            ulong latency = clnt.hrt.ElapsedMicroseconds;
            int   lat     = Convert.ToInt32(latency);

            clnt.transportInformation(latency, sndr);
            msg.content = "done";
            sndr.sendMessage(msg);

            // Wait for user to press a key to quit.
            // Ensures that client has gotten all server replies.
            Util.waitForUser();

            // shut down this client's Receiver and Sender by sending close messages
            rcvr.shutDown();
            sndr.shutdown();

            Console.Write("\n\n");
        }
 /// <summary>
 /// Main program entry
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     Console.Write("\nStarting CommService write client");
     Console.Write("\n =============================\n");
     Console.Title = "Project 2 Requirements Testing";
     BasicRequirementTest clnt = new BasicRequirementTest();
     clnt.processCommandLine(args);
     string localPort = Util.urlPort(clnt.localUrl);
     string localAddr = Util.urlAddress(clnt.localUrl);
     Receiver rcvr = new Receiver(localPort, localAddr);
     if (rcvr.StartService())
         rcvr.doService(rcvr.defaultServiceAction());
     Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
     Message msg = new Message();
     msg.fromUrl = clnt.localUrl;
     msg.toUrl = clnt.remoteUrl;
     Console.Write("\nSender's url is {0} \n", msg.fromUrl);
     Console.Write("\nAttempting to connect to {0}\n", msg.toUrl);
     if (!sndr.Connect(msg.toUrl))
     {
         Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
         sndr.shutdown();
         rcvr.shutDown();
         return;
     }
     string key = "";
     clnt.TestR2(ref msg, sndr, ref key);
     clnt.TestR3(ref msg, sndr);
     clnt.TestR4(ref msg, sndr, key);
     clnt.TestR5(ref msg, sndr);
     clnt.TestR6(ref msg, sndr);
     clnt.TestR7A(ref msg, sndr);
     clnt.TestR7B(ref msg, sndr);
     clnt.TestR7C(ref msg, sndr);
     clnt.TestR7D(ref msg, sndr);
     clnt.TestR7E(ref msg, sndr);
     clnt.TestR8(ref msg, sndr);
     clnt.TestR9(ref msg, sndr);
     Util.waitForUser();            // Wait for user to press a key to quit.
     rcvr.shutDown();               // shut down this client's Receiver and Sender by sending close messages
     sndr.shutdown();
     Console.Write("\n\n");
 }
Exemplo n.º 16
0
 //-----------< action for received special messages >------------
 private static bool specialMessage(ref Message msg, Server srvr, Sender sndr, Receiver rcvr, ref ulong read_clnt_latency_time, ref ulong write_clnt_process_time, ref ulong server_throughput_time, ref int counter_write, ref int counter_read)
 {
   if (msg.content == "connection start message")
   {
     srvr.server_throuput.Start();
     return true; // don't send back start message
   }
   else if (msg.content == "done")
   {
     //---------< maitain test performance data for server throughput >----
     srvr.server_throuput.Stop();
     server_throughput_time += srvr.server_throuput.ElapsedMicroseconds;
     Console.Write("\n  client has finished\n");
     Console.WriteLine("\nServer throughput: " + server_throughput_time + " microseconds\n");
     Util.swapUrls(ref msg);
     Console.WriteLine("\n\n Sending Message: " + msg.content + "\n\n");
     sndr.sendMessage(msg);
     return true;
   }
   else
        if (msg.content.Contains("write-client"))
   {
     write_client_processing(ref counter_write, ref write_clnt_process_time, ref msg);
     return true;
   }
   else if (msg.content.Contains("read-client"))
   {
     read_client_latency(ref counter_read, ref read_clnt_latency_time, ref msg);
     return true;
   }
   else if (msg.content == ("test-result"))
   {
     send_test_result(ref msg, ref read_clnt_latency_time, write_clnt_process_time, server_throughput_time, counter_read, counter_write, sndr);
     return true;
   }
   else
   {
     return false;
   }
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");

            Console.Title = "Client #1";

            Client clnt = new Client();

            clnt.processCommandLine(args);

            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }

            Sender sndr = new Sender(clnt.localUrl); // Sender needs localUrl for start message

            Message msg = new Message();

            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;

            Console.Write("\n  sender's url is {0}", msg.fromUrl);
            Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);

            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }

            int numMsgs = 5;
            int counter = 0;

            while (true)
            {
                msg         = new Message();
                msg.fromUrl = clnt.localUrl;
                msg.toUrl   = clnt.remoteUrl;
                msg.content = "Message #" + (++counter).ToString();
                Console.Write("\n  sending {0}", msg.content);
                if (!sndr.sendMessage(msg))
                {
                    return;
                }
                /////////////////////////////////////////////////////////////////
                // The delay, below, can now be removed without changing the
                // sending behavior except that it becomes faster.  However
                // We want to simulate a "normal" minimum delay between messages
                // to measure latency and server throughput.  Without the delay
                // the server's queue will very quickly contain a large number
                // of messages and we won't be accurately representing the system
                // behavior for a single client and server.
                //
                // Instead, we stress the server by running multiple clients
                // concurrently.
                //
                Thread.Sleep(100);
                if (counter >= numMsgs)
                {
                    break;
                }
            }
            msg         = new Message();
            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;
            msg.content = "done";
            sndr.sendMessage(msg);

            // Wait for user to press a key to quit.
            // Ensures that client has gotten all server replies.
            Util.waitForUser();

            // shut down this client's Receiver and Sender by sending close messages
            rcvr.shutDown();
            sndr.shutdown();

            Console.Write("\n\n");
        }
Exemplo n.º 18
0
 //--------< Define action to be performed on receiving message >------
 private static Action doserviceAction(Sender sndr, Receiver rcvr, Server srvr)
 {
   int counter_write = 0;
   int counter_read = 0;
   ulong write_clnt_process_time = 0;
   ulong read_clnt_latency_time = 0;
   ulong server_throughput_time = 0;
   Action serviceAction = () =>
   {
     Message msg = null;
     while (true)
     {
       msg = rcvr.getMessage();   // note use of non-service method to deQ messages          
       Console.Write("\n  Received message:\n");
       Console.Write("\n  sender is {0}\n", msg.fromUrl);
       Console.Write("\n  content is {0}\n", msg.content);
       if (specialMessage(ref msg, srvr, sndr, rcvr, ref read_clnt_latency_time, ref write_clnt_process_time, ref server_throughput_time, ref counter_write, ref counter_read))
       {
         continue;
       }
       else if (msg.content == "closeServer")
       {
         Console.Write("\n\nreceived closeServer\n\n");
         break;
       }
       else
       {
         WriteLine();
         List<string> msg_list = msg.content.Split(',').ToList<string>();
         IEnumerator<string> msg_enumerator = msg_list.GetEnumerator();
         ServerParser sp = new ServerParser();
         string str = "";
         while (msg_enumerator.MoveNext())
         {
           getDatabase(ref sp, ref msg_enumerator, ref str);
         };
         // swap urls for outgoing message
         msg.content = str;
         Util.swapUrls(ref msg);
         /////////////////////////////////////////////////
         // Use the statement below for normal operation
         Console.WriteLine("\n\n Sending Message: " + msg.content + "\n\n");
         sndr.sendMessage(msg);
       }
     }
   };
   return serviceAction;
 }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.Write("\n  Starting Writer client");
            Console.Write("\n =============================\n");
            Console.Title = "Writer";
            Client clnt = new Client();

            try
            {
                clnt.processCommandLine(args);
                string   localPort = Util.urlPort(clnt.localUrl);
                string   localAddr = Util.urlAddress(clnt.localUrl);
                Receiver rcvr      = new Receiver(localPort, localAddr);
                Sender   sndr      = new Sender(clnt.localUrl); // Sender needs localUrl for start message

                if (rcvr.StartService())
                {
                    rcvr.doService(rcvr.defaultServiceAction());
                }

                Message msg = new Message();
                msg.fromUrl = clnt.localUrl;
                msg.toUrl   = clnt.remoteUrl;

                Console.Write("\n  sender's url is {0}", msg.fromUrl);
                Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);

                if (!sndr.Connect(msg.toUrl))
                {
                    Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                    sndr.shutdown();
                    rcvr.shutDown();
                    return;
                }

                clnt.timer.Start();
                clnt.readMessageTemplates("XMLWriter.xml");
                if (clnt.listOfMsgs.Count() > 0)
                {
                    rcvr.setTotalMessageSize(clnt.getTotalNumberOfMessages(clnt.listOfMsgs));
                    clnt.processMessages(clnt.listOfMsgs, sndr);
                    while (true)
                    {
                        if (rcvr.getLastFlag())
                        {
                            clnt.timer.Stop();
                            break;
                        }
                    }
                }
                ulong latency = clnt.timer.ElapsedMicroseconds;
                clnt.sendPerformanceMessage(latency, sndr);
                msg.content = "done";
                sndr.sendMessage(msg);
                // Wait for user to press a key to quit.
                // Ensures that client has gotten all server replies.
                Util.waitForUser();
                // shut down this client's Receiver and Sender by sending close messages
                rcvr.shutDown();
                sndr.shutdown();
                Console.Write("\n\n");
            }
            catch (Exception e)
            {
                Console.Write("Invalid XMl file or some exception occured.");
                Console.Write("Exception : " + e.StackTrace);
                throw;
            }
        }
 //--------< Define action to be performed on receiving message >------
 private static Action doserviceAction(Receiver rcvr, Client clnt)
 {
   Action serviceAction = () =>
   {
     if (Util.verbose)
       Console.Write("\n  starting Receiver.defaultServiceAction");
     Message msg1 = null;
     while (true)
     {
       msg1 = rcvr.getMessage();   // note use of non-service method to deQ messages
       Console.Write("\n  Received message:");
       Console.Write("\n  sender is {0}", msg1.fromUrl);
       Console.Write("\n  content is {0}\n", msg1.content);
       if (msg1.content == "done")
       {
         clnt.read_client_latency.Stop();
         clnt.flag = false;
         Console.WriteLine("\n\n Read Client latency: " + clnt.read_client_latency.ElapsedMicroseconds + " microseconds\n\n");
       }
       if (msg1.content == "closeReceiver")
         break;
     }
   };
   return serviceAction;
 }
Exemplo n.º 21
0
        //----< Main method. >-----
        static void Main(string[] args)
        {
            Util.verbose    = false;
            Util.verboseApp = true;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);
            srvr.preLoadData();

            Console.Title = "Server";
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");

            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
            //Sender sndr = new Sender();
            Receiver rcvr = new Receiver(srvr.port, srvr.address);

            // - serviceAction defines what the server does with received messages
            // - This serviceAction just announces incoming messages and echos them
            //   back to the sender.
            // - Note that demonstrates sender routing works if you run more than
            //   one client.

            Action serviceAction = () =>
            {
                Message    msg = null;
                HiResTimer hrt = new HiResTimer();
                while (true)
                {
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    if (Util.verbose)
                    {
                        Console.Write("\n  Received message:");
                        Console.Write("\n  sender is {0}", msg.fromUrl);
                        Console.Write("\n  content is {0}\n", msg.content);
                    }
                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    try
                    {
                        XDocument xdoc = XDocument.Parse(msg.content);

                        string operationCalled = identifyOperation(xdoc);
                        // swap urls for outgoing message
                        if (operationCalled == "add")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("add Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processAddMessage(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "delete")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("delete Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processDeleteMessage(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }

                        else if (operationCalled == "edit")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("Edit Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processEditMessage(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }

                        else if (operationCalled == "query1")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query1 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery1Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query2")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query2 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery2Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query3")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query3 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery3Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query4")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query4 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery4Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query5")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query5 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery5Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "persist")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("persist Operation Called");
                            }
                            hrt.Start();
                            srvr.persistDatatToFile();
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            msg.content = "Persist operation performed.";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "restore")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("Restore Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processDataRestoreMessageRequest();
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                            continue;
                        }
                        else if (operationCalled == "performance")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("performance Operation Called");
                            }
                            Message msgToWpf1 = new Message();
                            msgToWpf1.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                            msgToWpf1.toUrl   = "http://localhost:8089/CommService";
                            msgToWpf1.content = srvr.createPerformanceMessageForWPF(xdoc, avgTime.ToString());
                            sndr.sendMessage(msgToWpf1);
                            continue;
                        }
                    }

                    catch (Exception e)
                    {
                        Console.WriteLine("Catch " + e.StackTrace + "\n");
                    }


#if (TEST_WPFCLIENT)
                    /////////////////////////////////////////////////
                    // The statements below support testing the
                    // WpfClient as it receives a stream of messages
                    // - for each message received the Server
                    //   sends back 1000 messages
                    //
                    int count = 0;
                    for (int i = 0; i < 2; ++i)
                    {
                        Message testMsg = new Message();
                        testMsg.toUrl   = msg.toUrl;
                        testMsg.fromUrl = msg.fromUrl;
                        testMsg.content = String.Format("test message #{0}", ++count);
                        Console.Write("\n  sending testMsg: {0}", testMsg.content);
                        sndr.sendMessage(testMsg);
                    }
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
                    // sndr.sendMessage(msg);
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.
            Util.waitForUser();
        }
Exemplo n.º 22
0
 static void Main(string[] args)
 {
     Console.Write("\n  starting CommService client");
     Console.Write("\n =============================\n");
     Console.Title = "Test Executive Client to display the results of remote NoSQL database operations";
     TestExec clnt = new TestExec();
     clnt.processCommandLine(args);
     HiResTimer timerTestExec = new HiResTimer();
     string localPort = Util.urlPort(clnt.localUrl);
     string localAddr = Util.urlAddress(clnt.localUrl);
     Receiver rcvr = new Receiver(localPort, localAddr);
     rcvr.setTimerFromClient(timerTestExec);
     clnt.startRcvrService(rcvr);
     Console.WriteLine("\n The Message request is");
     Console.Write("\n =================================\n");
     Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
     MessageMaker testExecInput = new MessageMaker(); 
     Message msg = new Message();
     string fileName = ".\\TestExecInput.xml"; 
     XDocument xmldoc = XDocument.Load(fileName);
     var requests = xmldoc.Descendants("Request");
     int requestCount = 0, readers = 0, writers = 0, portReader = 0, portWriter = 0, numberOfRequests = 0, numberOfRequestsWriters = 0;
     string readerDisplay = "", writerDisplay = "";
     clnt.getReadersWritersCount(xmldoc, ref readers, ref writers, ref portReader, ref portWriter, ref numberOfRequests, ref readerDisplay, ref writerDisplay, ref numberOfRequestsWriters);
     timerTestExec.Start();
     foreach (var request in requests)
     {   //send each request to construct message and send it to the server
         clnt.sendEachRequest(request,clnt,msg,sndr,rcvr,testExecInput);
         Console.Title = "TestExec Client to display the NoSQl database operations: Operations " + (++requestCount) + " are Sent";
     }
     msg.content = "done";
     Util.waitForUser();
     rcvr.shutDown();
     sndr.shutdown();
     Console.Write("\n\n");
     if(args.Count() != 0)
     {
         readers = Convert.ToInt32(args[0]);
         writers = Convert.ToInt32(args[1]);
         numberOfRequests = Convert.ToInt32(args[2]);
         numberOfRequestsWriters = Convert.ToInt32(args[3]);
     }
     for(int i = 1; i <= writers; i++)
     {
         System.Diagnostics.Process.Start(".\\Client\\bin\\Debug\\Client.exe",""+(portWriter++) + " " + numberOfRequestsWriters + " "+writerDisplay);
     }
     for(int j = 1; j <= readers; j++)
     {
         System.Diagnostics.Process.Start(".\\Client2\\bin\\Debug\\Client2.exe",(""+(portReader++)+" "+numberOfRequests+" "+readerDisplay));
     }
 }
Exemplo n.º 23
0
 static void Main(string[] args)
 {
        HiResTimer hres = new HiResTimer(); //High Resolution Timer
     Console.Write("\nStarting CommService Read client");
     Console.Write("\n =============================\n");
     Console.Title = "Read Client";
     Message msg = new Message();
     ReadClient clnt = new ReadClient();
     clnt.processCommandLine(args);
     string localPort = Util.urlPort(clnt.localUrl);
     string localAddr = Util.urlAddress(clnt.localUrl);
     Receiver rcvr = new Receiver(localPort, localAddr);
     Action serviceAction = DefineServiceAction(hres, clnt, rcvr);
     if (rcvr.StartService())
         rcvr.doService(serviceAction);
     Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message         
     msg.fromUrl = clnt.localUrl;
     msg.toUrl = clnt.remoteUrl;
     Console.Write("Sender's url is {0}", msg.fromUrl);
     Console.Write("Attempting to connect to {0}\n", msg.toUrl);
     if (!sndr.Connect(msg.toUrl))
     {
         Console.Write("Could not connect in {0} attempts\n", sndr.MaxConnectAttempts);
         sndr.shutdown();
         rcvr.shutDown();
         return;
     }
     msg = PerformanceTest(hres, msg, clnt, sndr);
     // Wait for user to press a key to quit.
     Util.waitForUser();
     // shut down this client's Receiver and Sender by sending close messages
     rcvr.shutDown();
     sndr.shutdown();
     Console.Write("\n\n");
 }
Exemplo n.º 24
0
        //----< Test Stub >--------------------------------------------------

#if (TEST_RECEIVER)

        static void Main(string[] args)
        {
            Util.verbose = true;

            Console.Title = "CommService Receiver";
            Console.Write("\n  Starting CommService Receiver");
            Console.Write("\n ===============================\n");

            Receiver rcvr = new Receiver();
            rcvr.ProcessCommandLine(args);

            Console.Write("\n  Receiver url = {0}\n", Util.makeUrl(rcvr.address, rcvr.port));

            // serviceAction defines what the server does with received messages

            if (rcvr.StartService())
            {
                //rcvr.doService();
                rcvr.doService(rcvr.defaultServiceAction());  // equivalent to rcvr.doService()
            }
            Console.Write("\n  press any key to exit: ");
            Console.ReadKey();
            Console.Write("\n\n");
        }
Exemplo n.º 25
0
 /// <summary>
 ///  Performance testing by inserting items
 /// </summary>
 /// <param name="hres"></param>
 /// <param name="msg"></param>
 /// <param name="clnt"></param>
 /// <param name="rcvr"></param>
 /// <param name="sndr"></param>
 private static void PerformanceTesting(HiResTimer hres, Message msg, WriterClient clnt, Receiver rcvr, Sender sndr)
 {
     try
     {
         XmlTextReader textReader = new XmlTextReader("Input.xml");
         string xmlStr = "";
         HiResTimer t = new HiResTimer();
         t.Start();
         if (File.Exists("Input.xml"))
         {
             XDocument docTemp;
             string key, msgid;
             xmlStr = InsertPerformance(hres, msg, clnt, sndr, xmlStr, out docTemp, out key, out msgid);
             string keyUp;
             XElement l;
             UpdatePerformance(msg, clnt, sndr, ref xmlStr, out docTemp, key, ref msgid, out keyUp, out l);
             //Delete entries
             docTemp = DeletePerformance(msg, clnt, sndr, ref xmlStr, key, ref msgid, ref keyUp, l);
         }
         t.Stop();
         clnt.WriteClientTime = t.ElapsedMicroseconds;
         msg = new Message();
         msg.fromUrl = clnt.localUrl;
         msg.toUrl = clnt.remoteUrl;
         msg.content = "done";
         sndr.sendMessage(msg);
         // Wait for user to press a key to quit.
         Util.waitForUser();
         // shut down this client's Receiver and Sender by sending close messages
         rcvr.shutDown();
         sndr.shutdown();
         Console.Write("\n\n");
     }
     catch (CustomException ex)
     {
         throw new CustomException("Error in main of peformance testing", ex);
     }
 }
 //--------< shutdown receiver and sender >---------------------------
 private static void shutdown(Receiver rcvr, Sender sndr)
 {
   sndr.shutdown();
   rcvr.shutDown();
 }
Exemplo n.º 27
0
 /// <summary>
 ///  Define service action that needs to be handled for receiver requests at the client
 /// </summary>
 /// <param name="hres"></param>
 /// <param name="clnt"></param>
 /// <param name="rcvr"></param>
 /// <returns></returns>
 private static Action DefineServiceAction(HiResTimer hres, WriterClient clnt, Receiver rcvr)
 {
     try
     {
         Action serviceAction = ServiceActionMake(hres, clnt, rcvr);
         return serviceAction;
     }
     catch (CustomException ex)
     {
         throw new CustomException("Error in define service action of writer client", ex);
     }
 }
Exemplo n.º 28
0
 private static Action ServiceActionMake(HiResTimer hres, WriterClient clnt, Receiver rcvr)
 {
     Action serviceAction = () =>
     {
         Message msg1 = null;
         while (true)
         {
             msg1 = rcvr.getMessage();   // note use of non-service method to deQ messages                           
             if (msg1.content == "done")
             {
                 hres.Stop(); ulong lookUpTime = hres.ElapsedMicroseconds;
                 Message msg2 = new Message();
                 msg2.fromUrl = clnt.localUrl;
                 msg2.toUrl = clnt.wpfClientURL;
                 msg2.content = "LookupTime;" + lookUpTime + ";" + "CntMsg;" + (ulong)clnt.total + ";";
                 Sender wpfSender = new Sender(clnt.localUrl);
                 wpfSender.sendMessage(msg2);
                 Console.WriteLine("\n----------------------Overall Performance Statistics for Write Client-----------------------------\n");
                 Console.WriteLine("Number of messages processed is {0}", clnt.total);
                 Console.WriteLine("\nTotal Execution time for the messages to be processed at Client Side is {0} microsecs", clnt.WriteClientTime);
                 Console.WriteLine("\nAverage Execution time for the messages to be processed at Client Side is {0} microsecs", clnt.WriteClientTime / (ulong)clnt.total);
                 Console.WriteLine("\nTotal Execution time for the messages from Client-Server-Client {0} microsecs", lookUpTime);
                 Console.WriteLine("\nAverage Execution time for the messages from Client-Server-Client is {0} microsecs", lookUpTime / (ulong)clnt.total);
                 Console.WriteLine("\n----------------------Overall Performance Statistics for Write Client-----------------------------\n");
                 break;
             }
             else if (msg1.content == "connection start message")
                 Console.WriteLine("Connection start message receieved at client side");
             else
             {
                 XDocument docTemp = XDocument.Load(new StringReader(msg1.content));
                 string mid = docTemp.Descendants("OperationMessage").Elements("MessageID").Single().Value;
                 string op = docTemp.Descendants("OperationMessage").Elements("Operation").Single().Value;
                 string resp = docTemp.Descendants("OperationMessage").Elements("Response").Single().Value;
                 Console.Write("\nMessage - MessageID:{0} received at the client", mid);
                 Console.Write("\nSender:{0}", msg1.fromUrl); Console.Write("\nOperation :{0}", op);
                 Console.Write("\nResponse :{0}", resp);
                 string oldDt = docTemp.Descendants("InsertTime").Select(i => i).Single().Value.ToString();
                 long microseconds = (DateTime.Now.Ticks - long.Parse(oldDt)) / 10;
                 Console.Write("\nExecution time for message(MessageID:{1}) is {0} microseconds\n", microseconds, mid);
             }
         }
         Util.waitForUser();
     };
     return serviceAction;
 }
Exemplo n.º 29
0
    static void Main(string[] args)
    {
try
        {
            HiResTimer hres = new HiResTimer(); //High Resolution Timer
            Console.Write("\nStarting CommService write client");
            Console.Write("\n =============================\n");
            Console.Title = "Write Client";
            Message msg = new Message();
            WriterClient clnt = new WriterClient();
            clnt.processCommandLine(args);
            string localPort = Util.urlPort(clnt.localUrl);
            string localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr = new Receiver(localPort, localAddr);
            Action serviceAction = DefineServiceAction(hres, clnt, rcvr);
            if (rcvr.StartService())
                rcvr.doService(serviceAction);
            Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message         
            msg.fromUrl = clnt.localUrl;
            msg.toUrl = clnt.remoteUrl;
            Console.Write("Sender's url is {0}", msg.fromUrl);
            Console.Write("Attempting to connect to {0}\n", msg.toUrl);
            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("Could not connect in {0} attempts\n", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }
            PerformanceTesting(hres, msg, clnt, rcvr, sndr);
        }
        catch (CustomException ex)
        {
            throw new CustomException("Error in main of writer client", ex);
        }
    }
Exemplo n.º 30
0
 void setupChannel()
 {
     try
     {
         rcvr = new Receiver(localPort, localAddress);
         Action serviceAction = () =>
         {
             try
             {
                 Message rmsg = null;
                 while (true)
                 {
                     rmsg = rcvr.getMessage();
                     Action act = () => { postRcvMsg(rmsg.content, rmsg.fromUrl); };
                     Dispatcher.Invoke(act, System.Windows.Threading.DispatcherPriority.Background);
                 }
             }
             catch (Exception ex)
             {
                 Action act = () =>
                 {
                     lblError.Content = ex.Message;
                 };
                 Dispatcher.Invoke(act);
             }
         };
         if (rcvr.StartService())
         {
             rcvr.doService(serviceAction);
         }
         TextBox lStat = new TextBox();
         sndr = new wpfSender(lStat, this.Dispatcher);
     }
     catch (CustomException wx)
     {
         Console.Write("Error in WPF client : {0}\n", wx.Message);
     }
 }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");
            Console.Title = "Writer Client to write on the NOSQL database";
            HiResTimer timerWriter = new HiResTimer();
            Client     clnt        = new Client();

            clnt.processCommandLine(args);
            string localPort = args[0];

            clnt.localUrl = "http://localhost:" + localPort + "/CommService";
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);

            rcvr.setTimerFromClient(timerWriter);
            clnt.startRcvrService(rcvr);
            Sender       sndr = new Sender(clnt.localUrl); // Sender needs localUrl for start message
            MessageMaker writerInput = new MessageMaker();
            Message      msg = new Message();
            string       fileName = ".\\WriterClientInput.xml";
            int          numberOfRequestsWriters = Convert.ToInt32(args[1]);
            XDocument    xmldoc = XDocument.Load(fileName);
            var          requests = xmldoc.Descendants("Request");
            int          requestCount = 0, i = 0; List <XElement> totalrequest = new List <XElement>();

            while (i < numberOfRequestsWriters)     //set the specified number of requests to send
            {
                totalrequest.Add(requests.ElementAt(i)); i++;
            }
            timerWriter.Start();
            foreach (var request in totalrequest)
            {
                msg           = new Message();
                msg           = writerInput.makeMessage(clnt.localUrl, clnt.remoteUrl, request);
                Console.Title = "Writer Client to write to NoSQl database: Writing " + (++requestCount) + " requests";
                if (!sndr.Connect(msg.toUrl))
                {
                    Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                    sndr.shutdown();
                    rcvr.shutDown();
                    return;
                }
                while (true)
                {
                    clnt.printMessage(msg);
                    if (!sndr.sendMessage(msg))
                    {
                        return;
                    }
                    Thread.Sleep(100);
                    break;
                }
                sndr.sendLatencyWriter(rcvr.avgLatency);
            }
            msg.content = "done";
            sndr.sendMessage(msg);
            Util.waitForUser();
            rcvr.shutDown();
            sndr.shutdown();
            Console.Write("\n\n");
        }