示例#1
0
        /// <summary>
        /// Stops an application.
        /// </summary>
        public void Stop()
        {
            //first check if the application is all finished
            IManagerStorage        store = ManagerStorageFactory.ManagerStorage();
            ApplicationStorageView app   = store.GetApplication(_Id);

            if (app.State != ApplicationState.Stopped)
            {
                ThreadStorageView[] threads = store.GetThreads(_Id);

                foreach (ThreadStorageView thread in threads)
                {
                    if (thread.State != ThreadState.Dead && thread.State != ThreadState.Finished)
                    {
                        GManager.AbortThread(new ThreadIdentifier(_Id, thread.ThreadId), thread.ExecutorId);

                        // clean up the thread status
                        thread.State = ThreadState.Dead;
                        store.UpdateThread(thread);
                    }
                }

                //update the application
                app.State         = ApplicationState.Stopped;
                app.TimeCompleted = DateTime.Now;
                store.UpdateApplication(app);

                logger.Debug("Stopped the current application." + _Id);
            }
            else
            {
                logger.Debug(string.Format("Application {0} already stopped.", _Id));
            }
        }
示例#2
0
        /// <summary>
        /// Return the thread with the highest priority from the pool of Ready threads.
        ///
        /// Note: pathetic way of selecting the highest priority thread.
        ///		This should be moved into the storage for a more efficient implementation.
        /// </summary>
        /// <returns></returns>
        protected ThreadStorageView GetNextAvailableThread()
        {
            // achieve thread safety by locking on a static variable
            // this lock is not enough, we should lock until the thread status changes
            lock (threadChooserLock)
            {
                ThreadStorageView[] threads = store.GetThreads(ApplicationState.Ready, ThreadState.Ready);

                if (threads == null || threads.Length == 0)
                {
                    return(null);
                }

                ThreadStorageView highestPriorityThread = threads[0];

                foreach (ThreadStorageView thread in threads)
                {
                    if (thread.Priority > highestPriorityThread.Priority)
                    {
                        highestPriorityThread = thread;
                    }
                }

                return(highestPriorityThread);
            }
        }