Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Insufficient number of arguments.");
                usage();
                Environment.Exit(-1);
            }
            else
            {
                string publisherName     = args[0];
                int    ownershipStrength = int.Parse(args[1]);
                int    numOfIterations   = int.Parse(args[2]);
                bool   stopSubscriber    = bool.Parse(args[3]);

                OwnershipPublisher pub = new OwnershipPublisher(publisherName, ownershipStrength);
                pub.setStrength(ownershipStrength);

                Console.WriteLine("=== [Publisher] Publisher  {0} with strength: {1} ", publisherName, ownershipStrength);
                Console.WriteLine(" / sending {0} prices ... stop_subscriber flag= {1}", numOfIterations, stopSubscriber.ToString());


                // The subscriber should display the prices in dollars
                float price = 10.0f;

                for (int x = 0; x < numOfIterations; x++)
                {
                    pub.publishEvent(price, publisherName);
                    Thread.Sleep(200);
                    price += 0.5f;
                }

                Thread.Sleep(2000);

                if (stopSubscriber)
                {
                    price = -1.0f;
                    Console.WriteLine("=== Stopping the subscriber");
                    pub.publishEvent(price, publisherName);
                }

                pub.dispose();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Insufficient number of arguments.");
                usage();
                Environment.Exit(-1);
            }
            else
            {
                string publisherName = args[0];
                int ownershipStrength = int.Parse(args[1]);
                int numOfIterations = int.Parse(args[2]);
                bool stopSubscriber = bool.Parse(args[3]);

                OwnershipPublisher pub = new OwnershipPublisher(publisherName, ownershipStrength);
                pub.setStrength(ownershipStrength);

                Console.WriteLine("=== [Publisher] Publisher  {0} with strength: {1} ", publisherName, ownershipStrength);
                Console.WriteLine(" / sending {0} prices ... stop_subscriber flag= {1}", numOfIterations, stopSubscriber.ToString());

                // The subscriber should display the prices in dollars
                float price = 10.0f;

                for (int x = 0; x < numOfIterations; x++)
                {
                    pub.publishEvent(price, publisherName);
                    Thread.Sleep(200);
                    price += 0.5f;
                }

                Thread.Sleep(2000);

                if (stopSubscriber)
                {
                    price = -1.0f;
                    Console.WriteLine("=== Stopping the subscriber");
                    pub.publishEvent(price, publisherName);
                }

                pub.dispose();
            }
        }