Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/11 17:58:59 (13 years ago)
Author:
cneumuel
Message:

#1233

  • added semaphores to ensure an appdomain is never unloaded when the start method has not finished
  • HiveEngine uploading and downloading of jobs works and is displayed in the view
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobDownloader.cs

    r6168 r6178  
    3030  public class HiveJobDownloader {
    3131    private IEnumerable<Guid> jobIds;
    32     private JobDownloader<ItemJob> jobDownloader;
     32    private ConcurrentJobDownloader<ItemJob> jobDownloader;
    3333    private IDictionary<Guid, HiveJob> results;
    3434
    3535    public bool IsFinished {
    3636      get {
    37         //return tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion ||
    38         //                             t.Status == TaskStatus.Faulted ||
    39         //                             t.Status == TaskStatus.Canceled);
    4037        return results.Count == jobIds.Count();
    4138      }
     
    4441    public int FinishedCount {
    4542      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);
    5443        return results.Count;
    5544      }
     
    5847    public IDictionary<Guid, HiveJob> Results {
    5948      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         //}
    6849        return results;
    6950      }
     
    7253    public HiveJobDownloader(IEnumerable<Guid> jobIds) {
    7354      this.jobIds = jobIds;
    74       this.jobDownloader = new JobDownloader<ItemJob>(2, 2);
     55      this.jobDownloader = new ConcurrentJobDownloader<ItemJob>(2, 2);
    7556      this.results = new Dictionary<Guid, HiveJob>();
    7657    }
     
    8162          (id, itemJob, exception) => {
    8263            if (exception != null) {
    83               throw new JobDownloaderException("Downloading job failed", exception);
     64              throw new ConcurrentJobDownloaderException("Downloading job failed", exception);
    8465            }
    8566            Job job = ServiceLocator.Instance.CallHiveService(s => s.GetJob(id));
     
    9576            }
    9677          });
    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      }     
    10679    }
    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 property
    110     //}
    111 
    112     //// use semaphore to ensure only few concurrenct connections and few SerializedJob objects in memory
    113     //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     //}
    14980  }
    15081}
Note: See TracChangeset for help on using the changeset viewer.