Example #1
0
        public context(Timer _timer, double interval, Dispatcher _dispatcher)
        {
            classTimer.Interval = interval;
            classTimer.Elapsed += new System.Timers.ElapsedEventHandler(syncro_Elapsed);

            bindDispatcher(_dispatcher);
        }
Example #2
0
 private void bindDispatcher(Dispatcher dispatcherCopy)
 {
     lock (global_access_lock)
     {
         bindedDispatcher = dispatcherCopy;
     }
 }
Example #3
0
        static int Main(string[] args)
        {
            if (args.Count() == 0)
            {
                int jobsToCreate = 120;
                int maxJobLen = 400000;
                double weight = 40; //drag average prority of jobs toward this number
                double weightLegth = 100000;
                double variance = 1.1; //how much towards the "weight" variable will it be dragged, if bigger, then variance between numbers is larger
                Random rand = new Random((int)DateTime.UtcNow.Ticks);

                Console.WriteLine("Creating {0} jobs with avg. weight {1} with average length {2}.", jobsToCreate, weight, weightLegth);
                Console.WriteLine("");

                //create dispatcher and item queue
                Analyzer schedAnalyzer = new Analyzer();
                Dispatcher taskDispatch = new Dispatcher(20, 500, 100, schedAnalyzer);

                for (int a = 0; a < jobsToCreate; a++)
                {
                    //determine priority
                    int r1 = rand.Next(jobsToCreate);
                    int deviation = (int)(r1 - weight);
                    int r2 = rand.Next(Math.Abs(deviation));
                    ushort prior = (ushort)((deviation <= 0) ? ((r1 + r2)*variance) : ((r1 - r2)*variance));

                    //determine length of job
                    r1 = rand.Next(maxJobLen);
                    deviation = (int)(r1 - weightLegth);
                    r2 = rand.Next(Math.Abs(deviation));
                    uint len = (uint)((deviation <= 0) ? ((r1 + r2)*variance) : ((r1 - r2)*variance));

                    if (taskDispatch.addItem(a, prior, len) == 3)
                    {
                        Console.WriteLine("error, max jobs reached or other fault.");
                        return 1;
                    }

                    Console.WriteLine("Job #{0} : priority -> {1}, jobLength -> {2}", a, prior, len);
                }

                //send back stats; for testing / debug. See if more algorithm optimizations needed
                _QueueData_ datum = taskDispatch.debugStats();
                Console.Write("\nAvg Priority Level -> {0},  StdDev -> {1}\nAvg. Job Length -> {2},  stdDev -> {3}\n", datum.avgPrior, datum.sdevPrior, datum.avgLen, datum.sdevLen);

                //scheduling starts here
                Console.WriteLine("Press any key to start with scheduler.\n");
                Console.ReadKey();
                schedAnalyzer.analyzerData();

                //start system wide timer
                Timer syncro = new Timer(0.1);

                //create running context
                context context1 = new context(syncro, 0.1, taskDispatch);

                //initialize context
                context1.start();

                /*temp
                for (int i = 0; i < 50; i++)
                {
                    Console.WriteLine("Job ID:{0} run", taskDispatch.schedule());
                } */

            }
            Console.ReadKey();
            return 0;
        }