- Timestamp:
- 04/16/13 13:13:41 (12 years ago)
- Location:
- branches/OaaS
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 23 24 packages
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/OaaS/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs
r8165 r9363 31 31 32 32 namespace HeuristicLab.Clients.Hive { 33 public class RefreshableJob : IHiveItem, IDeepCloneable, IContent, IComparable<RefreshableJob> {33 public class RefreshableJob : IHiveItem, IDeepCloneable, IContent, IComparable<RefreshableJob>, IDisposable { 34 34 private JobResultPoller jobResultPoller; 35 35 private ConcurrentTaskDownloader<ItemTask> jobDownloader; 36 private static object locker = new object(); 36 private object locker = new object(); 37 private object downloadFinishedLocker = new object(); 38 object jobResultReceivedLocker = new object(); 37 39 38 40 public bool IsProgressing { get; set; } … … 46 48 throw new ArgumentNullException(); 47 49 48 if (job != null) Der gisterJobEvents();50 if (job != null) DeregisterJobEvents(); 49 51 job = value; 50 52 if (job != null) { … … 64 66 set { 65 67 if (hiveTasks != value) { 66 if (hiveTasks != null) DeregisterHive JobsEvents();68 if (hiveTasks != null) DeregisterHiveTasksEvents(); 67 69 hiveTasks = value; 68 if (hiveTasks != null) RegisterHive JobsEvents();70 if (hiveTasks != null) RegisterHiveTasksEvents(); 69 71 OnHiveTasksChanged(); 70 72 } … … 156 158 157 159 // may execute jobs with privileged permissions on slaves 158 private bool isAllowedPrivileged = true;159 160 public bool IsAllowedPrivileged { 160 get { return isAllowedPrivileged; }161 get { return Job.IsPrivileged; } 161 162 set { 162 if (value != isAllowedPrivileged) {163 isAllowedPrivileged = value;163 if (value != Job.IsPrivileged) { 164 Job.IsPrivileged = value; 164 165 OnIsAllowedPrivilegedChanged(); 165 166 } … … 188 189 #region Constructors and Cloning 189 190 public RefreshableJob() { 190 this.refreshAutomatically = true;191 this.refreshAutomatically = false; 191 192 this.Job = new Job(); 192 193 this.log = new ThreadSafeLog(); … … 228 229 jobResultPoller = new JobResultPoller(job.Id, Settings.Default.ResultPollingInterval); 229 230 RegisterResultPollingEvents(); 230 jobResultPoller.AutoResumeOnException = true;231 jobResultPoller.AutoResumeOnException = false; 231 232 } 232 233 … … 239 240 if (jobResultPoller != null && jobResultPoller.IsPolling) { 240 241 jobResultPoller.Stop(); 242 DeregisterResultPollingEvents(); 241 243 } 242 244 } … … 258 260 } 259 261 } 262 260 263 private void jobResultPoller_JobResultReceived(object sender, EventArgs<IEnumerable<LightweightTask>> e) { 261 foreach (LightweightTask lightweightTask in e.Value) { 262 HiveTask hiveTask = GetHiveTaskById(lightweightTask.Id); 263 if (hiveTask != null) { 264 // lastJobDataUpdate equals DateTime.MinValue right after it was uploaded. When the first results are polled, this value is updated 265 if (hiveTask.Task.State == TaskState.Offline && lightweightTask.State != TaskState.Finished && lightweightTask.State != TaskState.Failed && lightweightTask.State != TaskState.Aborted) { 266 hiveTask.Task.LastTaskDataUpdate = lightweightTask.LastTaskDataUpdate; 267 } 268 269 hiveTask.UpdateFromLightweightJob(lightweightTask); 270 271 if (!hiveTask.IsFinishedTaskDownloaded && !hiveTask.IsDownloading && hiveTask.Task.LastTaskDataUpdate < lightweightTask.LastTaskDataUpdate) { 272 log.LogMessage(string.Format("Downloading task {0}", lightweightTask.Id)); 273 hiveTask.IsDownloading = true; 274 jobDownloader.DownloadTaskData(hiveTask.Task, (localJob, itemJob) => { 275 log.LogMessage(string.Format("Finished downloading task {0}", localJob.Id)); 276 HiveTask localHiveTask = GetHiveTaskById(localJob.Id); 277 278 if (itemJob == null) { 279 localHiveTask.IsDownloading = false; 280 } 281 282 if (itemJob == null) { 283 // something bad happened to this task. bad task, BAAAD task! 284 } else { 285 // if the task is paused, download but don't integrate into parent optimizer (to avoid Prepare) 286 287 if (localJob.State == TaskState.Paused) { 288 localHiveTask.ItemTask = itemJob; 289 } else { 290 if (localJob.ParentTaskId.HasValue) { 291 HiveTask parentHiveTask = GetHiveTaskById(localJob.ParentTaskId.Value); 292 parentHiveTask.IntegrateChild(itemJob, localJob.Id); 264 lock (jobResultReceivedLocker) { 265 foreach (LightweightTask lightweightTask in e.Value) { 266 HiveTask hiveTask = GetHiveTaskById(lightweightTask.Id); 267 if (hiveTask != null) { 268 // lastJobDataUpdate equals DateTime.MinValue right after it was uploaded. When the first results are polled, this value is updated 269 if (hiveTask.Task.State == TaskState.Offline && lightweightTask.State == TaskState.Waiting) { 270 hiveTask.Task.LastTaskDataUpdate = lightweightTask.LastTaskDataUpdate; 271 } 272 273 hiveTask.UpdateFromLightweightJob(lightweightTask); 274 275 if (!hiveTask.IsFinishedTaskDownloaded && !hiveTask.IsDownloading && hiveTask.Task.LastTaskDataUpdate < lightweightTask.LastTaskDataUpdate && (lightweightTask.State == TaskState.Finished || lightweightTask.State == TaskState.Aborted || lightweightTask.State == TaskState.Failed || lightweightTask.State == TaskState.Paused)) { 276 log.LogMessage(string.Format("Downloading task {0}", lightweightTask.Id)); 277 hiveTask.IsDownloading = true; 278 jobDownloader.DownloadTaskData(hiveTask.Task, (localJob, itemJob) => { 279 lock (downloadFinishedLocker) { 280 log.LogMessage(string.Format("Finished downloading task {0}", localJob.Id)); 281 HiveTask localHiveTask = GetHiveTaskById(localJob.Id); 282 283 if (itemJob == null) { 284 // something bad happened to this task. bad task, BAAAD task! 285 localHiveTask.IsDownloading = false; 293 286 } else { 294 localHiveTask.ItemTask = itemJob; 287 // if the task is paused, download but don't integrate into parent optimizer (to avoid Prepare) 288 if (localJob.State == TaskState.Paused) { 289 localHiveTask.ItemTask = itemJob; 290 } else { 291 if (localJob.ParentTaskId.HasValue) { 292 HiveTask parentHiveTask = GetHiveTaskById(localJob.ParentTaskId.Value); 293 parentHiveTask.IntegrateChild(itemJob, localJob.Id); 294 } else { 295 localHiveTask.ItemTask = itemJob; 296 } 297 } 298 localHiveTask.IsDownloading = false; 299 localHiveTask.Task.LastTaskDataUpdate = lightweightTask.LastTaskDataUpdate; 295 300 } 296 301 } 297 localHiveTask.IsDownloading = false; 298 localHiveTask.Task.LastTaskDataUpdate = localJob.LastTaskDataUpdate; 299 } 300 }); 302 }); 303 } 301 304 } 302 305 } 303 }304 GC.Collect(); // force GC, because .NET is too lazy here (deserialization takes a lot of memory)305 if (AllJobsFinished()) {306 this.ExecutionState = Core.ExecutionState.Stopped;307 StopResultPolling();308 }309 UpdateTotalExecutionTime();310 UpdateStatistics();311 OnStateLogListChanged();312 OnTaskReceived();306 GC.Collect(); // force GC, because .NET is too lazy here (deserialization takes a lot of memory) 307 if (AllJobsFinished()) { 308 this.ExecutionState = Core.ExecutionState.Stopped; 309 StopResultPolling(); 310 } 311 UpdateTotalExecutionTime(); 312 UpdateStatistics(); 313 OnStateLogListChanged(); 314 OnTaskReceived(); 315 } 313 316 } 314 317 … … 334 337 || j.Task.State == TaskState.Aborted 335 338 || j.Task.State == TaskState.Failed) 336 && j.IsFinishedTaskDownloaded);339 && !j.IsDownloading); 337 340 } 338 341 … … 356 359 } 357 360 358 private void Der gisterJobEvents() {361 private void DeregisterJobEvents() { 359 362 job.ToStringChanged -= new EventHandler(OnToStringChanged); 360 363 job.PropertyChanged -= new PropertyChangedEventHandler(job_PropertyChanged); … … 471 474 472 475 #region HiveTasks Events 473 private void RegisterHive JobsEvents() {476 private void RegisterHiveTasksEvents() { 474 477 this.hiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<HiveTask>(hivetasks_ItemsAdded); 475 478 this.hiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveTask>(hiveTasks_ItemsRemoved); … … 477 480 } 478 481 479 private void DeregisterHive JobsEvents() {482 private void DeregisterHiveTasksEvents() { 480 483 this.hiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveTask>(hivetasks_ItemsAdded); 481 484 this.hiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveTask>(hiveTasks_ItemsRemoved); … … 559 562 560 563 public Guid Id { 561 get { return job.Id; } 564 get { 565 if (job == null) return Guid.Empty; 566 return job.Id; 567 } 562 568 set { job.Id = value; } 563 569 } … … 603 609 return this.ToString().CompareTo(other.ToString()); 604 610 } 611 612 public void Unload() { 613 // stop result polling 614 if (refreshAutomatically) 615 RefreshAutomatically = false; 616 DisposeTasks(); 617 hiveTasks = new ItemCollection<HiveTask>(); 618 } 619 620 #region IDisposable Members 621 public void Dispose() { 622 if (jobDownloader != null) { 623 jobDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(jobDownloader_ExceptionOccured); 624 jobDownloader.Dispose(); 625 jobDownloader = null; 626 } 627 if (jobResultPoller != null) { 628 DeregisterResultPollingEvents(); 629 jobResultPoller = null; 630 } 631 if (hiveTasks != null) { 632 DisposeTasks(); 633 } 634 if (job != null) { 635 DeregisterJobEvents(); 636 job = null; 637 } 638 } 639 640 private void DisposeTasks() { 641 DeregisterHiveTasksEvents(); 642 foreach (var task in hiveTasks) { 643 task.Dispose(); 644 } 645 hiveTasks.Clear(); // this should remove the item_StateLogChanged event handlers 646 hiveTasks = null; 647 } 648 #endregion 605 649 } 606 650 }
Note: See TracChangeset
for help on using the changeset viewer.