Changeset 6419 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
- Timestamp:
- 06/16/11 00:06:54 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs
r6381 r6419 31 31 /// </summary> 32 32 public class Executor : MarshalByRefObject, IDisposable { 33 public Guid JobId { get; set; }34 private IJob Job { get; set; }35 public int CoresNeeded { get; set; }36 public int MemoryNeeded { get; set; }37 33 private bool wasJobAborted = false; 38 34 private Semaphore pauseStopSem = new Semaphore(0, 1); 39 35 private Semaphore startJobSem = new Semaphore(0, 1); 40 //make pause or stop wait until start is finished 41 private Semaphore jobStartedSem = new Semaphore(0, 1); 36 private Semaphore jobStartedSem = new Semaphore(0, 1); // make pause or stop wait until start is finished 42 37 private ExecutorQueue executorQueue; 43 public ExecutorQueue ExecutorCommandQueue { 44 get { 45 return executorQueue; 46 } 47 } 38 private bool jobDataInvalid = false; // if true, the jobdata is not sent when the job is failed 39 private IJob job; 40 private DateTime creationTime; 41 42 public Guid JobId { get; set; } 43 public int CoresNeeded { get; set; } 44 public int MemoryNeeded { get; set; } 48 45 public bool IsStopping { get; set; } 49 46 public bool IsPausing { get; set; } 50 private DateTime CreationTime { get; set; } 47 51 48 private Exception currentException; 52 49 public String CurrentException { … … 60 57 } 61 58 59 public ExecutorQueue ExecutorCommandQueue { 60 get { return executorQueue; } 61 } 62 62 63 private ExecutionState ExecutionState { 63 get { 64 return Job != null ? Job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; 65 } 64 get { return job != null ? job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; } 66 65 } 67 66 68 67 public TimeSpan ExecutionTime { 69 get { 70 return Job != null ? Job.ExecutionTime : new TimeSpan(0, 0, 0); 71 } 68 get { return job != null ? job.ExecutionTime : new TimeSpan(0, 0, 0); } 72 69 } 73 70 … … 80 77 public void Start(byte[] serializedJob) { 81 78 try { 82 CreationTime = DateTime.Now;83 Job = PersistenceUtil.Deserialize<IJob>(serializedJob);79 creationTime = DateTime.Now; 80 job = PersistenceUtil.Deserialize<IJob>(serializedJob); 84 81 85 82 RegisterJobEvents(); 86 83 87 Job.Start(); 88 if (!jobStartedSem.WaitOne(TimeSpan.FromSeconds(15))) { 84 job.Start(); 85 if (!jobStartedSem.WaitOne(TimeSpan.FromSeconds(25))) { 86 jobDataInvalid = true; 89 87 throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired."); 90 88 } … … 101 99 // wait until job is started. if this does not happen, the Job is null an we give up 102 100 jobStartedSem.WaitOne(TimeSpan.FromSeconds(15)); 103 if ( Job == null) {101 if (job == null) { 104 102 currentException = new Exception("Pausing job " + this.JobId + ": Job is null"); 105 103 return; 106 104 } 107 105 108 if ( Job.ExecutionState == ExecutionState.Started) {106 if (job.ExecutionState == ExecutionState.Started) { 109 107 try { 110 Job.Pause();108 job.Pause(); 111 109 //we need to block the pause... 112 110 pauseStopSem.WaitOne(); … … 122 120 // wait until job is started. if this does not happen, the Job is null an we give up 123 121 jobStartedSem.WaitOne(TimeSpan.FromSeconds(15)); 124 if ( Job == null) {122 if (job == null) { 125 123 currentException = new Exception("Stopping job " + this.JobId + ": Job is null"); 126 124 } … … 129 127 if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) { 130 128 try { 131 Job.Stop();129 job.Stop(); 132 130 pauseStopSem.WaitOne(); 133 131 } … … 139 137 140 138 private void RegisterJobEvents() { 141 Job.JobStopped += new EventHandler(Job_JobStopped);142 Job.JobFailed += new EventHandler(Job_JobFailed);143 Job.JobPaused += new EventHandler(Job_JobPaused);144 Job.JobStarted += new EventHandler(Job_JobStarted);139 job.JobStopped += new EventHandler(Job_JobStopped); 140 job.JobFailed += new EventHandler(Job_JobFailed); 141 job.JobPaused += new EventHandler(Job_JobPaused); 142 job.JobStarted += new EventHandler(Job_JobStarted); 145 143 } 146 144 147 145 private void DeregisterJobEvents() { 148 Job.JobStopped -= new EventHandler(Job_JobStopped);149 Job.JobFailed -= new EventHandler(Job_JobFailed);150 Job.JobPaused -= new EventHandler(Job_JobPaused);151 Job.JobStarted -= new EventHandler(Job_JobStarted);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); 152 150 } 153 151 … … 182 180 183 181 public JobData GetJobData() { 184 if (Job.ExecutionState == ExecutionState.Started) { 182 if (jobDataInvalid) return null; 183 184 if (job.ExecutionState == ExecutionState.Started) { 185 185 throw new InvalidStateException("Job is still running"); 186 186 } else { 187 187 JobData jobData = new JobData(); 188 if ( Job == null) {188 if (job == null) { 189 189 //send empty job and save exception 190 190 jobData.Data = PersistenceUtil.Serialize(new JobData()); … … 193 193 } 194 194 } else { 195 jobData.Data = PersistenceUtil.Serialize( Job);195 jobData.Data = PersistenceUtil.Serialize(job); 196 196 } 197 197 jobData.JobId = JobId; … … 201 201 202 202 public void Dispose() { 203 if ( Job != null)203 if (job != null) 204 204 DeregisterJobEvents(); 205 Job = null;205 job = null; 206 206 } 207 207 }
Note: See TracChangeset
for help on using the changeset viewer.