Changeset 6178 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobDownloader.cs
- Timestamp:
- 05/10/11 17:58:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobDownloader.cs
r6168 r6178 30 30 public class HiveJobDownloader { 31 31 private IEnumerable<Guid> jobIds; 32 private JobDownloader<ItemJob> jobDownloader;32 private ConcurrentJobDownloader<ItemJob> jobDownloader; 33 33 private IDictionary<Guid, HiveJob> results; 34 34 35 35 public bool IsFinished { 36 36 get { 37 //return tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion ||38 // t.Status == TaskStatus.Faulted ||39 // t.Status == TaskStatus.Canceled);40 37 return results.Count == jobIds.Count(); 41 38 } … … 44 41 public int FinishedCount { 45 42 get { 46 //var faulted = tasks.Where(t => t.Status == TaskStatus.Faulted);47 //if (faulted.Count() > 0) {48 // abort = true;49 // throw faulted.First().Exception;50 //}51 //return tasks.Count(t => t.Status == TaskStatus.RanToCompletion ||52 // t.Status == TaskStatus.Faulted ||53 // t.Status == TaskStatus.Canceled);54 43 return results.Count; 55 44 } … … 58 47 public IDictionary<Guid, HiveJob> Results { 59 48 get { 60 //var results = new Dictionary<Guid, HiveJob>();61 //foreach (var t in tasks) {62 // if (t.Status == TaskStatus.Faulted) {63 // throw t.Exception;64 // }65 // if (t.Result != null)66 // results.Add(t.Result.Job.Id, t.Result);67 //}68 49 return results; 69 50 } … … 72 53 public HiveJobDownloader(IEnumerable<Guid> jobIds) { 73 54 this.jobIds = jobIds; 74 this.jobDownloader = new JobDownloader<ItemJob>(2, 2);55 this.jobDownloader = new ConcurrentJobDownloader<ItemJob>(2, 2); 75 56 this.results = new Dictionary<Guid, HiveJob>(); 76 57 } … … 81 62 (id, itemJob, exception) => { 82 63 if (exception != null) { 83 throw new JobDownloaderException("Downloading job failed", exception);64 throw new ConcurrentJobDownloaderException("Downloading job failed", exception); 84 65 } 85 66 Job job = ServiceLocator.Instance.CallHiveService(s => s.GetJob(id)); … … 95 76 } 96 77 }); 97 } 98 99 //tasks = new List<Task<HiveJob>>(); 100 //TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException); 101 //foreach (Guid jobId in jobIds) { 102 // tasks.Add(Task<JobData>.Factory.StartNew( 103 // (x) => DownloadJob(x), jobId) 104 // .ContinueWith((x) => DeserializeJob(x.Result))); 105 //} 78 } 106 79 } 107 108 //private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) {109 // e.SetObserved(); // avoid crash of process because task crashes. first exception found is handled in Results property110 //}111 112 //// use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory113 //private Semaphore downloadSemaphore = new Semaphore(2, 2);114 //private Semaphore deserializeSemaphore = new Semaphore(2, 2);115 //protected JobData DownloadJob(object jobId) {116 // downloadSemaphore.WaitOne();117 // deserializeSemaphore.WaitOne();118 // JobData result;119 // try {120 // if (abort) return null;121 // result = ServiceLocator.Instance.CallHiveService(s => s.GetJobData((Guid)jobId));122 // }123 // finally {124 // downloadSemaphore.Release();125 // }126 // return result;127 //}128 129 //protected HiveJob DeserializeJob(JobData jobData) {130 // try {131 // Job job = ServiceLocator.Instance.CallHiveService(s => s.GetJob(jobData.JobId));132 // if (abort || job == null || jobData == null) return null;133 134 // HiveJob hiveJob;135 // var itemJob = PersistenceUtil.Deserialize<ItemJob>(jobData.Data);136 // if (itemJob is OptimizerJob) {137 // hiveJob = new OptimizerHiveJob((OptimizerJob)itemJob);138 // } else {139 // hiveJob = new HiveJob(itemJob, true);140 // }141 // jobData.Data = null; // reduce memory consumption.142 // hiveJob.Job = job;143 // return hiveJob;144 // }145 // finally {146 // deserializeSemaphore.Release();147 // }148 //}149 80 } 150 81 }
Note: See TracChangeset
for help on using the changeset viewer.