Beispiel #1
0
        public TopicWork(ICommentWork commentWork, IBannedWordWork bannedWordWork, IThreadWork threadWork, SettingWork settingWork)
        {
            _commentWork    = commentWork;
            _bannedWordWork = bannedWordWork;
            _threadWork     = threadWork;
            _settingWork    = settingWork;

            _defaultSetting = _settingWork.GetDefaultSetting();
        }
Beispiel #2
0
 public TopicDriver(ITopicWork contentTopicWork, ICommentWork commentWork,
                    ICommentDriver commentDriver, ITagWork tagWork, IThreadWork threadWork)
     : base(contentTopicWork)
 {
     _topicWork     = contentTopicWork;
     _commentWork   = commentWork;
     _commentDriver = commentDriver;
     _tagWork       = tagWork;
     _threadWork    = threadWork;
 }
Beispiel #3
0
        public CommentWork(IUploadFileWork uploadWork, IUploadFileCategoryWork uploadCategoryWork,
                           IBannedWordWork bannedWordWork, SettingWork settingWork, ThreadWork threadWork, IRepository <ContentTopic> topicRepository)
        {
            _topicRepository    = topicRepository;
            _uploadWork         = uploadWork;
            _uploadCategoryWork = uploadCategoryWork;
            _bannedWordWork     = bannedWordWork;
            _settingWork        = settingWork;
            _threadWork         = threadWork;

            _defaultSetting = _settingWork.GetDefaultSetting();
        }
Beispiel #4
0
        /// <summary>
        /// Handles executing the thread work.
        /// Thread logic:
        ///		While isClickerThreadRunning:
        ///			Wake anyone waiting for us to finish our current job
        ///			Wait for someone to set a new job and wake us up
        ///			Wake anyone waiting for us to confirm that we've recieved a job.
        ///			While threadWork.IsComplete():
        ///				Execute the job payload
        ///				Wait for either a confirmation to stop working or for a given time limit.
        /// </summary>
        private void WorkerThreadLogic()
        {
            lock (workerThreadLock)
            {
                while (true)
                {
                    if (!isClickerThreadRunning)
                    {
                        // If clickerThreadRunning flag has been set to false then main is waiting for us to confirm that
                        //   this thread has completed (main's waiting on isThreadComplete to be set to true)
                        Utils.OutputLine("Worker: PULSE becuase we're finished", Utils.OutputLevel.Threading);
                        isThreadComplete = true;
                        Monitor.Pulse(workerThreadLock);
                        return;
                    }

                    // Main must wait for 'threadWork' to be set to null before it can schedule more work. Let main know
                    //   that we're done with the previous work.
                    Utils.OutputLine("Worker: PULSE we set threadWork to null and we're waiting for work", Utils.OutputLevel.Threading);
                    threadWork = null;
                    Monitor.Pulse(workerThreadLock);

                    while (isClickerThreadRunning && threadWork == null)
                    {
                        // Wait for main to schedule some more work for us *or* for main to stop this thread.
                        Utils.OutputLine("Worker: WAIT for more work...", Utils.OutputLevel.Threading);
                        Monitor.Wait(workerThreadLock);
                        Utils.OutputLine("Worker: RESUME", Utils.OutputLevel.Threading);
                        Utils.OutputLine("Worker: PULSE for acknowledgement that we woke up from the pulse", Utils.OutputLevel.Threading);
                        Monitor.Pulse(workerThreadLock);
                    }

                    Utils.OutputLine("Worker: (debug) " + isClickerThreadRunning + " Threadwork: " + ((threadWork == null) ? "Null" : "Yes"), Utils.OutputLevel.Threading);

                    int retryCount = 0;
                    while (isClickerThreadRunning && threadWork != null && threadWork.IsComplete())
                    {
                        // Keep executing our payload every 'retryDelayInMs' ms until main tells us to top
                        //   executing it. Main must notify us whenever it stops executing.
                        //OutputLine("Execute...");
                        Utils.OutputLine("Worker: Execute...", Utils.OutputLevel.Threading);
                        threadWork.Execute(retryCount);
                        Utils.OutputLine("Worker: WAIT " + threadWork.GetRetryRate() + "ms", Utils.OutputLevel.Threading);
                        Monitor.Wait(workerThreadLock, threadWork.GetRetryRate());
                        Utils.OutputLine("Worker: RESUME", Utils.OutputLevel.Threading);

                        ++retryCount;
                    }
                    Utils.OutputLine("Worker: Done executing!", Utils.OutputLevel.Threading);
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Schedules a job. This function will BLOCK until the previously scheduled job has finished.
 /// </summary>
 /// <param name="newWork"></param>
 public void SetWork(IThreadWork newWork)
 {
     lock (workerThreadLock)
     {
         Utils.OutputLine("ClickObjectFace: StopThreadWork", Utils.OutputLevel.Game);
         StopThreadWork();
         Utils.OutputLine("ClickObjectFace: PULSE because new threadwork...", Utils.OutputLevel.Threading);
         threadWork = newWork;
         Monitor.Pulse(workerThreadLock);
         Utils.OutputLine("ClickObjectFace: WAIT for thread to start working...", Utils.OutputLevel.Threading);
         Monitor.Wait(workerThreadLock);
         Utils.OutputLine("ClickObjectFace: RESUME", Utils.OutputLevel.Threading);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Kills the thread pool thread if it's running. This function will BLOCK until the thread has
 /// completed. Must be called prior to shutting down to guarentee a clean exit.
 /// </summary>
 public void KillPreviousThread()
 {
     if (workerThread == null)
     {
         return;
     }
     lock (workerThreadLock)
     {
         Utils.OutputLine("KillPreviousThread: Previous thread still running, joining it...", Utils.OutputLevel.Game);
         StopThreadWork();
         isClickerThreadRunning = false;
         Monitor.Pulse(workerThreadLock);
         while (!isThreadComplete)
         {
             Utils.OutputLine("KillPreviousThread: WAIT for thread to end...", Utils.OutputLevel.Threading);
             Monitor.Wait(workerThreadLock);
             Utils.OutputLine("KillPreviousThread: RESUME", Utils.OutputLevel.Threading);
         }
         threadWork = null;
     }
     workerThread.Join();
     workerThread = null;
 }
Beispiel #7
0
 public ThreadDriver(IThreadWork threadWork)
     : base(threadWork)
 {
     _threadServic = threadWork;
 }
Beispiel #8
0
 public PermissionWork(IRepository <Permission> permissionRepository, IThreadWork threadWork)
 {
     _permissionRepository = permissionRepository;
     _threadWork           = threadWork;
 }
Beispiel #9
0
 public CommentDriver(ICommentWork commentWork, IThreadWork threadWork)
     : base(commentWork)
 {
     _commentWork = commentWork;
     _threadWordk = threadWork;
 }