Changeset 5782
- Timestamp:
- 03/21/11 21:50:39 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 2 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 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/OptimizerJob.cs
r5450 r5782 154 154 } 155 155 156 public v oid Pause() {156 public virtual void Pause() { 157 157 optimizer.Pause(); 158 158 } … … 173 173 174 174 public event EventHandler JobPaused; 175 protected v oid OnJobPaused(object sender, EventArgs e) {175 protected virtual void OnJobPaused() { 176 176 EventHandler handler = JobPaused; 177 177 if (handler != null) handler(this, EventArgs.Empty); … … 218 218 protected virtual void RegisterEvents() { 219 219 optimizer.Stopped += new EventHandler(optimizer_Stopped); 220 optimizer.Paused += new EventHandler( OnJobPaused);220 optimizer.Paused += new EventHandler(optimizer_Paused); 221 221 optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred); 222 222 optimizer.DescriptionChanged += new EventHandler(optimizer_DescriptionChanged); … … 229 229 protected virtual void DeregisterEvents() { 230 230 optimizer.Stopped -= new EventHandler(optimizer_Stopped); 231 optimizer.Paused -= new EventHandler( OnJobPaused);231 optimizer.Paused -= new EventHandler(optimizer_Paused); 232 232 optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred); 233 233 optimizer.DescriptionChanged -= this.DescriptionChanged; … … 265 265 OnJobStopped(); 266 266 } 267 268 protected virtual void optimizer_Paused(object sender, EventArgs e) { 269 OnJobPaused(); 270 } 267 271 #endregion 268 272
Note: See TracChangeset
for help on using the changeset viewer.