예제 #1
0
        public override void Run()
        {
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            string instanceId    = RoleEnvironment.CurrentRoleInstance.Id;
            int    instanceIndex = 0;

            if (int.TryParse(instanceId.Substring(instanceId.LastIndexOf(".") + 1), out instanceIndex)) // On cloud.
            {
                int.TryParse(instanceId.Substring(instanceId.LastIndexOf("_") + 1), out instanceIndex); // On compute emulator.
            }

            for (int i = 0; i < THREADS_PER_TOPIC * TOPICS; i++)
            {
                int topicnumber = 0;
#if DEBUG
                topicnumber = 1;
#else
                topicnumber = (i - (i % THREADS_PER_TOPIC)) / THREADS_PER_TOPIC + 1;
#endif

                agents.Add(WorkerAgent.Start(instanceIndex, i % THREADS_PER_TOPIC + 1, topicnumber));
            }

            int  seconds = 0;
            long recordsincurrentminute = 0;
            long lastminutestotal       = 0;

            while (true)
            {
                //long messagesProcessed = 0;
                //foreach(WorkerAgent wa in agents)
                //{

                //messagesProcessed += Interlocked.Read(ref wa.MessagesProcessed);
                //}

                Thread.Sleep(10000);

                //seconds++;

                //if (seconds % 60 == 0)
                //{
                //recordsincurrentminute = messagesProcessed - lastminutestotal;

                //Trace.WriteLine(recordsincurrentminute);

                //lastminutestotal = messagesProcessed;

                //}
            }
        }
예제 #2
0
        public static WorkerAgent Start(int instanceNumber, int threadNumber, int messageTopicNumber)
        {
            WorkerAgent instance = new WorkerAgent(instanceNumber, threadNumber, messageTopicNumber);

            return(instance);
        }