Changeset 5782 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
- Timestamp:
- 03/21/11 21:50:39 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
r5778 r5782 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 35 36 private bool wasJobAborted = false; 36 37 public Core Core { get; set; } 38 private Semaphore pauseStopSem = new Semaphore(0, 1); 37 39 38 40 private Exception currentException; … … 84 86 85 87 public void Pause() { 86 Job.Pause(); 87 88 if (Job == null) { 89 throw new InvalidStateException("Job is null"); 90 } 91 92 if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) { 93 try { 94 Job.Pause(); 95 //we need to block the pause... 96 pauseStopSem.WaitOne(); 97 } 98 catch (Exception ex) { 99 SlaveClientCom.Instance.ClientCom.LogMessage("Error pausing job:" + ex.ToString()); 100 } 101 } 88 102 } 89 103 90 104 public void Stop() { 105 if (Job == null) { 106 throw new InvalidStateException("Job is null"); 107 } 91 108 wasJobAborted = true; 109 92 110 if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) { 93 Job.Stop(); 94 } else { 95 Job_JobStopped(this, EventArgs.Empty); 111 try { 112 Job.Stop(); 113 pauseStopSem.WaitOne(); 114 } 115 catch (Exception ex) { 116 SlaveClientCom.Instance.ClientCom.LogMessage("Error stopping job:" + ex.ToString()); 117 } 96 118 } 97 119 } … … 103 125 Job.WaitForChildJobs += new EventHandler(Job_WaitForChildJobs); 104 126 Job.DeleteChildJobs += new EventHandler(Job_DeleteChildJobs); 127 Job.JobPaused += new EventHandler(Job_JobPaused); 105 128 } 106 129 … … 111 134 Job.WaitForChildJobs -= new EventHandler(Job_WaitForChildJobs); 112 135 Job.DeleteChildJobs -= new EventHandler(Job_DeleteChildJobs); 136 Job.JobPaused -= new EventHandler(Job_JobPaused); 113 137 } 114 138 … … 159 183 private void Job_JobStopped(object sender, EventArgs e) { 160 184 if (wasJobAborted) { 161 Core.EnqueueExecutorMessage(Core.KillAppDomain, JobId);185 pauseStopSem.Release(); 162 186 } else { 187 //it's a clean and finished job, so send it 163 188 Core.EnqueueExecutorMessage(Core.SendFinishedJob, JobId); 164 189 } … … 171 196 172 197 if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) { 173 try { Job.Stop(); } 174 catch { } 198 try { 199 Job.Stop(); 200 wasJobAborted = true; 201 pauseStopSem.WaitOne(); 202 } 203 catch (Exception ex) { 204 SlaveClientCom.Instance.ClientCom.LogMessage("Error stopping job:" + ex.ToString()); 205 } 175 206 } 176 207 … … 178 209 } 179 210 211 180 212 public JobData GetPausedJob() { 181 if (Job == null) { 182 throw new InvalidStateException("Job is null"); 183 } 184 185 if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) { 186 try { Job.Pause(); } 187 catch { } 188 } 189 213 if (Job.ExecutionState != HeuristicLab.Core.ExecutionState.Paused) { 214 throw new Exception("Executor: Job has to be paused before fetching results."); 215 } 190 216 return GetJob(); 217 } 218 219 private void Job_JobPaused(object sender, EventArgs e) { 220 pauseStopSem.Release(); 191 221 } 192 222
Note: See TracChangeset
for help on using the changeset viewer.