Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJobDownloader.cs @ 6178

Last change on this file since 6178 was 6178, checked in by cneumuel, 13 years ago

#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 size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Clients.Hive.ExperimentManager;
26using HeuristicLab.Clients.Hive.Jobs;
27using HeuristicLab.Hive;
28
29namespace HeuristicLab.Clients.Hive {
30  public class HiveJobDownloader {
31    private IEnumerable<Guid> jobIds;
32    private ConcurrentJobDownloader<ItemJob> jobDownloader;
33    private IDictionary<Guid, HiveJob> results;
34
35    public bool IsFinished {
36      get {
37        return results.Count == jobIds.Count();
38      }
39    }
40
41    public int FinishedCount {
42      get {
43        return results.Count;
44      }
45    }
46
47    public IDictionary<Guid, HiveJob> Results {
48      get {
49        return results;
50      }
51    }
52
53    public HiveJobDownloader(IEnumerable<Guid> jobIds) {
54      this.jobIds = jobIds;
55      this.jobDownloader = new ConcurrentJobDownloader<ItemJob>(2, 2);
56      this.results = new Dictionary<Guid, HiveJob>();
57    }
58
59    public void StartAsync() {
60      foreach (Guid jobId in jobIds) {
61        jobDownloader.DownloadJob(jobId,
62          (id, itemJob, exception) => {
63            if (exception != null) {
64              throw new ConcurrentJobDownloaderException("Downloading job failed", exception);
65            }
66            Job job = ServiceLocator.Instance.CallHiveService(s => s.GetJob(id));
67            if (job != null && itemJob != null) {
68              HiveJob hiveJob;
69              if (itemJob is OptimizerJob) {
70                hiveJob = new OptimizerHiveJob((OptimizerJob)itemJob);
71              } else {
72                hiveJob = new HiveJob(itemJob, true);
73              }
74              hiveJob.Job = job;
75              this.results.Add(id, hiveJob);
76            }
77          });
78      }     
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.