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
Location:
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4
Files:
4 added
2 deleted
7 edited

Legend:

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

    r6111 r6178  
    274274      List<IPluginDescription> plugins;
    275275
    276       if (hiveJob.JobItem.ComputeInParallel &&
    277         (hiveJob.JobItem.Item is Optimization.Experiment || hiveJob.JobItem.Item is Optimization.BatchRun)) {
     276      if (hiveJob.ItemJob.ComputeInParallel &&
     277        (hiveJob.ItemJob.Item is Optimization.Experiment || hiveJob.ItemJob.Item is Optimization.BatchRun)) {
    278278        hiveJob.Job.IsParentJob = true;
    279279        hiveJob.Job.FinishWhenChildJobsFinished = true;
    280         hiveJob.JobItem.CollectChildJobs = false; // don't collect child-jobs on slaves
     280        hiveJob.ItemJob.CollectChildJobs = false; // don't collect child-jobs on slaves
    281281        jobData = hiveJob.GetAsJobData(true, out plugins);
    282282      } else {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/HiveJob.cs

    r6168 r6178  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Drawing;
    2526using System.Linq;
     
    5556    }
    5657
     58    [Storable]
    5759    protected Job job;
    5860    public Job Job {
     
    6062      set {
    6163        if (job != value) {
     64          DeregisterJobEvents();
    6265          job = value;
     66          RegisterJobEvents();
     67          itemJobDownloaded = false;
    6368          OnJobChanged();
    6469          OnToStringChanged();
    6570          OnItemImageChanged();
    6671        }
     72       
    6773      }
    6874    }
    6975
    7076    [Storable]
    71     protected ItemJob jobItem;
    72     public ItemJob JobItem {
    73       get { return jobItem; }
     77    protected ItemJob itemJob;
     78    public ItemJob ItemJob {
     79      get { return itemJob; }
    7480      internal set {
    75         if (jobItem != null && syncJobsWithOptimizers) {
     81        if (itemJob != null && syncJobsWithOptimizers) {
    7682          this.childHiveJobs.Clear();
    7783        }
    78         if (jobItem != value) {
    79           DergisterJobItemsEvents();
    80           jobItem = value;
    81           RegisterJobItemEvents();
     84        if (itemJob != value) {
     85          DergisterItemJobEvents();
     86          itemJob = value;
     87          RegisterItemJobEvents();
    8288          OnJobItemChanged();
    83         }
    84       }
     89          itemJobDownloaded = true;
     90        }
     91      }
     92    }
     93
     94    // job downloaded since last status change
     95    [Storable]
     96    private bool itemJobDownloaded = false;
     97    public bool ItemJobDownloaded {
     98      get { return itemJobDownloaded; }
    8599    }
    86100
     
    106120    }
    107121
    108     public HiveJob(ItemJob jobItem, bool autoCreateChildHiveJobs)
     122    public HiveJob(ItemJob itemJob, bool autoCreateChildHiveJobs)
    109123      : this() {
    110124      this.syncJobsWithOptimizers = autoCreateChildHiveJobs;
    111       this.JobItem = jobItem;
     125      this.ItemJob = itemJob;
    112126      this.syncJobsWithOptimizers = true;
    113127    }
     
    117131      this.Job = job;
    118132      try {
    119         this.JobItem = PersistenceUtil.Deserialize<ItemJob>(jobData.Data);
     133        this.ItemJob = PersistenceUtil.Deserialize<ItemJob>(jobData.Data);
    120134      }
    121135      catch {
    122         this.JobItem = null;
     136        this.ItemJob = null;
    123137      }
    124138      this.childHiveJobs = new ItemList<HiveJob>();
     
    130144      : base(original, cloner) {
    131145      this.Job = cloner.Clone(original.job);
    132       this.JobItem = cloner.Clone(original.JobItem);
     146      this.ItemJob = cloner.Clone(original.ItemJob);
    133147      this.childHiveJobs = cloner.Clone(original.childHiveJobs);
    134148      this.syncJobsWithOptimizers = original.syncJobsWithOptimizers;
     149      this.itemJobDownloaded = original.itemJobDownloaded;
    135150    }
    136151    public override IDeepCloneable Clone(Cloner cloner) {
     
    141156    protected virtual void UpdateChildHiveJobs() { }
    142157
    143     protected virtual void RegisterJobItemEvents() {
    144       if (JobItem != null) {
    145         JobItem.ComputeInParallelChanged += new EventHandler(JobItem_ComputeInParallelChanged);
    146         JobItem.ToStringChanged += new EventHandler(JobItem_ToStringChanged);
    147       }
    148     }
    149     protected virtual void DergisterJobItemsEvents() {
    150       if (JobItem != null) {
    151         JobItem.ComputeInParallelChanged -= new EventHandler(JobItem_ComputeInParallelChanged);
    152         JobItem.ToStringChanged -= new EventHandler(JobItem_ToStringChanged);
     158    protected virtual void RegisterItemJobEvents() {
     159      if (ItemJob != null) {
     160        ItemJob.ComputeInParallelChanged += new EventHandler(JobItem_ComputeInParallelChanged);
     161        ItemJob.ToStringChanged += new EventHandler(JobItem_ToStringChanged);
     162      }
     163    }
     164    protected virtual void DergisterItemJobEvents() {
     165      if (ItemJob != null) {
     166        ItemJob.ComputeInParallelChanged -= new EventHandler(JobItem_ComputeInParallelChanged);
     167        ItemJob.ToStringChanged -= new EventHandler(JobItem_ToStringChanged);
    153168      }
    154169    }
     
    168183      this.OnToStringChanged();
    169184    }
    170    
     185
    171186    protected virtual void JobItem_ComputeInParallelChanged(object sender, EventArgs e) {
    172       if (JobItem != null && syncJobsWithOptimizers) {
     187      if (ItemJob != null && syncJobsWithOptimizers) {
    173188        this.UpdateChildHiveJobs();
    174189      }
     
    180195
    181196    public override string ToString() {
    182       if (jobItem != null) {
    183         return jobItem.ToString();
     197      if (itemJob != null) {
     198        return itemJob.ToString();
    184199      } else {
    185200        return base.ToString();
     
    196211        job.Command = lightweightJob.Command;
    197212        job.LastJobDataUpdate = lightweightJob.LastJobDataUpdate;
    198        
     213
    199214        OnJobStateChanged();
    200215        OnToStringChanged();
     
    210225    /// </param>
    211226    public virtual JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) {
    212       plugins = null;
    213       return null;
     227      plugins = new List<IPluginDescription>();
     228      if (this.itemJob == null)
     229        return null;
     230
     231      IEnumerable<Type> usedTypes;
     232      byte[] jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes);
     233
     234      JobData jobData = new JobData() {
     235        JobId = job.Id,
     236        Data = jobByteArray
     237      };
     238
     239      PluginUtil.CollectDeclaringPlugins(plugins, usedTypes);
     240
     241      return jobData;
    214242    }
    215243
     
    239267      if (handler != null) handler(this, EventArgs.Empty);
    240268    }
     269
     270    private void RegisterJobEvents() {
     271      if (job != null)
     272        job.PropertyChanged += new PropertyChangedEventHandler(job_PropertyChanged);
     273    }
     274
     275    private void DeregisterJobEvents() {
     276      if (job != null)
     277        job.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(job_PropertyChanged);
     278    }
     279
     280    private void job_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     281      if (e.PropertyName == "State") {
     282        itemJobDownloaded = false;
     283      }
     284    }
    241285    #endregion
    242    
     286
    243287    /// <summary>
    244288    /// Returns a list of HiveJobs including this and all its child-jobs recursively
     
    326370      } else {
    327371        ServiceLocator.Instance.CallHiveService(s => s.PauseJob(this.job.Id));
    328       }     
     372      }
    329373    }
    330374
     
    343387        JobData jobData = new JobData();
    344388        jobData.JobId = this.job.Id;
    345         jobData.Data = PersistenceUtil.Serialize(this.jobItem);
     389        jobData.Data = PersistenceUtil.Serialize(this.itemJob);
    346390        service.UpdateJobData(this.Job, jobData);
    347391        service.RestartJob(this.job.Id);
     
    350394      });
    351395    }
    352    
     396
    353397    public ICollection<IItemTreeNodeAction<HiveJob>> Actions {
    354398      get {
     
    364408  public class HiveJob<T> : HiveJob where T : ItemJob {
    365409
    366     public new T JobItem {
    367       get { return (T)base.JobItem; }
    368       internal set { base.JobItem = value; }
     410    public new T ItemJob {
     411      get { return (T)base.ItemJob; }
     412      internal set { base.ItemJob = value; }
    369413    }
    370414
    371415    #region Constructors and Cloning
    372416    public HiveJob() : base() { }
     417    public HiveJob(T itemJob) : base(itemJob, true) { }
    373418    protected HiveJob(HiveJob original, Cloner cloner)
    374419      : base(original, cloner) {
  • 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}
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/OptimizerHiveJob.cs

    r6111 r6178  
    3737    public OptimizerHiveJob(IOptimizer optimizer)
    3838      : this() {
    39       this.JobItem = new OptimizerJob(optimizer);
     39      this.ItemJob = new OptimizerJob(optimizer);
    4040    }
    4141    public OptimizerHiveJob(OptimizerJob optimizerJob)
    4242      : this() {
    43       this.JobItem = optimizerJob;
     43      this.ItemJob = optimizerJob;
    4444    }
    4545    protected OptimizerHiveJob(OptimizerHiveJob original, Cloner cloner)
     
    6060      base.UpdateChildHiveJobs();
    6161      if (Job != null && syncJobsWithOptimizers) {
    62         if (!JobItem.ComputeInParallel) {
     62        if (!ItemJob.ComputeInParallel) {
    6363          this.childHiveJobs.Clear();
    6464        } else {
    65           if (JobItem.Item is Optimization.Experiment) {
    66             Optimization.Experiment experiment = (Optimization.Experiment)JobItem.Item;
     65          if (ItemJob.Item is Optimization.Experiment) {
     66            Optimization.Experiment experiment = (Optimization.Experiment)ItemJob.Item;
    6767            foreach (IOptimizer childOpt in experiment.Optimizers) {
    6868              this.childHiveJobs.Add(new OptimizerHiveJob(childOpt));
    6969            }
    70           } else if (JobItem.Item is Optimization.BatchRun) {
    71             Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;
     70          } else if (ItemJob.Item is Optimization.BatchRun) {
     71            Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun;
    7272            if (batchRun.Optimizer != null) {
    7373              while (this.childHiveJobs.Count < batchRun.Repetitions) {
     
    8383    }
    8484
    85     protected override void RegisterJobItemEvents() {
    86       base.RegisterJobItemEvents();
    87       if (JobItem != null) {
    88         if (JobItem.Item is Optimization.Experiment) {
    89           Optimization.Experiment experiment = JobItem.OptimizerAsExperiment;
     85    protected override void RegisterItemJobEvents() {
     86      base.RegisterItemJobEvents();
     87      if (ItemJob != null) {
     88        if (ItemJob.Item is Optimization.Experiment) {
     89          Optimization.Experiment experiment = ItemJob.OptimizerAsExperiment;
    9090          experiment.Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
    9191          experiment.Optimizers.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
    9292          experiment.Optimizers.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved);
    9393          experiment.Optimizers.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
    94         } else if (JobItem.Item is Optimization.BatchRun) {
    95           Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;
     94        } else if (ItemJob.Item is Optimization.BatchRun) {
     95          Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun;
    9696          batchRun.RepetitionsChanged += new EventHandler(batchRun_RepetitionsChanged);
    9797          batchRun.OptimizerChanged += new EventHandler(batchRun_OptimizerChanged);
     
    9999      }
    100100    }
    101     protected override void DergisterJobItemsEvents() {
    102       base.DergisterJobItemsEvents();
    103       if (JobItem != null) {
    104         if (JobItem.Item is Optimization.Experiment) {
    105           Optimization.Experiment experiment = JobItem.OptimizerAsExperiment;
     101    protected override void DergisterItemJobEvents() {
     102      base.DergisterItemJobEvents();
     103      if (ItemJob != null) {
     104        if (ItemJob.Item is Optimization.Experiment) {
     105          Optimization.Experiment experiment = ItemJob.OptimizerAsExperiment;
    106106          experiment.Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
    107107          experiment.Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
    108108          experiment.Optimizers.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsRemoved);
    109109          experiment.Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
    110         } else if (JobItem.Item is Optimization.BatchRun) {
    111           Optimization.BatchRun batchRun = JobItem.OptimizerAsBatchRun;
     110        } else if (ItemJob.Item is Optimization.BatchRun) {
     111          Optimization.BatchRun batchRun = ItemJob.OptimizerAsBatchRun;
    112112          batchRun.RepetitionsChanged -= new EventHandler(batchRun_RepetitionsChanged);
    113113          batchRun.OptimizerChanged -= new EventHandler(batchRun_OptimizerChanged);
     
    129129
    130130    private void Optimizers_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    131       if (syncJobsWithOptimizers && this.JobItem.ComputeInParallel) {
     131      if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) {
    132132        foreach (var item in e.Items) {
    133133          if (GetChildByOptimizer(item.Value) == null && item.Value.Name != "Placeholder") {
     
    138138    }
    139139    private void Optimizers_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    140       if (syncJobsWithOptimizers && this.JobItem.ComputeInParallel) {
     140      if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) {
    141141        foreach (var item in e.OldItems) {
    142142          this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value));
     
    150150    }
    151151    private void Optimizers_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    152       if (syncJobsWithOptimizers && this.JobItem.ComputeInParallel) {
     152      if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) {
    153153        foreach (var item in e.Items) {
    154154          this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value));
     
    157157    }
    158158    private void Optimizers_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOptimizer>> e) {
    159       if (syncJobsWithOptimizers && this.JobItem.ComputeInParallel) {
     159      if (syncJobsWithOptimizers && this.ItemJob.ComputeInParallel) {
    160160        foreach (var item in e.Items) {
    161161          this.childHiveJobs.Remove(this.GetChildByOptimizer(item.Value));
     
    174174      syncJobsWithOptimizers = false; // don't sync with optimizers during this method
    175175
    176       if (this.JobItem != null && this.JobItem.Item != null) {
    177         if (this.JobItem.Item is Optimization.Experiment) {
    178           UpdateOptimizerInExperiment(this.JobItem.OptimizerAsExperiment, optimizerJob);
    179         } else if (this.JobItem.Item is Optimization.BatchRun) {
    180           UpdateOptimizerInBatchRun(this.JobItem.OptimizerAsBatchRun, optimizerJob);
     176      if (this.ItemJob != null && this.ItemJob.Item != null) {
     177        if (this.ItemJob.Item is Optimization.Experiment) {
     178          UpdateOptimizerInExperiment(this.ItemJob.OptimizerAsExperiment, optimizerJob);
     179        } else if (this.ItemJob.Item is Optimization.BatchRun) {
     180          UpdateOptimizerInBatchRun(this.ItemJob.OptimizerAsBatchRun, optimizerJob);
    181181        }
    182182      }
     
    185185      if (!optimizerJob.ComputeInParallel) {
    186186        child.syncJobsWithOptimizers = false;
    187         child.JobItem = optimizerJob;
     187        child.ItemJob = optimizerJob;
    188188        child.syncJobsWithOptimizers = true;
    189189      }
     
    236236    internal void SetIndexInParentOptimizerList(OptimizerHiveJob parentHiveJob) {
    237237      if (parentHiveJob != null) {
    238         if (parentHiveJob.JobItem.Item is Optimization.Experiment) {
    239           this.JobItem.IndexInParentOptimizerList = parentHiveJob.JobItem.OptimizerAsExperiment.Optimizers.IndexOf(this.JobItem.Item);
    240         } else if (parentHiveJob.JobItem.Item is Optimization.BatchRun) {
    241           this.JobItem.IndexInParentOptimizerList = 0;
     238        if (parentHiveJob.ItemJob.Item is Optimization.Experiment) {
     239          this.ItemJob.IndexInParentOptimizerList = parentHiveJob.ItemJob.OptimizerAsExperiment.Optimizers.IndexOf(this.ItemJob.Item);
     240        } else if (parentHiveJob.ItemJob.Item is Optimization.BatchRun) {
     241          this.ItemJob.IndexInParentOptimizerList = 0;
    242242        } else {
    243243          throw new NotSupportedException("Only Experiment and BatchRuns are supported");
     
    253253      var optimizerHiveJob = (OptimizerHiveJob)hiveJob;
    254254      syncJobsWithOptimizers = false;
    255       if (this.JobItem != null && optimizerHiveJob.JobItem != null) {
     255      if (this.ItemJob != null && optimizerHiveJob.ItemJob != null) {
    256256        // if job is in state Paused, it has to preserve its ResultCollection, which is cleared when a optimizer is added to an experiment
    257257        OptimizerJob optimizerJobClone = null;
    258258        if (optimizerHiveJob.Job.State == JobState.Paused) {
    259           optimizerJobClone = (OptimizerJob)optimizerHiveJob.JobItem.Clone();
    260         }
    261 
    262         if (this.JobItem.Item is Optimization.Experiment) {
    263           if (!this.JobItem.OptimizerAsExperiment.Optimizers.Contains(optimizerHiveJob.JobItem.Item)) {
    264             UpdateOptimizerInExperiment(this.JobItem.OptimizerAsExperiment, optimizerHiveJob.JobItem);
     259          optimizerJobClone = (OptimizerJob)optimizerHiveJob.ItemJob.Clone();
     260        }
     261
     262        if (this.ItemJob.Item is Optimization.Experiment) {
     263          if (!this.ItemJob.OptimizerAsExperiment.Optimizers.Contains(optimizerHiveJob.ItemJob.Item)) {
     264            UpdateOptimizerInExperiment(this.ItemJob.OptimizerAsExperiment, optimizerHiveJob.ItemJob);
    265265          }
    266         } else if (this.JobItem.Item is Optimization.BatchRun) {
    267           UpdateOptimizerInBatchRun(this.JobItem.OptimizerAsBatchRun, optimizerHiveJob.JobItem);
     266        } else if (this.ItemJob.Item is Optimization.BatchRun) {
     267          UpdateOptimizerInBatchRun(this.ItemJob.OptimizerAsBatchRun, optimizerHiveJob.ItemJob);
    268268        }
    269269
    270270        if (optimizerHiveJob.Job.State == JobState.Paused) {
    271           optimizerHiveJob.JobItem = optimizerJobClone;
     271          optimizerHiveJob.ItemJob = optimizerJobClone;
    272272        }
    273273      }
     
    283283    public override JobData GetAsJobData(bool withoutChildOptimizers, out List<IPluginDescription> plugins) {
    284284      plugins = new List<IPluginDescription>();
    285       if (this.jobItem == null) // || this.jobItem.Optimizer == null
     285      if (this.itemJob == null) // || this.jobItem.Optimizer == null
    286286        return null;
    287287
    288288      IEnumerable<Type> usedTypes;
    289289      byte[] jobByteArray;
    290       if (withoutChildOptimizers && this.JobItem.Item is Optimization.Experiment) {
    291         OptimizerJob clonedJob = (OptimizerJob)this.JobItem.Clone(); // use a cloned job, so that the childHiveJob don't get confused
     290      if (withoutChildOptimizers && this.ItemJob.Item is Optimization.Experiment) {
     291        OptimizerJob clonedJob = (OptimizerJob)this.ItemJob.Clone(); // use a cloned job, so that the childHiveJob don't get confused
    292292        clonedJob.OptimizerAsExperiment.Optimizers.Clear();
    293293        jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes);
    294       } else if (withoutChildOptimizers && this.JobItem.Item is Optimization.BatchRun) {
    295         OptimizerJob clonedJob = (OptimizerJob)this.JobItem.Clone();
     294      } else if (withoutChildOptimizers && this.ItemJob.Item is Optimization.BatchRun) {
     295        OptimizerJob clonedJob = (OptimizerJob)this.ItemJob.Clone();
    296296        clonedJob.OptimizerAsBatchRun.Optimizer = null;
    297297        jobByteArray = PersistenceUtil.Serialize(clonedJob, out usedTypes);
    298       } else if (this.JobItem.Item is IAlgorithm) {
    299         ((IAlgorithm)this.JobItem.Item).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size
    300         jobByteArray = PersistenceUtil.Serialize(this.JobItem, out usedTypes);
     298      } else if (this.ItemJob.Item is IAlgorithm) {
     299        ((IAlgorithm)this.ItemJob.Item).StoreAlgorithmInEachRun = false; // avoid storing the algorithm in runs to reduce size
     300        jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes);
    301301      } else {
    302         jobByteArray = PersistenceUtil.Serialize(this.JobItem, out usedTypes);
     302        jobByteArray = PersistenceUtil.Serialize(this.ItemJob, out usedTypes);
    303303      }
    304304
     
    315315    public OptimizerHiveJob GetChildByOptimizerJob(OptimizerJob optimizerJob) {
    316316      foreach (OptimizerHiveJob child in ChildHiveJobs) {
    317         if (child.JobItem == optimizerJob)
     317        if (child.ItemJob == optimizerJob)
    318318          return child;
    319319      }
     
    323323    public HiveJob<OptimizerJob> GetChildByOptimizer(IOptimizer optimizer) {
    324324      foreach (OptimizerHiveJob child in ChildHiveJobs) {
    325         if (child.JobItem.Item == optimizer)
     325        if (child.ItemJob.Item == optimizer)
    326326          return child;
    327327      }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ExperimentManager/RefreshableHiveExperiment.cs

    r6168 r6178  
    3434  public class RefreshableHiveExperiment : IHiveItem, IDeepCloneable, IContent, IProgressReporter {
    3535    private JobResultPoller jobResultPoller;
    36     private JobDownloader<ItemJob> jobDownloader = new JobDownloader<ItemJob>(2, 2);
     36    private ConcurrentJobDownloader<ItemJob> jobDownloader = new ConcurrentJobDownloader<ItemJob>(2, 2);
    3737    private static object locker = new object();
    3838
     
    8383    }
    8484
     85    [Storable]
     86    private bool isControllable = true;
     87    public bool IsControllable {
     88      get { return isControllable; }
     89      set {
     90        if (value != isControllable) {
     91          isControllable = value;
     92          OnIsControllableChanged();
     93        }
     94      }
     95    }
     96
    8597    #region Constructors and Cloning
    8698    public RefreshableHiveExperiment() {
     
    99111      this.RefreshAutomatically = original.RefreshAutomatically;
    100112      this.IncludeJobs = original.IncludeJobs;
     113      this.IsControllable = original.IsControllable;
    101114    }
    102115    public IDeepCloneable Clone(Cloner cloner) {
     
    163176            jobDownloader.DownloadJob(hj.Job.Id, (id, itemJob, exception) => {
    164177              if (exception != null) {
    165                 throw new JobDownloaderException("Downloading job failed.", exception);
     178                throw new ConcurrentJobDownloaderException("Downloading job failed.", exception);
    166179              }
    167180
     
    171184                // if the job is paused, download but don't integrate into parent optimizer (to avoid Prepare)
    172185                if (hj.Job.State == JobState.Paused) {
    173                   hj.JobItem = itemJob;
     186                  hj.ItemJob = itemJob;
    174187                } else {
    175188                  if (lightweightJob.ParentJobId.HasValue) {
     
    177190                    parentHiveJob.IntegrateChild(itemJob, hj.Job.Id);
    178191                  } else {
    179                     hj.JobItem = itemJob;
     192                    hj.ItemJob = itemJob;
    180193                  }
    181194                }
     
    211224
    212225    public bool AllJobsFinished() {
    213       return hiveExperiment.GetAllHiveJobs().All(j => j.Job.State == JobState.Finished
    214                                             || j.Job.State == JobState.Aborted
    215                                             || j.Job.State == JobState.Failed);
     226      return hiveExperiment.GetAllHiveJobs().All(j => (j.Job.State == JobState.Finished
     227                                                   || j.Job.State == JobState.Aborted
     228                                                   || j.Job.State == JobState.Failed)
     229                                                   && j.ItemJobDownloaded);
    216230    }
    217231
     
    299313      if (handler != null) handler(sender, e);
    300314    }
     315
     316    public event EventHandler IsControllableChanged;
     317    private void OnIsControllableChanged() {
     318      var handler = IsControllableChanged;
     319      if (handler != null) handler(this, EventArgs.Empty);
     320    }
    301321    #endregion
    302322
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/HeuristicLab.Clients.Hive-3.4.csproj

    r6168 r6178  
    120120    <Compile Include="Exceptions\JobResultPollingException.cs" />
    121121    <Compile Include="Exceptions\OptimizerNotFoundException.cs" />
    122     <Compile Include="ExperimentManager\JobDownloader.cs" />
     122    <Compile Include="ExperimentManager\ConcurrentJobDownloader.cs" />
     123    <Compile Include="ExperimentManager\EngineHiveJob.cs" />
    123124    <Compile Include="ExperimentManager\ExperimentManagerClient.cs" />
    124125    <Compile Include="ExperimentManager\HiveJobDownloader.cs" />
    125     <Compile Include="ExperimentManager\JobDownloaderException.cs" />
     126    <Compile Include="ExperimentManager\ConcurrentJobDownloaderException.cs" />
    126127    <Compile Include="ExperimentManager\TreeView\IItemTree.cs" />
    127128    <Compile Include="ExperimentManager\TreeView\IItemTreeAction.cs" />
     
    145146    <None Include="Properties\AssemblyInfo.cs.frame" />
    146147    <Compile Include="Exceptions\ServiceClientFactoryException.cs" />
     148    <Compile Include="ScopeExtensions.cs" />
    147149    <Compile Include="ServiceClients\Appointment.cs" />
    148150    <Compile Include="ServiceClients\HiveItemCollection.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/EngineJob.cs

    r6111 r6178  
    7272
    7373    protected override void RegisterItemEvents() {
     74      base.RegisterItemEvents();
    7475      Item.Stopped += new EventHandler(engine_Stopped);
     76      Item.Paused += new EventHandler(Item_Paused);
     77      Item.Started += new EventHandler(Item_Started);
    7578      Item.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
     79      Item.ExecutionStateChanged += new EventHandler(Item_ExecutionStateChanged);
     80      Item.ExecutionTimeChanged += new EventHandler(Item_ExecutionTimeChanged);
    7681    }
    7782
    7883    protected override void DeregisterItemEvents() {
    7984      Item.Stopped -= new EventHandler(engine_Stopped);
     85      Item.Paused -= new EventHandler(Item_Paused);
     86      Item.Started -= new EventHandler(Item_Started);
    8087      Item.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(engine_ExceptionOccurred);
     88      Item.ExecutionStateChanged -= new EventHandler(Item_ExecutionStateChanged);
     89      Item.ExecutionTimeChanged -= new EventHandler(Item_ExecutionTimeChanged);
     90      base.DeregisterItemEvents();
    8191    }
    8292
     
    8797    private void engine_Stopped(object sender, EventArgs e) {
    8898      OnJobStopped();
     99    }
     100
     101    private void Item_Paused(object sender, EventArgs e) {
     102      OnJobPaused();
     103    }
     104
     105    private void Item_ExecutionTimeChanged(object sender, EventArgs e) {
     106      OnExecutionTimeChanged();
     107    }
     108
     109    private void Item_ExecutionStateChanged(object sender, EventArgs e) {
     110      OnExecutionStateChanged();
     111    }
     112
     113    private void Item_Started(object sender, EventArgs e) {
     114      OnJobStarted();
    89115    }
    90116
Note: See TracChangeset for help on using the changeset viewer.