Changeset 9169
- Timestamp:
- 01/16/13 11:13:18 (12 years ago)
- Location:
- branches/UnloadJobs
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UnloadJobs/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveJobManagerView.cs
r7259 r9169 54 54 Content.Refreshing += new EventHandler(Content_Refreshing); 55 55 Content.Refreshed += new EventHandler(Content_Refreshed); 56 Content.Hive ExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);56 Content.HiveJobsChanged += new EventHandler(Content_HiveJobsChanged); 57 57 58 58 } … … 61 61 Content.Refreshing -= new EventHandler(Content_Refreshing); 62 62 Content.Refreshed -= new EventHandler(Content_Refreshed); 63 Content.Hive ExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);63 Content.HiveJobsChanged -= new EventHandler(Content_HiveJobsChanged); 64 64 base.DeregisterContentEvents(); 65 65 } … … 123 123 124 124 protected override void OnClosing(FormClosingEventArgs e) { 125 base.OnClosing(e); 126 if (Content != null && Content.Jobs != null) { 127 foreach (var exp in Content.Jobs.OfType<RefreshableJob>()) { 128 if (exp.RefreshAutomatically) { 129 exp.RefreshAutomatically = false; // stop result polling 130 } 125 if (Content.Jobs.Any(x => x.IsProgressing)) { 126 MessageBox.Show("The Hive Job Manager can only be closed after all down/uploads are finished. ", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 127 e.Cancel = true; 128 } else { 129 base.OnClosing(e); 130 if (Content != null && Content.Jobs != null) { 131 Content.Jobs.ItemsRemoved -= new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved); 132 Content.ClearHiveClient(); 131 133 } 132 134 } … … 139 141 } 140 142 141 private void Content_HiveExperimentsChanged(object sender, EventArgs e) { 142 Content.Jobs.ItemsRemoved += new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved); 143 private void Content_HiveJobsChanged(object sender, EventArgs e) { 144 if (Content.Jobs != null) { 145 Content.Jobs.ItemsRemoved += new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved); 146 } 143 147 } 144 148 } -
branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/ConcurrentTaskDownloader.cs
r7259 r9169 30 30 /// Downloads and deserializes jobs. It avoids too many jobs beeing downloaded or deserialized at the same time to avoid memory problems 31 31 /// </summary> 32 public class ConcurrentTaskDownloader<T> where T : class, ITask {32 public class ConcurrentTaskDownloader<T> : IDisposable where T : class, ITask { 33 33 private bool abort = false; 34 34 // use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory … … 82 82 if (abort) return null; 83 83 result = HiveServiceLocator.Instance.CallHiveService(s => s.GetTaskData(task.Id)); 84 } finally { 84 } 85 finally { 85 86 downloadSemaphore.Release(); 86 87 } … … 95 96 taskData.Item2.Data = null; // reduce memory consumption. 96 97 return new Tuple<Task, T>(taskData.Item1, deserializedJob); 97 } finally { 98 } 99 finally { 98 100 deserializeSemaphore.Release(); 99 101 } … … 110 112 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 111 113 } 114 115 #region IDisposable Members 116 public void Dispose() { 117 TaskScheduler.UnobservedTaskException -= new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException); 118 deserializeSemaphore.Dispose(); 119 downloadSemaphore.Dispose(); 120 } 121 #endregion 112 122 } 113 123 } -
branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r9107 r9169 52 52 if (value != jobs) { 53 53 jobs = value; 54 OnHive ExperimentsChanged();54 OnHiveJobsChanged(); 55 55 } 56 56 } … … 77 77 78 78 private HiveClient() { } 79 80 public void ClearHiveClient() { 81 foreach (var j in Jobs) { 82 if (j.RefreshAutomatically) { 83 j.RefreshAutomatically = false; // stop result polling 84 j.Dispose(); 85 } 86 } 87 Jobs = null; 88 if (onlinePlugins != null) 89 onlinePlugins.Clear(); 90 if (alreadyUploadedPlugins != null) 91 alreadyUploadedPlugins.Clear(); 92 } 79 93 80 94 #region Refresh … … 205 219 if (handler != null) handler(this, EventArgs.Empty); 206 220 } 207 public event EventHandler Hive ExperimentsChanged;208 private void OnHive ExperimentsChanged() {209 var handler = Hive ExperimentsChanged;221 public event EventHandler HiveJobsChanged; 222 private void OnHiveJobsChanged() { 223 var handler = HiveJobsChanged; 210 224 if (handler != null) handler(this, EventArgs.Empty); 211 225 } … … 308 322 } 309 323 finally { 310 refreshableJob.RefreshAutomatically = true; 311 refreshableJob.StartResultPolling(); 324 //refreshableJob.RefreshAutomatically = true; 312 325 refreshableJob.Job.Modified = false; 313 326 refreshableJob.IsProgressing = false; … … 421 434 refreshableJob.IsProgressing = true; 422 435 refreshableJob.Progress = new Progress(); 436 TaskDownloader downloader = null; 423 437 424 438 try { … … 433 447 434 448 refreshableJob.Progress.Status = "Downloading tasks..."; 435 TaskDownloaderdownloader = new TaskDownloader(allTasks.Select(x => x.Id));449 downloader = new TaskDownloader(allTasks.Select(x => x.Id)); 436 450 downloader.StartAsync(); 437 451 … … 465 479 refreshableJob.IsProgressing = false; 466 480 refreshableJob.Progress.Finish(); 481 if (downloader != null) { 482 downloader.Dispose(); 483 } 467 484 } 468 485 } -
branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs
r9107 r9169 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; … … 48 48 throw new ArgumentNullException(); 49 49 50 if (job != null) Der gisterJobEvents();50 if (job != null) DeregisterJobEvents(); 51 51 job = value; 52 52 if (job != null) { … … 66 66 set { 67 67 if (hiveTasks != value) { 68 if (hiveTasks != null) DeregisterHive JobsEvents();68 if (hiveTasks != null) DeregisterHiveTasksEvents(); 69 69 hiveTasks = value; 70 if (hiveTasks != null) RegisterHive JobsEvents();70 if (hiveTasks != null) RegisterHiveTasksEvents(); 71 71 OnHiveTasksChanged(); 72 72 } … … 240 240 if (jobResultPoller != null && jobResultPoller.IsPolling) { 241 241 jobResultPoller.Stop(); 242 DeregisterResultPollingEvents(); 242 243 } 243 244 } … … 358 359 } 359 360 360 private void Der gisterJobEvents() {361 private void DeregisterJobEvents() { 361 362 job.ToStringChanged -= new EventHandler(OnToStringChanged); 362 363 job.PropertyChanged -= new PropertyChangedEventHandler(job_PropertyChanged); … … 473 474 474 475 #region HiveTasks Events 475 private void RegisterHive JobsEvents() {476 private void RegisterHiveTasksEvents() { 476 477 this.hiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<HiveTask>(hivetasks_ItemsAdded); 477 478 this.hiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveTask>(hiveTasks_ItemsRemoved); … … 479 480 } 480 481 481 private void DeregisterHive JobsEvents() {482 private void DeregisterHiveTasksEvents() { 482 483 this.hiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveTask>(hivetasks_ItemsAdded); 483 484 this.hiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveTask>(hiveTasks_ItemsRemoved); … … 605 606 return this.ToString().CompareTo(other.ToString()); 606 607 } 608 609 #region IDisposable Members 610 public void Dispose() { 611 if (jobDownloader != null) { 612 jobDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(jobDownloader_ExceptionOccured); 613 jobDownloader.Dispose(); 614 jobDownloader = null; 615 } 616 if (job != null) { 617 DeregisterJobEvents(); 618 job = null; 619 } 620 if (hiveTasks != null) { 621 DeregisterHiveTasksEvents(); 622 hiveTasks.Clear(); // this should remove the item_StateLogChanged event handlers 623 hiveTasks = null; 624 } 625 if (jobResultPoller != null) { 626 DeregisterResultPollingEvents(); 627 jobResultPoller = null; 628 } 629 } 630 #endregion 607 631 } 608 632 } -
branches/UnloadJobs/HeuristicLab.Clients.Hive/3.3/TaskDownloader.cs
r7259 r9169 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Clients.Hive.Jobs; 26 27 using HeuristicLab.Common; 27 using System.Threading;28 28 29 29 namespace HeuristicLab.Clients.Hive { 30 public class TaskDownloader {30 public class TaskDownloader : IDisposable { 31 31 private IEnumerable<Guid> taskIds; 32 32 private ConcurrentTaskDownloader<ItemTask> taskDownloader; … … 38 38 public bool IsFinished { 39 39 get { 40 try { 41 resultsLock.EnterReadLock(); 42 return results.Count == taskIds.Count(); 43 } finally { resultsLock.ExitReadLock(); } 40 try { 41 resultsLock.EnterReadLock(); 42 return results.Count == taskIds.Count(); 43 } 44 finally { resultsLock.ExitReadLock(); } 44 45 } 45 46 } … … 59 60 public int FinishedCount { 60 61 get { 61 try { 62 resultsLock.EnterReadLock(); 63 return results.Count; 64 } finally { resultsLock.ExitReadLock(); } 62 try { 63 resultsLock.EnterReadLock(); 64 return results.Count; 65 } 66 finally { resultsLock.ExitReadLock(); } 65 67 } 66 68 } … … 68 70 public IDictionary<Guid, HiveTask> Results { 69 71 get { 70 try { 71 resultsLock.EnterReadLock(); 72 return results; 73 } finally { resultsLock.ExitReadLock(); } 72 try { 73 resultsLock.EnterReadLock(); 74 return results; 75 } 76 finally { resultsLock.ExitReadLock(); } 74 77 } 75 78 } … … 97 100 resultsLock.EnterWriteLock(); 98 101 this.results.Add(localJob.Id, hiveTask); 99 } finally { resultsLock.ExitWriteLock(); } 102 } 103 finally { resultsLock.ExitWriteLock(); } 100 104 } 101 105 }); … … 114 118 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 115 119 } 120 121 #region IDisposable Members 122 public void Dispose() { 123 taskDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured); 124 resultsLock.Dispose(); 125 } 126 #endregion 116 127 } 117 128 }
Note: See TracChangeset
for help on using the changeset viewer.