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 moved

Legend:

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

    r6721 r6725  
    3131
    3232  /// <summary>
    33   ///  Manages a single job and it's appdomain.
     33  ///  Manages a single task and it's appdomain.
    3434  /// </summary>
    35   public class SlaveJob : MarshalByRefObject {
     35  public class SlaveTask : MarshalByRefObject {
    3636    private Executor executor;
    3737    private AppDomain appDomain;
     
    4141    private PluginManager pluginManager;
    4242    private ILog log;
    43     public Guid JobId { get; private set; }
     43    public Guid TaskId { get; private set; }
    4444    public bool IsPrepared { get; private set; }
    4545
     
    5454    }
    5555
    56     public SlaveJob(PluginManager pluginManager, int coresNeeded, ILog log) {
     56    public SlaveTask(PluginManager pluginManager, int coresNeeded, ILog log) {
    5757      this.pluginManager = pluginManager;
    5858      this.coresNeeded = coresNeeded;
     
    6363    }
    6464
    65     public void StartJobAsync(Task job, TaskData jobData) {
     65    public void StartJobAsync(Task task, TaskData taskData) {
    6666      try {
    67         this.JobId = job.Id;
    68         Prepare(job);
    69         StartJobInAppDomain(jobData);
     67        this.TaskId = task.Id;
     68        Prepare(task);
     69        StartTaskInAppDomain(taskData);
    7070      }
    7171      catch (Exception) {
     
    7676    }
    7777
    78     public void PauseJob() {
     78    public void PauseTask() {
    7979      if (!IsPrepared) throw new AppDomainNotCreatedException();
    8080      if (!executor.IsPausing && !executor.IsStopping) executor.Pause();
    8181    }
    8282
    83     public void StopJob() {
     83    public void StopTask() {
    8484      if (!IsPrepared) throw new AppDomainNotCreatedException();
    8585      if (!executor.IsPausing && !executor.IsStopping) executor.Stop();
    8686    }
    8787
    88     private void Prepare(Task job) {
    89       string pluginDir = Path.Combine(pluginManager.PluginTempBaseDir, job.Id.ToString());
     88    private void Prepare(Task task) {
     89      string pluginDir = Path.Combine(pluginManager.PluginTempBaseDir, task.Id.ToString());
    9090      string configFileName;
    91       pluginManager.PreparePlugins(job, out configFileName);
    92       appDomain = CreateAppDomain(job, pluginDir, configFileName);
     91      pluginManager.PreparePlugins(task, out configFileName);
     92      appDomain = CreateAppDomain(task, pluginDir, configFileName);
    9393      IsPrepared = true;
    9494    }
    9595
    96     private AppDomain CreateAppDomain(Task job, String pluginDir, string configFileName) {
    97       if (job.IsPrivileged) {
    98         appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
     96    private AppDomain CreateAppDomain(Task task, String pluginDir, string configFileName) {
     97      if (task.IsPrivileged) {
     98        appDomain = SandboxManager.CreateAndInitPrivilegedSandbox(task.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
    9999      } else {
    100         appDomain = SandboxManager.CreateAndInitSandbox(job.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
     100        appDomain = SandboxManager.CreateAndInitSandbox(task.Id.ToString(), pluginDir, Path.Combine(pluginDir, configFileName));
    101101      }
    102102      appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException);
     
    105105      executor = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    106106
    107       executor.JobId = job.Id;
    108       executor.CoresNeeded = job.CoresNeeded;
    109       executor.MemoryNeeded = job.MemoryNeeded;
     107      executor.TaskId = task.Id;
     108      executor.CoresNeeded = task.CoresNeeded;
     109      executor.MemoryNeeded = task.MemoryNeeded;
    110110      return appDomain;
    111111    }
    112112
    113     private void StartJobInAppDomain(TaskData jobData) {
    114       executor.Start(jobData.Data);
     113    private void StartTaskInAppDomain(TaskData taskData) {
     114      executor.Start(taskData.Data);
    115115      waitForStartBeforeKillSem.Release();
    116116      StartExecutorMonitoringThread();
     
    118118
    119119    public void DisposeAppDomain() {
    120       log.LogMessage(string.Format("Shutting down Appdomain for Task {0}", JobId));
     120      log.LogMessage(string.Format("Shutting down Appdomain for Task {0}", TaskId));
    121121      StopExecutorMonitoringThread();
    122122
     
    145145        }
    146146      }
    147       pluginManager.DeletePluginsForJob(JobId);
     147      pluginManager.DeletePluginsForJob(TaskId);
    148148      GC.Collect();
    149149    }
     
    154154    }
    155155
    156     public TaskData GetJobData() {
    157       return executor.GetJobData();
     156    public TaskData GetTaskData() {
     157      return executor.GetTaskData();
    158158    }
    159159
     
    176176    /// Because the executor is in an appdomain and is not able to call back
    177177    /// (because of security -> lease time for marshall-by-ref object is 5 min),
    178     /// we have to poll the executor for events we have to react to (e.g. job finished...)   
     178    /// we have to poll the executor for events we have to react to (e.g. task finished...)   
    179179    /// </summary>
    180180    private void MonitorExecutor() {
     
    184184
    185185        switch (message.MessageType) {
    186           case ExecutorMessageType.JobStarted:
    187             OnJobStarted();
    188             break;
    189 
    190           case ExecutorMessageType.JobPaused:
    191             executorMonitoringRun = false;
    192             OnJobPaused();
    193             DisposeAppDomain();
    194             break;
    195 
    196           case ExecutorMessageType.JobStopped:
    197             executorMonitoringRun = false;
    198             OnJobStopped();
    199             DisposeAppDomain();
    200             break;
    201 
    202           case ExecutorMessageType.JobFailed:
    203             executorMonitoringRun = false;
    204             OnJobFailed(new JobFailedException(executor.CurrentExceptionStr));
     186          case ExecutorMessageType.TaskStarted:
     187            OnTaskStarted();
     188            break;
     189
     190          case ExecutorMessageType.TaskPaused:
     191            executorMonitoringRun = false;
     192            OnTaskPaused();
     193            DisposeAppDomain();
     194            break;
     195
     196          case ExecutorMessageType.TaskStopped:
     197            executorMonitoringRun = false;
     198            OnTaskStopped();
     199            DisposeAppDomain();
     200            break;
     201
     202          case ExecutorMessageType.TaskFailed:
     203            executorMonitoringRun = false;
     204            OnTaskFailed(new TaskFailedException(executor.CurrentExceptionStr));
    205205            DisposeAppDomain();
    206206            break;
     
    216216              OnExceptionOccured(executor.CurrentException);
    217217            } else {
    218               OnExceptionOccured(new Exception(string.Format("Unknow exception occured in Executor for job {0}", JobId)));
     218              OnExceptionOccured(new Exception(string.Format("Unknow exception occured in Executor for task {0}", TaskId)));
    219219            }
    220220            break;
     
    224224    #endregion
    225225
    226     public event EventHandler<EventArgs<Guid>> JobStarted;
    227     private void OnJobStarted() {
    228       var handler = JobStarted;
    229       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    230     }
    231 
    232     public event EventHandler<EventArgs<Guid>> JobStopped;
    233     private void OnJobStopped() {
    234       var handler = JobStopped;
    235       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    236     }
    237 
    238     public event EventHandler<EventArgs<Guid>> JobPaused;
    239     private void OnJobPaused() {
    240       var handler = JobPaused;
    241       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    242     }
    243 
    244     public event EventHandler<EventArgs<Guid>> JobAborted;
    245     private void OnJobAborted() {
    246       var handler = JobAborted;
    247       if (handler != null) handler(this, new EventArgs<Guid>(this.JobId));
    248     }
    249 
    250     public event EventHandler<EventArgs<Guid, Exception>> JobFailed;
    251     private void OnJobFailed(Exception exception) {
    252       var handler = JobFailed;
    253       if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception));
     226    public event EventHandler<EventArgs<Guid>> TaskStarted;
     227    private void OnTaskStarted() {
     228      var handler = TaskStarted;
     229      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     230    }
     231
     232    public event EventHandler<EventArgs<Guid>> TaskStopped;
     233    private void OnTaskStopped() {
     234      var handler = TaskStopped;
     235      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     236    }
     237
     238    public event EventHandler<EventArgs<Guid>> TaskPaused;
     239    private void OnTaskPaused() {
     240      var handler = TaskPaused;
     241      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     242    }
     243
     244    public event EventHandler<EventArgs<Guid>> TaskAborted;
     245    private void OnTaskAborted() {
     246      var handler = TaskAborted;
     247      if (handler != null) handler(this, new EventArgs<Guid>(this.TaskId));
     248    }
     249
     250    public event EventHandler<EventArgs<Guid, Exception>> TaskFailed;
     251    private void OnTaskFailed(Exception exception) {
     252      var handler = TaskFailed;
     253      if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.TaskId, exception));
    254254    }
    255255
     
    257257    private void OnExceptionOccured(Exception exception) {
    258258      var handler = ExceptionOccured;
    259       if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.JobId, exception));
     259      if (handler != null) handler(this, new EventArgs<Guid, Exception>(this.TaskId, exception));
    260260    }
    261261  }
Note: See TracChangeset for help on using the changeset viewer.