Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/08/11 16:38:28 (13 years ago)
Author:
ascheibe
Message:

#1233 more renaming for more consistency

File:
1 edited

Legend:

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

    r6721 r6725  
    2929namespace HeuristicLab.Clients.Hive.SlaveCore {
    3030  /// <summary>
    31   /// The executor runs in the appdomain and handles the execution of an Hive job.
     31  /// The executor runs in the appdomain and handles the execution of an Hive task.
    3232  /// </summary>
    3333  public class Executor : MarshalByRefObject, IDisposable {
    34     private bool wasJobAborted = false;
     34    private bool wasTaskAborted = false;
    3535    private AutoResetEvent pauseStopSem = new AutoResetEvent(false);
    36     private AutoResetEvent startJobSem = new AutoResetEvent(false); // block start method call
    37     private AutoResetEvent jobStartedSem = new AutoResetEvent(false); // make pause or stop wait until start is finished
     36    private AutoResetEvent startTaskSem = new AutoResetEvent(false); // block start method call
     37    private AutoResetEvent taskStartedSem = new AutoResetEvent(false); // make pause or stop wait until start is finished
    3838    private ExecutorQueue executorQueue;
    39     private bool jobDataInvalid = false; // if true, the jobdata is not sent when the job is failed
    40     private IJob job;
     39    private bool taskDataInvalid = false; // if true, the jobdata is not sent when the task is failed
     40    private ITask task;
    4141    private DateTime creationTime;
    4242
    43     public Guid JobId { get; set; }
     43    public Guid TaskId { get; set; }
    4444    public int CoresNeeded { get; set; }
    4545    public int MemoryNeeded { get; set; }
     
    6363
    6464    private ExecutionState ExecutionState {
    65       get { return job != null ? job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; }
     65      get { return task != null ? task.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; }
    6666    }
    6767
    6868    public TimeSpan ExecutionTime {
    69       get { return job != null ? job.ExecutionTime : new TimeSpan(0, 0, 0); }
     69      get { return task != null ? task.ExecutionTime : new TimeSpan(0, 0, 0); }
    7070    }
    7171
     
    7979      try {
    8080        creationTime = DateTime.Now;
    81         job = PersistenceUtil.Deserialize<IJob>(serializedJob);
     81        task = PersistenceUtil.Deserialize<ITask>(serializedJob);
    8282
    8383        RegisterJobEvents();
    8484
    85         job.Start();
    86         if (!startJobSem.WaitOne(Settings.Default.ExecutorSemTimeouts)) {
    87           jobDataInvalid = true;
    88           throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired.");
     85        task.Start();
     86        if (!startTaskSem.WaitOne(Settings.Default.ExecutorSemTimeouts)) {
     87          taskDataInvalid = true;
     88          throw new TimeoutException("Timeout when starting the task. TaskStarted event was not fired.");
    8989        }
    9090      }
    9191      catch (Exception e) {
    9292        this.CurrentException = e;
    93         Job_JobFailed(this, new EventArgs<Exception>(e));
     93        Task_TaskFailed(this, new EventArgs<Exception>(e));
    9494      }
    9595      finally {
    96         jobStartedSem.Set();
     96        taskStartedSem.Set();
    9797      }
    9898    }
     
    100100    public void Pause() {
    101101      IsPausing = true;
    102       // wait until job is started. if this does not happen, the Task is null an we give up
    103       jobStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
    104       if (job == null) {
    105         CurrentException = new Exception("Pausing job " + this.JobId + ": Task is null");
     102      // wait until task is started. if this does not happen, the Task is null an we give up
     103      taskStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
     104      if (task == null) {
     105        CurrentException = new Exception("Pausing task " + this.TaskId + ": Task is null");
    106106        executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    107107        return;
    108108      }
    109109
    110       if (job.ExecutionState == ExecutionState.Started) {
     110      if (task.ExecutionState == ExecutionState.Started) {
    111111        try {
    112           job.Pause();
     112          task.Pause();
    113113          //we need to block the pause...
    114114          pauseStopSem.WaitOne();
    115115        }
    116116        catch (Exception ex) {
    117           CurrentException = new Exception("Error pausing job " + this.JobId + ": " + ex.ToString());
     117          CurrentException = new Exception("Error pausing task " + this.TaskId + ": " + ex.ToString());
    118118          executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    119119        }
     
    123123    public void Stop() {
    124124      IsStopping = true;
    125       // wait until job is started. if this does not happen, the Task is null an we give up
    126       jobStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
    127       if (job == null) {
    128         CurrentException = new Exception("Stopping job " + this.JobId + ": Task is null");
     125      // wait until task is started. if this does not happen, the Task is null an we give up
     126      taskStartedSem.WaitOne(Settings.Default.ExecutorSemTimeouts);
     127      if (task == null) {
     128        CurrentException = new Exception("Stopping task " + this.TaskId + ": Task is null");
    129129        executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    130130      }
    131       wasJobAborted = true;
     131      wasTaskAborted = true;
    132132
    133133      if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) {
    134134        try {
    135           job.Stop();
     135          task.Stop();
    136136          pauseStopSem.WaitOne();
    137137        }
    138138        catch (Exception ex) {
    139           CurrentException = new Exception("Error stopping job " + this.JobId + ": " + ex.ToString());
     139          CurrentException = new Exception("Error stopping task " + this.TaskId + ": " + ex.ToString());
    140140          executorQueue.AddMessage(ExecutorMessageType.ExceptionOccured);
    141141        }
     
    144144
    145145    private void RegisterJobEvents() {
    146       job.JobStopped += new EventHandler(Job_JobStopped);
    147       job.JobFailed += new EventHandler(Job_JobFailed);
    148       job.JobPaused += new EventHandler(Job_JobPaused);
    149       job.JobStarted += new EventHandler(Job_JobStarted);
     146      task.TaskStopped += new EventHandler(Task_TaskStopped);
     147      task.TaskFailed += new EventHandler(Task_TaskFailed);
     148      task.TaskPaused += new EventHandler(Task_TaskPaused);
     149      task.TaskStarted += new EventHandler(Task_TaskStarted);
    150150    }
    151151
    152152    private void DeregisterJobEvents() {
    153       job.JobStopped -= new EventHandler(Job_JobStopped);
    154       job.JobFailed -= new EventHandler(Job_JobFailed);
    155       job.JobPaused -= new EventHandler(Job_JobPaused);
    156       job.JobStarted -= new EventHandler(Job_JobStarted);
     153      task.TaskStopped -= new EventHandler(Task_TaskStopped);
     154      task.TaskFailed -= new EventHandler(Task_TaskFailed);
     155      task.TaskPaused -= new EventHandler(Task_TaskPaused);
     156      task.TaskStarted -= new EventHandler(Task_TaskStarted);
    157157    }
    158158
    159159    #region Task Events
    160     private void Job_JobFailed(object sender, EventArgs e) {
     160    private void Task_TaskFailed(object sender, EventArgs e) {
    161161      IsStopping = true;
    162162      EventArgs<Exception> ex = (EventArgs<Exception>)e;
    163163      CurrentException = ex.Value;
    164       executorQueue.AddMessage(ExecutorMessageType.JobFailed);
    165     }
    166 
    167     private void Job_JobStopped(object sender, EventArgs e) {
     164      executorQueue.AddMessage(ExecutorMessageType.TaskFailed);
     165    }
     166
     167    private void Task_TaskStopped(object sender, EventArgs e) {
    168168      IsStopping = true;
    169       if (wasJobAborted) {
     169      if (wasTaskAborted) {
    170170        pauseStopSem.Set();
    171171      }
    172       executorQueue.AddMessage(ExecutorMessageType.JobStopped);
    173     }
    174 
    175     private void Job_JobPaused(object sender, EventArgs e) {
     172      executorQueue.AddMessage(ExecutorMessageType.TaskStopped);
     173    }
     174
     175    private void Task_TaskPaused(object sender, EventArgs e) {
    176176      IsPausing = true;
    177177      pauseStopSem.Set();
    178       executorQueue.AddMessage(ExecutorMessageType.JobPaused);
    179     }
    180 
    181     private void Job_JobStarted(object sender, EventArgs e) {
    182       startJobSem.Set();
    183       executorQueue.AddMessage(ExecutorMessageType.JobStarted);
     178      executorQueue.AddMessage(ExecutorMessageType.TaskPaused);
     179    }
     180
     181    private void Task_TaskStarted(object sender, EventArgs e) {
     182      startTaskSem.Set();
     183      executorQueue.AddMessage(ExecutorMessageType.TaskStarted);
    184184    }
    185185    #endregion
    186186
    187     public TaskData GetJobData() {
    188       if (jobDataInvalid) return null;
    189 
    190       if (job.ExecutionState == ExecutionState.Started) {
     187    public TaskData GetTaskData() {
     188      if (taskDataInvalid) return null;
     189
     190      if (task.ExecutionState == ExecutionState.Started) {
    191191        throw new InvalidStateException("Task is still running");
    192192      } else {
    193         TaskData jobData = new TaskData();
    194         if (job == null) {
    195           //send empty job and save exception
    196           jobData.Data = PersistenceUtil.Serialize(new TaskData());
     193        TaskData taskData = new TaskData();
     194        if (task == null) {
     195          //send empty task and save exception
     196          taskData.Data = PersistenceUtil.Serialize(new TaskData());
    197197          if (CurrentException == null) {
    198             CurrentException = new Exception("Task with id " + this.JobId + " is null, sending empty job");
     198            CurrentException = new Exception("Task with id " + this.TaskId + " is null, sending empty task");
    199199          }
    200200        } else {
    201           jobData.Data = PersistenceUtil.Serialize(job);
    202         }
    203         jobData.TaskId = JobId;
    204         return jobData;
     201          taskData.Data = PersistenceUtil.Serialize(task);
     202        }
     203        taskData.TaskId = TaskId;
     204        return taskData;
    205205      }
    206206    }
    207207
    208208    public void Dispose() {
    209       if (job != null)
     209      if (task != null)
    210210        DeregisterJobEvents();
    211       job = null;
     211      task = null;
    212212    }
    213213  }
Note: See TracChangeset for help on using the changeset viewer.