Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5782 for branches


Ignore:
Timestamp:
03/21/11 21:50:39 (13 years ago)
Author:
ascheibe
Message:

#1233

  • fixed job pause bug... again
  • general Executor improvements
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs

    r5778 r5782  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    3536    private bool wasJobAborted = false;
    3637    public Core Core { get; set; }
     38    private Semaphore pauseStopSem = new Semaphore(0, 1);
    3739
    3840    private Exception currentException;
     
    8486
    8587    public void Pause() {
    86       Job.Pause();
    87 
     88      if (Job == null) {
     89        throw new InvalidStateException("Job is null");
     90      }
     91
     92      if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
     93        try {
     94          Job.Pause();
     95          //we need to block the pause...
     96          pauseStopSem.WaitOne();
     97        }
     98        catch (Exception ex) {
     99          SlaveClientCom.Instance.ClientCom.LogMessage("Error pausing job:" + ex.ToString());
     100        }
     101      }
    88102    }
    89103
    90104    public void Stop() {
     105      if (Job == null) {
     106        throw new InvalidStateException("Job is null");
     107      }
    91108      wasJobAborted = true;
     109
    92110      if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) {
    93         Job.Stop();
    94       } else {
    95         Job_JobStopped(this, EventArgs.Empty);
     111        try {
     112          Job.Stop();
     113          pauseStopSem.WaitOne();
     114        }
     115        catch (Exception ex) {
     116          SlaveClientCom.Instance.ClientCom.LogMessage("Error stopping job:" + ex.ToString());
     117        }
    96118      }
    97119    }
     
    103125      Job.WaitForChildJobs += new EventHandler(Job_WaitForChildJobs);
    104126      Job.DeleteChildJobs += new EventHandler(Job_DeleteChildJobs);
     127      Job.JobPaused += new EventHandler(Job_JobPaused);
    105128    }
    106129
     
    111134      Job.WaitForChildJobs -= new EventHandler(Job_WaitForChildJobs);
    112135      Job.DeleteChildJobs -= new EventHandler(Job_DeleteChildJobs);
     136      Job.JobPaused -= new EventHandler(Job_JobPaused);
    113137    }
    114138
     
    159183    private void Job_JobStopped(object sender, EventArgs e) {
    160184      if (wasJobAborted) {
    161         Core.EnqueueExecutorMessage(Core.KillAppDomain, JobId);
     185        pauseStopSem.Release();
    162186      } else {
     187        //it's a clean and finished job, so send it
    163188        Core.EnqueueExecutorMessage(Core.SendFinishedJob, JobId);
    164189      }
     
    171196
    172197      if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
    173         try { Job.Stop(); }
    174         catch { }
     198        try {
     199          Job.Stop();
     200          wasJobAborted = true;
     201          pauseStopSem.WaitOne();
     202        }
     203        catch (Exception ex) {
     204          SlaveClientCom.Instance.ClientCom.LogMessage("Error stopping job:" + ex.ToString());
     205        }
    175206      }
    176207
     
    178209    }
    179210
     211
    180212    public JobData GetPausedJob() {
    181       if (Job == null) {
    182         throw new InvalidStateException("Job is null");
    183       }
    184 
    185       if (Job.ExecutionState == HeuristicLab.Core.ExecutionState.Started) {
    186         try { Job.Pause(); }
    187         catch { }
    188       }
    189 
     213      if (Job.ExecutionState != HeuristicLab.Core.ExecutionState.Paused) {
     214        throw new Exception("Executor: Job has to be paused before fetching results.");
     215      }
    190216      return GetJob();
     217    }
     218
     219    private void Job_JobPaused(object sender, EventArgs e) {
     220      pauseStopSem.Release();
    191221    }
    192222
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/Jobs/OptimizerJob.cs

    r5450 r5782  
    154154    }
    155155
    156     public void Pause() {
     156    public virtual void Pause() {
    157157      optimizer.Pause();
    158158    }
     
    173173
    174174    public event EventHandler JobPaused;
    175     protected void OnJobPaused(object sender, EventArgs e) {
     175    protected virtual void OnJobPaused() {
    176176      EventHandler handler = JobPaused;
    177177      if (handler != null) handler(this, EventArgs.Empty);
     
    218218    protected virtual void RegisterEvents() {
    219219      optimizer.Stopped += new EventHandler(optimizer_Stopped);
    220       optimizer.Paused += new EventHandler(OnJobPaused);
     220      optimizer.Paused += new EventHandler(optimizer_Paused);
    221221      optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
    222222      optimizer.DescriptionChanged += new EventHandler(optimizer_DescriptionChanged);
     
    229229    protected virtual void DeregisterEvents() {
    230230      optimizer.Stopped -= new EventHandler(optimizer_Stopped);
    231       optimizer.Paused -= new EventHandler(OnJobPaused);
     231      optimizer.Paused -= new EventHandler(optimizer_Paused);
    232232      optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
    233233      optimizer.DescriptionChanged -= this.DescriptionChanged;
     
    265265      OnJobStopped();
    266266    }
     267
     268    protected virtual void optimizer_Paused(object sender, EventArgs e) {
     269      OnJobPaused();
     270    }
    267271    #endregion
    268272
Note: See TracChangeset for help on using the changeset viewer.