Exemple #1
0
        private static int Main(string[] args)
        {
            Options options = new Options();
            CommandLineParser parser = new CommandLineParser(options);
            parser.Parse();
            if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.GetErrorsAsString(78));
                return -1;
            }
            if (options.Help)
            {
                Console.WriteLine(parser.UsageInfo.GetOptionsAsString(78));
                return 0;
            }
            bool singleProcess =
                (!options.Setup && !options.Control && !options.Publish && !options.Subscribe);
            if (singleProcess)
            {
                options.Setup = options.Control = options.Publish =  true;
                options.Subscribe = true;
            }
                

            string exchange = "amq.direct";
            switch (options.Mode)
            {
                case "shared":
                    options.SubQuota = (options.Pubs*options.Count)/options.Subs;
                    break;
                case "fanout":
                    options.SubQuota = (options.Pubs*options.Count);
                    exchange = "amq.fanout";
                    break;
                case "topic":
                    options.SubQuota = (options.Pubs*options.Count);
                    exchange = "amq.topic";
                    break;
            }

            if (options.Setup)
            {
                SetupTest setup = new SetupTest(options);
                setup.Start(); // Set up queues
            }

            Thread contT = null;
            if ( options.Control)
            {
                Controller c = new Controller(options);
                contT = new Thread(c.Start);
                contT.Start();
            }

            Thread[] publishers = null;
            Thread[] subscribers = null;

            // Start pubs/subs for each queue/topic.
            for (int i = 0; i < options.Queues; ++i)
            {
                string key = "perftest" + i; // Queue or topic name.
                if (options.Publish)
                {
                    int n = singleProcess ? options.Pubs : 1;
                    publishers = new Thread[n];
                    for (int j = 0; j < n; ++j)
                    {
                        PublishThread pt = new PublishThread(options, key, exchange);
                        publishers[i] = new Thread(pt.Start);
                        publishers[i].Start();
                    }
                }
                if ( options.Subscribe)
                {
                    int n = singleProcess ? options.Subs : 1;
                    subscribers = new Thread[n];
                    for (int j = 0; j < n; ++j)
                    {
                        SubscribeThread st;
                        if (options.Mode.Equals("shared"))
                            st = new SubscribeThread(options, key);
                        else
                            st = new SubscribeThread(options, key, exchange);
                        subscribers[i] = new Thread(st.Start);
                        subscribers[i].Start();
                    }
                }
            }

            if (options.Control)
            {
                contT.Join();
            }


            // Wait for started threads.
            if (options.Publish)
            {
                foreach (Thread t in publishers)
                {
                    t.Join();
                }
            }

            if (options.Subscribe)
            {
                foreach (Thread t in subscribers)
                {
                    t.Join();
                }
            }


            return 0;
        }
        private static int Main(string[] args)
        {
            Options           options = new Options();
            CommandLineParser parser  = new CommandLineParser(options);

            parser.Parse();
            if (parser.HasErrors)
            {
                Console.WriteLine(parser.UsageInfo.GetErrorsAsString(78));
                return(-1);
            }
            if (options.Help)
            {
                Console.WriteLine(parser.UsageInfo.GetOptionsAsString(78));
                return(0);
            }
            bool singleProcess =
                (!options.Setup && !options.Control && !options.Publish && !options.Subscribe);

            if (singleProcess)
            {
                options.Setup     = options.Control = options.Publish = true;
                options.Subscribe = true;
            }


            string exchange = "amq.direct";

            switch (options.Mode)
            {
            case "shared":
                options.SubQuota = (options.Pubs * options.Count) / options.Subs;
                break;

            case "fanout":
                options.SubQuota = (options.Pubs * options.Count);
                exchange         = "amq.fanout";
                break;

            case "topic":
                options.SubQuota = (options.Pubs * options.Count);
                exchange         = "amq.topic";
                break;
            }

            if (options.Setup)
            {
                SetupTest setup = new SetupTest(options);
                setup.Start(); // Set up queues
            }

            Thread contT = null;

            if (options.Control)
            {
                Controller c = new Controller(options);
                contT = new Thread(c.Start);
                contT.Start();
            }

            Thread[] publishers  = null;
            Thread[] subscribers = null;

            // Start pubs/subs for each queue/topic.
            for (int i = 0; i < options.Queues; ++i)
            {
                string key = "perftest" + i; // Queue or topic name.
                if (options.Publish)
                {
                    int n = singleProcess ? options.Pubs : 1;
                    publishers = new Thread[n];
                    for (int j = 0; j < n; ++j)
                    {
                        PublishThread pt = new PublishThread(options, key, exchange);
                        publishers[i] = new Thread(pt.Start);
                        publishers[i].Start();
                    }
                }
                if (options.Subscribe)
                {
                    int n = singleProcess ? options.Subs : 1;
                    subscribers = new Thread[n];
                    for (int j = 0; j < n; ++j)
                    {
                        SubscribeThread st;
                        if (options.Mode.Equals("shared"))
                        {
                            st = new SubscribeThread(options, key);
                        }
                        else
                        {
                            st = new SubscribeThread(options, key, exchange);
                        }
                        subscribers[i] = new Thread(st.Start);
                        subscribers[i].Start();
                    }
                }
            }

            if (options.Control)
            {
                contT.Join();
            }


            // Wait for started threads.
            if (options.Publish)
            {
                foreach (Thread t in publishers)
                {
                    t.Join();
                }
            }

            if (options.Subscribe)
            {
                foreach (Thread t in subscribers)
                {
                    t.Join();
                }
            }


            return(0);
        }