Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/04/10 10:44:14 (14 years ago)
Author:
cneumuel
Message:

merged with changes from Hive-3.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs

    r4139 r4141  
    5353    private const string itemDescription = "A runner for a single experiment, which's algorithms are executed in the Hive.";
    5454    private const int resultPollingIntervalMs = 15000;
     55    private const int snapshotPollingIntervalMs = 1000;
    5556    private const int maxSnapshotRetries = 20;
    5657    private object locker = new object();
     
    169170      clone.executionTime = this.executionTime;
    170171      clone.pendingOptimizersByJobId = new Dictionary<Guid, IOptimizer>();
     172
    171173      foreach (var pair in this.pendingOptimizersByJobId)
    172174        clone.pendingOptimizersByJobId[pair.Key] = (IOptimizer)cloner.Clone(pair.Value);
     175
    173176      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
    175179      clone.log = (ILog)cloner.Clone(log);
    176180      clone.stopPending = this.stopPending;
     
    243247    public void Prepare() {
    244248      if (experiment != null) {
     249        StopResultPolling();
     250        pendingOptimizersByJobId.Clear();
     251        parentOptimizersByPendingOptimizer.Clear();
     252        jobItems.Clear();
    245253        experiment.Prepare();
    246254        this.ExecutionState = Core.ExecutionState.Prepared;
     
    251259    public void Start() {
    252260      OnStarted();
     261      ExecutionTime = new TimeSpan();
    253262      lastUpdateTime = DateTime.Now;
    254263      this.ExecutionState = Core.ExecutionState.Started;
     
    295304    private void CreateResultPollingThreads() {
    296305      foreach (JobItem jobItem in JobItems) {
    297         if (!resultPollingThreads.ContainsKey(jobItem.JobDto.Id)) {
     306        if (!resultPollingThreads.ContainsKey(jobItem.JobDto.Id) && jobItem.JobDto.State != State.Finished) {
    298307          resultPollingThreads.Add(jobItem.JobDto.Id, CreateResultPollingThread(jobItem.JobDto));
    299308        }
     
    303312    public void StartResultPolling() {
    304313      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       }
    311314      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      }
    312323    }
    313324
     
    452463
    453464          do {
    454             Thread.Sleep(resultPollingIntervalMs);
    455465            if (stopPending || !this.IsPollingResults) {
    456466              return;
     
    479489              UpdateSnapshot(jobResponse);
    480490            }
     491
     492            Thread.Sleep(resultPollingIntervalMs);
    481493          } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped);
    482494
     
    486498          IOptimizer originalOptimizer = pendingOptimizersByJobId[job.Id];
    487499          IOptimizer restoredOptimizer = ((OptimizerJob)restoredObject).Optimizer;
    488 
     500         
    489501          ReplaceOptimizer(parentOptimizersByPendingOptimizer[originalOptimizer], originalOptimizer, restoredOptimizer);
    490502          pendingOptimizersByJobId.Remove(job.Id);
    491503          parentOptimizersByPendingOptimizer.Remove(originalOptimizer);
    492504
     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
    493517          if (pendingOptimizersByJobId.Count == 0) {
    494             // finished
    495518            this.ExecutionState = Core.ExecutionState.Stopped;
    496519            OnStopped();
    497520          }
    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           }
    506521        }
    507522      });
     
    519534
    520535    private void LogMessage(string message) {
    521       // HeuristicLab.Log is not Thread-Safe, so lock every call
     536      // HeuristicLab.Log is not Thread-Safe, so lock on every call
    522537      lock (locker) {
    523538        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());
    524579      }
    525580    }
Note: See TracChangeset for help on using the changeset viewer.