Changeset 6725 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/SlaveTask.cs
- Timestamp:
- 09/08/11 16:38:28 (13 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/SlaveTask.cs
r6721 r6725 31 31 32 32 /// <summary> 33 /// Manages a single joband it's appdomain.33 /// Manages a single task and it's appdomain. 34 34 /// </summary> 35 public class Slave Job: MarshalByRefObject {35 public class SlaveTask : MarshalByRefObject { 36 36 private Executor executor; 37 37 private AppDomain appDomain; … … 41 41 private PluginManager pluginManager; 42 42 private ILog log; 43 public Guid JobId { get; private set; }43 public Guid TaskId { get; private set; } 44 44 public bool IsPrepared { get; private set; } 45 45 … … 54 54 } 55 55 56 public Slave Job(PluginManager pluginManager, int coresNeeded, ILog log) {56 public SlaveTask(PluginManager pluginManager, int coresNeeded, ILog log) { 57 57 this.pluginManager = pluginManager; 58 58 this.coresNeeded = coresNeeded; … … 63 63 } 64 64 65 public void StartJobAsync(Task job, TaskData jobData) {65 public void StartJobAsync(Task task, TaskData taskData) { 66 66 try { 67 this. JobId = job.Id;68 Prepare( job);69 Start JobInAppDomain(jobData);67 this.TaskId = task.Id; 68 Prepare(task); 69 StartTaskInAppDomain(taskData); 70 70 } 71 71 catch (Exception) { … … 76 76 } 77 77 78 public void Pause Job() {78 public void PauseTask() { 79 79 if (!IsPrepared) throw new AppDomainNotCreatedException(); 80 80 if (!executor.IsPausing && !executor.IsStopping) executor.Pause(); 81 81 } 82 82 83 public void Stop Job() {83 public void StopTask() { 84 84 if (!IsPrepared) throw new AppDomainNotCreatedException(); 85 85 if (!executor.IsPausing && !executor.IsStopping) executor.Stop(); 86 86 } 87 87 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()); 90 90 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); 93 93 IsPrepared = true; 94 94 } 95 95 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)); 99 99 } 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)); 101 101 } 102 102 appDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomain_UnhandledException); … … 105 105 executor = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName); 106 106 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; 110 110 return appDomain; 111 111 } 112 112 113 private void Start JobInAppDomain(TaskData jobData) {114 executor.Start( jobData.Data);113 private void StartTaskInAppDomain(TaskData taskData) { 114 executor.Start(taskData.Data); 115 115 waitForStartBeforeKillSem.Release(); 116 116 StartExecutorMonitoringThread(); … … 118 118 119 119 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)); 121 121 StopExecutorMonitoringThread(); 122 122 … … 145 145 } 146 146 } 147 pluginManager.DeletePluginsForJob( JobId);147 pluginManager.DeletePluginsForJob(TaskId); 148 148 GC.Collect(); 149 149 } … … 154 154 } 155 155 156 public TaskData Get JobData() {157 return executor.Get JobData();156 public TaskData GetTaskData() { 157 return executor.GetTaskData(); 158 158 } 159 159 … … 176 176 /// Because the executor is in an appdomain and is not able to call back 177 177 /// (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. jobfinished...)178 /// we have to poll the executor for events we have to react to (e.g. task finished...) 179 179 /// </summary> 180 180 private void MonitorExecutor() { … … 184 184 185 185 switch (message.MessageType) { 186 case ExecutorMessageType. JobStarted:187 On JobStarted();188 break; 189 190 case ExecutorMessageType. JobPaused:191 executorMonitoringRun = false; 192 On JobPaused();193 DisposeAppDomain(); 194 break; 195 196 case ExecutorMessageType. JobStopped:197 executorMonitoringRun = false; 198 On JobStopped();199 DisposeAppDomain(); 200 break; 201 202 case ExecutorMessageType. JobFailed:203 executorMonitoringRun = false; 204 On JobFailed(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)); 205 205 DisposeAppDomain(); 206 206 break; … … 216 216 OnExceptionOccured(executor.CurrentException); 217 217 } 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))); 219 219 } 220 220 break; … … 224 224 #endregion 225 225 226 public event EventHandler<EventArgs<Guid>> JobStarted;227 private void On JobStarted() {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 On JobStopped() {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 On JobPaused() {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 On JobAborted() {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 On JobFailed(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)); 254 254 } 255 255 … … 257 257 private void OnExceptionOccured(Exception exception) { 258 258 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)); 260 260 } 261 261 }
Note: See TracChangeset
for help on using the changeset viewer.