Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
 public void startRcvrService(Receiver rcvr)
 {   //start receiver service
     if (rcvr.StartService())
     {
         rcvr.doService(rcvr.defaultServiceAction());
     }
 }
 public void startRcvrService(Receiver rcvr)
 {
     if (rcvr.StartService())
     {
         rcvr.doService(rcvr.defaultServiceAction());
     }
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("  The intent of the write client is to stress the database with write operations.");
            Console.WriteLine("  Write operations - Insert, Delete, Edit name, Edit Description and Add Children.");
            Console.WriteLine("\n  If log option is enabled, messsages are logged to this console window as they are sent.");
            Console.WriteLine("  If log is enabled result of response is displayed as responses are received from server.");
            Console.WriteLine("  If log option is disabled, only latency time for each operation is disaplyed on the console window.");
            Client clnt = new Client();

            clnt.processCommandLine(args);
            bool log_message = clnt.processCommandLineForWriteLog(args);

            if (log_message)
            {
                Console.WriteLine("  (Log option is Enabled for this client)");
            }
            else
            {
                Console.WriteLine("  (Log option is Disabled for this client)");
            }
            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);
            string   win_title = "Write Client - " + localPort;

            Console.Title = win_title;
            Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
            Action client_receive_action = clnt.define_receive_action(rcvr, sndr, log_message, localPort);

            if (rcvr.StartService())
            {
                rcvr.doService(client_receive_action);
            }
            Message msg = new Message();

            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;
            Console.WriteLine("\n\n  Starting CommService  Write client");
            Console.Write("  =============================");
            Console.Write("\n  Write client local url is {0}", msg.fromUrl);
            Console.Write("\n  Attempting to connect to server on {0}\n", msg.toUrl);
            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  Could not connect to server in {0} attempts, closing application.", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }
            Console.WriteLine("\n  *****************************\n  Going to read messages present in XML file - Write_Client_XML.xml and send them sequentially to server.\n  *****************************");
            clnt.send_messages(sndr, msg, "./../../../../SavedXMLFiles/Write_Client_XML.xml", log_message);
            Thread.Sleep(100);
            msg.content = "done";
            sndr.sendMessage(msg);
            Util.waitForUser();
            // shut down this client's Receiver and Sender by sending close messages
            rcvr.shutDown();
            sndr.shutdown();
            Console.Write("\n\n");
        }
Ejemplo n.º 5
0
 // start service of server
 public bool doService()
 {
     if (rcvr.StartService())
     {
         rcvr.doService(ServiceAction());
         return true;
     }
     return false;
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Thread.Sleep(2000);
            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");
            Console.Title = "Reader Client";
            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();
            rcvr.setTotalMessageSize(clnt.getMsgLen("XMLReader.xml"));
            clnt.readMsgTemplate("XMLReader.xml", sndr);
            while (true)
            {
                if (rcvr.getLastFlag())
                {
                    clnt.hrt.Stop();
                    break;
                }
            }
            ulong latency = clnt.hrt.ElapsedMicroseconds;

            clnt.travelLatency(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");
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("  The intent of the demo client is to demonstarte that all the operations of Project-2 can be executed remotely.");
            Console.WriteLine("  All the request messages stored in /SavedXMLFiles/Demo_Client_XML.xml are sent to server sequentially.");
            Console.WriteLine("  The Demo_Client_XML.xml file consists of Write operations, Read operations and Persist operations.");
            Console.WriteLine("  Write operations - Insert, Delete, Edit Name, Edit Description and Add Children");
            Console.WriteLine("  Read operations - Get Value, Get Children, Get Keys with string pattern in metadata");
            Console.WriteLine("  PErsist operations - Persist database, Load Database");
            Console.WriteLine("\n  The DB contents are displayed on the server only in case of demo client to show the successful operations on DB.");
            Console.WriteLine("  These are displayed to show to user that operations are successfully performed on the database.");
            Console.WriteLine("\n  ******************\n  To launch the readers and writers enter any key on the TestExecutive window.");
            Console.WriteLine("  You can verify all types of operations done and displayed on server window, before launching readers and writers.");
            Console.Write("\n  Starting CommService for demo client");
            Console.Write("\n ================================\n");
            Thread.Sleep(1000);
            bool   log_message = true;
            Client clnt        = new Client();

            clnt.processCommandLine(args);
            Receiver rcvr      = new Receiver(Util.urlPort(clnt.localUrl), Util.urlAddress(clnt.localUrl));
            string   win_title = "Demo Client - " + Util.urlPort(clnt.localUrl);

            Console.Title = win_title;
            Action client_receive_action = clnt.define_receive_action(rcvr, log_message);

            if (rcvr.StartService())
            {
                rcvr.doService(client_receive_action);
            }
            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  Demo client local url is {0}", msg.fromUrl);
            Console.Write("\n  Attempting to connect to server on {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.send_messages(sndr, msg, "./../../../../SavedXMLFiles/Demo_Client_XML.xml", log_message);
            Thread.Sleep(100);
            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");
        }
 public WriteClient(string LocalUrl, string ToUrl)
 {
     localUrl  = LocalUrl;
     remoteUrl = ToUrl;
     rcvr      = new Receiver(Utilities.urlPort(localUrl), Utilities.urlAddress(localUrl));
     if (rcvr.StartService())
     {
         rcvr.doService(rcvr.defaultServiceAction());
     }
     sndr = new Sender(localUrl);
 }
Ejemplo n.º 9
0
 public ReadClient(string LocalUrl, string ToUrl)
 {
     acts      = new Dictionary <string, Func <Message, string> >();
     localUrl  = LocalUrl;
     remoteUrl = ToUrl;
     rcvr      = new Receiver(Utilities.urlPort(localUrl), Utilities.urlAddress(localUrl));
     if (rcvr.StartService())
     {
         rcvr.doService(serviceAction());
     }
     sndr = new Sender(localUrl);
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            MessageMaker msgMaker = new MessageMaker();

            Console.Write("\nStarting Test Executive");
            Console.Write("\n=============================\n");
            Message    msg   = new Message();
            HiResTimer timer = new HiResTimer();

            Console.Title = "Write Client";
            WriteClient writeClient = new WriteClient();

            if (args.Length == 2)
            {
                writeClient.numMsg = Convert.ToInt32(args[1]);
            }
            writeClient.processCommandLine(args);
            string   localPort = Util.urlPort(writeClient.localUrl);
            string   localAddr = Util.urlAddress(writeClient.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr, timer);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }
            Sender    sndr     = new Sender(writeClient.localUrl); // Sender needs localUrl for start message
            XDocument xmlInput = writeClient.GetInputFromXml();
            var       results  = xmlInput.Descendants("element");

            writeClient.sendMessageToServer(results, timer, msgMaker, sndr, rcvr);
            Console.Write("\n  sender's url is {0}", writeClient.localUrl);
            Console.Write("\n  attempting to connect to {0}\n", writeClient.remoteUrl);
            //Wait until all messages from server are received.
            while (rcvr.count < writeClient.numMsg)
            {
                sndr.SendWriterLatency(rcvr.totalExecutionTime / rcvr.count);
            }
            msg.content = "done";
            msg.fromUrl = writeClient.localUrl;
            msg.toUrl   = writeClient.remoteUrl;
            sndr.sendMessage(msg);
            Util.waitForUser();
            sndr.SendWriterLatency(rcvr.totalExecutionTime / rcvr.count);
            rcvr.shutDown();
            sndr.shutdown();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            TestExecutive test = new TestExecutive();

            if (args.Count() == 4)
            {
                test.readers           = Convert.ToInt32(args[0]);
                test.writers           = Convert.ToInt32(args[1]);
                test.numReaderMessages = Convert.ToInt32(args[2]);
                test.numWriterMessages = Convert.ToInt32(args[3]);
            }
            MessageMaker msgMaker = new MessageMaker();
            HiResTimer   timer    = new HiResTimer();
            Message      msg      = new Message();

            Console.Write("\nStarting Test Executive");
            Console.Write("\n=============================\n");
            Console.Title = "Test Executive";
            string   localPort = Util.urlPort(test.localUrl);
            string   localAddr = Util.urlAddress(test.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr, timer);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }
            Sender    sndr     = new Sender(test.localUrl); // Sender needs localUrl for start message
            XDocument xmlInput = test.GetInputFromXml();
            var       results  = xmlInput.Descendants("element");

            Console.Write("\n  sender's url is {0}", test.localUrl);
            Console.Write("\n  attempting to connect to {0}\n", test.remoteUrl);
            timer.Start();
            test.sendMessageToServer(results, timer, msgMaker, sndr, rcvr);
            msg.content = "done";
            msg.fromUrl = test.localUrl;
            msg.toUrl   = test.remoteUrl;
            sndr.sendMessage(msg);
            Console.WriteLine("\n\nPress any key to start performance testing...");
            Util.waitForUser();
            test.LaunchReadersAndWriters();
            rcvr.shutDown();
            sndr.shutdown();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);

            bool log_messages = true;

            string srv_win = "Server - " + srvr.port;

            Console.Title = srv_win;
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");
            //Console.WriteLine("Going to create a DB and add a single element to it:");


            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 = srvr.define_server_receiveaction(rcvr, sndr, log_messages);

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.

            Thread.Sleep(10000);
            Util.waitForUser();
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");

            Console.Title = "Client #2";

            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");
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
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.
        }
Ejemplo n.º 16
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;
            }
        }
Ejemplo n.º 17
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(); 
    }
Ejemplo n.º 18
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();
        }
Ejemplo n.º 19
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.
        }
Ejemplo n.º 20
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);
     }
 }
Ejemplo n.º 21
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");
        }
 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 = "Write Client: " + localPort;
   if (rcvr.StartService())
     rcvr.doService(doserviceAction(rcvr));
   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 write1.xml file".title();
   string path = Path.GetFullPath("../../../Write Client/bin/Debug/write1.xml");
   XDocument newDoc = XDocument.Load(path);
   clnt.write_clinet_parse.Start();
   Parser p = new Parser(logger_flag);
   p.parse(newDoc, ref msg, sndr);
   Message msg1 = new Message();
   msg1.fromUrl = clnt.localUrl;
   msg1.toUrl = clnt.remoteUrl;
   msg1.content = "done";
   sndr.sendMessage(msg1);
   clnt.write_clinet_parse.Stop();
   Message msg2 = new Message();
   msg2.fromUrl = clnt.localUrl;
   msg2.toUrl = clnt.remoteUrl;
   msg2.content = "write-client," + clnt.write_clinet_parse.ElapsedMicroseconds;
   sndr.sendMessage(msg2);
   Console.WriteLine("\n\nWrite-Client Processing Time: " + clnt.write_clinet_parse.ElapsedMicroseconds + " microseconds\n");
   // 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");
 }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            //Thread.Sleep(1500);
            Console.Write("\n  starting CommService writer client");
            Console.Write("\n =======================================\n");
            Console.Write("\n XML for Reading template is XMLWriter.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.Write("\n Demonstrating Requirement #4 by sending add/delete/edit/persist/augment messages from writer client to server.");
            Console.Write("\n Demonstrating Requirement #5 by taking format of request from XML and showing performance on GUI as well as on Console(If logging switch is on).");
            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;
            }

            clnt.hrt.Start();
            rcvr.setTotalMessageSize(clnt.getMessageSize("XMLWriter.xml"));
            clnt.readMessageTemplates("XMLWriter.xml", sndr);
            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");
 }
Ejemplo n.º 25
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");
 }
Ejemplo n.º 26
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);
     }
 }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            Console.WriteLine("  The intent of the read client is to stress the database with read operations.\n  Read operations - Get DBElement with key, Get children of DBElement, Get keys of DBElements with particular pattern.");
            Console.WriteLine("\n  If partial log option is enabled, only a partial part of the response messsage is logged to this console window.(latency and part of result)\n  If Partial log option is not enabled, entire result is displayed on the GUI.");
            Console.WriteLine("  For all requests, latency time for each message is displayed on this window and WPF GUI.");
            Console.WriteLine("  Once all request messages are received, average latency times are updated in WPF GUI.");
            Client clnt = new Client();

            clnt.processCommandLine(args);
            bool log_message = true;

            if (clnt.processCommandLineForPartialLog(args))
            {
                log_message = false;
            }
            if (!log_message)
            {
                Console.WriteLine("  (Partial log option is enabled for this client)");
            }
            else
            {
                Console.WriteLine(" (Partial log option is not enabled for this client.)");
            }

            Console.Write("\n  Starting CommService Read client");
            Console.Write("\n  =============================\n");
            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);
            string   win_title = "Read Client - " + localPort;

            Console.Title = win_title;

            Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message
            Action client_receive_action = clnt.define_receive_action(rcvr, log_message, sndr, localPort);

            if (rcvr.StartService())
            {
                rcvr.doService(client_receive_action);
            }
            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;
            }
            Console.WriteLine("\n  *****************************\n  Going to read messages present in XML file - Read_Client_XML.xml and send them sequentially to server.\n  *****************************");
            clnt.send_messages(sndr, msg, "./../../../../SavedXMLFiles/Read_Client_XML.xml", log_message);
            Thread.Sleep(100);
            msg.content = "done";
            sndr.sendMessage(msg);
            Util.waitForUser();
            rcvr.shutDown();
            sndr.shutdown();
            Console.Write("\n\n");
        }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Mains the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            DatabaseController dbController = new DatabaseController();

            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);
            double totalTime = 0;
            int    count     = 0;

            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);
            Action   serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    HiResTimer timer = new HiResTimer();
                    timer.Start();
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    srvr.displayReceivedMsg(msg);
                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client {0} has finished\n", msg.fromUrl);
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    if (msg.fromUrl == "http://localhost:8080/CommService")
                    {
                        continue;
                    }
                    var result = dbController.QueryDatabase(msg.content);
                    msg.content = "received " + msg.content + " from " + msg.fromUrl;
                    Util.swapUrls(ref msg);
                    Message testMsg = new Message {
                        content = result, fromUrl = msg.fromUrl, toUrl = msg.toUrl
                    };
                    srvr.displaySentMsg(msg, result);
                    sndr.sendMessage(testMsg);
                    timer.Stop();
                    sndr.SendServerThroughput(srvr.calculateThroughput(timer, ref totalTime, ++count));
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // so the call doesn't block.
            }
            Util.waitForUser();
        }
        //----< 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);
        }
Ejemplo n.º 31
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);
        }
    }