Changeset 4141 for branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
- Timestamp:
- 08/04/10 10:44:14 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
r4139 r4141 53 53 private const string itemDescription = "A runner for a single experiment, which's algorithms are executed in the Hive."; 54 54 private const int resultPollingIntervalMs = 15000; 55 private const int snapshotPollingIntervalMs = 1000; 55 56 private const int maxSnapshotRetries = 20; 56 57 private object locker = new object(); … … 169 170 clone.executionTime = this.executionTime; 170 171 clone.pendingOptimizersByJobId = new Dictionary<Guid, IOptimizer>(); 172 171 173 foreach (var pair in this.pendingOptimizersByJobId) 172 174 clone.pendingOptimizersByJobId[pair.Key] = (IOptimizer)cloner.Clone(pair.Value); 175 173 176 foreach (var pair in this.parentOptimizersByPendingOptimizer) 174 clone.parentOptimizersByPendingOptimizer[pair.Key] = (IOptimizer)cloner.Clone(pair.Value); 177 clone.parentOptimizersByPendingOptimizer[(IOptimizer)cloner.Clone(pair.Key)] = (IOptimizer)cloner.Clone(pair.Value); 178 175 179 clone.log = (ILog)cloner.Clone(log); 176 180 clone.stopPending = this.stopPending; … … 243 247 public void Prepare() { 244 248 if (experiment != null) { 249 StopResultPolling(); 250 pendingOptimizersByJobId.Clear(); 251 parentOptimizersByPendingOptimizer.Clear(); 252 jobItems.Clear(); 245 253 experiment.Prepare(); 246 254 this.ExecutionState = Core.ExecutionState.Prepared; … … 251 259 public void Start() { 252 260 OnStarted(); 261 ExecutionTime = new TimeSpan(); 253 262 lastUpdateTime = DateTime.Now; 254 263 this.ExecutionState = Core.ExecutionState.Started; … … 295 304 private void CreateResultPollingThreads() { 296 305 foreach (JobItem jobItem in JobItems) { 297 if (!resultPollingThreads.ContainsKey(jobItem.JobDto.Id) ) {306 if (!resultPollingThreads.ContainsKey(jobItem.JobDto.Id) && jobItem.JobDto.State != State.Finished) { 298 307 resultPollingThreads.Add(jobItem.JobDto.Id, CreateResultPollingThread(jobItem.JobDto)); 299 308 } … … 303 312 public void StartResultPolling() { 304 313 this.stopResultsPollingPending = false; 305 CreateResultPollingThreads();306 foreach (Thread pollingThread in resultPollingThreads.Values) {307 if (pollingThread.ThreadState != System.Threading.ThreadState.Running) {308 pollingThread.Start();309 }310 }311 314 this.IsPollingResults = true; 315 lock (resultPollingThreads) { 316 CreateResultPollingThreads(); 317 foreach (Thread pollingThread in resultPollingThreads.Values) { 318 if (pollingThread.ThreadState != System.Threading.ThreadState.Running) { 319 pollingThread.Start(); 320 } 321 } 322 } 312 323 } 313 324 … … 452 463 453 464 do { 454 Thread.Sleep(resultPollingIntervalMs);455 465 if (stopPending || !this.IsPollingResults) { 456 466 return; … … 479 489 UpdateSnapshot(jobResponse); 480 490 } 491 492 Thread.Sleep(resultPollingIntervalMs); 481 493 } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped); 482 494 … … 486 498 IOptimizer originalOptimizer = pendingOptimizersByJobId[job.Id]; 487 499 IOptimizer restoredOptimizer = ((OptimizerJob)restoredObject).Optimizer; 488 500 489 501 ReplaceOptimizer(parentOptimizersByPendingOptimizer[originalOptimizer], originalOptimizer, restoredOptimizer); 490 502 pendingOptimizersByJobId.Remove(job.Id); 491 503 parentOptimizersByPendingOptimizer.Remove(originalOptimizer); 492 504 505 } catch (ThreadInterruptedException exception) { 506 507 } finally { 508 GetJobItemById(job.Id).LogMessage("ResultsPolling Thread stopped"); 509 lock (resultPollingThreads) { 510 resultPollingThreads.Remove(job.Id); 511 if (resultPollingThreads.Count == 0) { 512 IsPollingResults = false; 513 } 514 } 515 516 // check if finished 493 517 if (pendingOptimizersByJobId.Count == 0) { 494 // finished495 518 this.ExecutionState = Core.ExecutionState.Stopped; 496 519 OnStopped(); 497 520 } 498 } catch (ThreadInterruptedException exception) {499 500 } finally {501 GetJobItemById(job.Id).LogMessage("ResultsPolling Thread stopped");502 resultPollingThreads.Remove(job.Id);503 if (resultPollingThreads.Count == 0) {504 IsPollingResults = false;505 }506 521 } 507 522 }); … … 519 534 520 535 private void LogMessage(string message) { 521 // HeuristicLab.Log is not Thread-Safe, so lock every call536 // HeuristicLab.Log is not Thread-Safe, so lock on every call 522 537 lock (locker) { 523 538 log.LogMessage(message); 539 } 540 } 541 542 public void RequestSnapshot(Guid jobId) { 543 IExecutionEngineFacade executionEngineFacade = GetExecutionEngineFacade(); 544 ResponseObject<SerializedJob> response; 545 int retryCount = 0; 546 547 Response snapShotResponse = executionEngineFacade.RequestSnapshot(jobId); 548 if (snapShotResponse.StatusMessage == ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED) { 549 // job already finished 550 Logger.Debug("HiveEngine: Abort - GetLastResult(false)"); 551 response = executionEngineFacade.GetLastSerializedResult(jobId, false, false); 552 Logger.Debug("HiveEngine: Abort - Server: " + response.StatusMessage + " success: " + response.Success); 553 } else { 554 // server sent snapshot request to client 555 // poll until snapshot is ready 556 do { 557 Thread.Sleep(snapshotPollingIntervalMs); 558 Logger.Debug("HiveEngine: Abort - GetLastResult(true)"); 559 response = executionEngineFacade.GetLastSerializedResult(jobId, false, true); 560 Logger.Debug("HiveEngine: Abort - Server: " + response.StatusMessage + " success: " + response.Success); 561 retryCount++; 562 // loop while 563 // 1. problem with communication with server 564 // 2. job result not yet ready 565 } while ( 566 (retryCount < maxSnapshotRetries) && ( 567 !response.Success || 568 response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) 569 ); 570 } 571 SerializedJob jobResult = response.Obj; 572 if (jobResult != null) { 573 Logger.Debug("HiveEngine: Results-polling - Got result!"); 574 575 //job = XmlParser.Deserialize<Job>(new MemoryStream(jobResult.SerializedJobData)); 576 577 throw new NotImplementedException("[chn] how to create a view in 3.3 and why should i do this here? shouldnt the caller of this method receive a result and decide what to do?"); 578 //ControlManager.Manager.ShowControl(job.Engine.CreateView()); 524 579 } 525 580 }
Note: See TracChangeset
for help on using the changeset viewer.