Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2018


Ignore:
Timestamp:
06/04/09 20:58:08 (15 years ago)
Author:
gkronber
Message:

Simplified HiveEngineEditor and worked on asynchronous polling of results in HiveEngine. #545 (Engine which can be executed in the Hive)

Location:
trunk/sources/HeuristicLab.Hive.Engine/3.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs

    r1990 r2018  
    4040  /// </summary>
    4141  public class HiveEngine : ItemBase, IEngine, IEditable {
     42    private const int SNAPSHOT_POLLING_INTERVAL_MS = 1000;
     43    private const int RESULT_POLLING_INTERVAL_MS = 10000;
    4244    private Guid jobId;
    4345    private Job job;
     
    8587      ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj);
    8688      jobId = res.Obj.Id;
     89
     90      StartResultPollingThread();
     91    }
     92
     93    private void StartResultPollingThread() {
     94      // start a backgroud thread to poll the final result of the job
     95      Thread t = new Thread(() => {
     96        IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
     97        ResponseObject<JobResult> response = null;
     98        do {
     99          response = executionEngineFacade.GetLastResult(jobId, true);
     100          if (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) {
     101            Thread.Sleep(RESULT_POLLING_INTERVAL_MS);
     102          }
     103        } while (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE);
     104        if (response.Success) {
     105          JobResult jobResult = response.Obj;
     106          if (jobResult != null) {
     107            job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
     108            OnFinished();
     109          }
     110        } else {
     111          Exception ex = new Exception(response.Obj.Exception.Message);
     112          ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
     113        }
     114      });
     115      t.Start();
     116    }
     117
     118    public void RequestSnapshot() {
     119      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
     120
     121      // poll until snapshot is ready
     122      ResponseObject<JobResult> response;
     123
     124      // request snapshot
     125      Response snapShotResponse = executionEngineFacade.RequestSnapshot(jobId);
     126      if (snapShotResponse.StatusMessage == ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED) {
     127        response = executionEngineFacade.GetLastResult(jobId, false);
     128      } else {
     129        do {
     130          response = executionEngineFacade.GetLastResult(jobId, true);
     131          if (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) {
     132            Thread.Sleep(SNAPSHOT_POLLING_INTERVAL_MS);
     133          }
     134        } while (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE);
     135      }
     136      if (response.Success) {
     137        JobResult jobResult = response.Obj;
     138        if (jobResult != null) {
     139          job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
     140          //PluginManager.ControlManager.ShowControl(job.Engine.CreateView());
     141        }
     142      } else {
     143        Exception ex = new Exception(response.Obj.Exception.Message);
     144        ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
     145      }
     146    }
     147
     148    public void ExecuteStep() {
     149      throw new NotSupportedException();
     150    }
     151
     152    public void ExecuteSteps(int steps) {
     153      throw new NotSupportedException();
     154    }
     155
     156    public void Abort() {
     157      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
     158      executionEngineFacade.AbortJob(jobId);
     159      OnFinished();
     160    }
     161
     162    public void Reset() {
     163      job.Engine.Reset();
     164      jobId = Guid.NewGuid();
     165      OnInitialized();
    87166    }
    88167
     
    131210    }
    132211
    133     public void RequestSnapshot() {
    134       IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
    135 
    136       // poll until snapshot is ready
    137       ResponseObject<JobResult> response;
    138 
    139       // request snapshot
    140       Response snapShotResponse = executionEngineFacade.RequestSnapshot(jobId);
    141       if (snapShotResponse.StatusMessage == ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED) {
    142         response = executionEngineFacade.GetLastResult(jobId, false);
    143       } else {
    144         do {
    145           response = executionEngineFacade.GetLastResult(jobId, true);
    146           if (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) {
    147             Thread.Sleep(1000);
    148           }
    149         } while (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE);
    150       }
    151       if (response.Success) {
    152         JobResult jobResult = response.Obj;
    153         if (jobResult != null) {
    154           job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
    155           PluginManager.ControlManager.ShowControl(job.Engine.CreateView());
    156         }
    157       } else {
    158         Exception ex = new Exception(response.Obj.Exception.Message);
    159         ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
    160       }
    161     }
    162 
    163 
    164     public void ExecuteStep() {
    165       throw new NotSupportedException();
    166     }
    167 
    168     public void ExecuteSteps(int steps) {
    169       throw new NotSupportedException();
    170     }
    171 
    172     public void Abort() {
    173       IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
    174       executionEngineFacade.AbortJob(jobId);
    175       OnFinished();
    176     }
    177 
    178     public void Reset() {
    179       job.Engine.Reset();
    180       jobId = Guid.NewGuid();
    181       OnInitialized();
    182     }
    183 
    184212    public event EventHandler Initialized;
    185213    /// <summary>
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs

    r1726 r2018  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.snapshotButton = new System.Windows.Forms.Button();
    4847      this.urlTextBox = new System.Windows.Forms.TextBox();
    4948      this.urlLabel = new System.Windows.Forms.Label();
     
    8483      this.scopeView.Size = new System.Drawing.Size(178, 422);
    8584      //
    86       // snapshotButton
    87       //
    88       this.snapshotButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    89       this.snapshotButton.Enabled = false;
    90       this.snapshotButton.Location = new System.Drawing.Point(294, 457);
    91       this.snapshotButton.Name = "snapshotButton";
    92       this.snapshotButton.Size = new System.Drawing.Size(92, 23);
    93       this.snapshotButton.TabIndex = 6;
    94       this.snapshotButton.Text = "Snapshot";
    95       this.snapshotButton.UseVisualStyleBackColor = true;
    96       this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click);
    97       //
    9885      // urlTextBox
    9986      //
     
    118105      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    119106      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    120       this.Controls.Add(this.snapshotButton);
    121107      this.Controls.Add(this.urlTextBox);
    122108      this.Controls.Add(this.urlLabel);
     
    131117      this.Controls.SetChildIndex(this.urlLabel, 0);
    132118      this.Controls.SetChildIndex(this.urlTextBox, 0);
    133       this.Controls.SetChildIndex(this.snapshotButton, 0);
    134119      this.splitContainer1.Panel1.ResumeLayout(false);
    135120      this.splitContainer1.Panel2.ResumeLayout(false);
     
    144129    #endregion
    145130
    146     private System.Windows.Forms.Button snapshotButton;
    147131    private System.Windows.Forms.TextBox urlTextBox;
    148132    private System.Windows.Forms.Label urlLabel;
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs

    r1726 r2018  
    6464      HiveEngine = hiveEngine;
    6565      base.executeButton.Click += new EventHandler(executeButton_Click);
     66      base.abortButton.Click += new EventHandler(abortButton_Click);
     67    }
     68
     69    void abortButton_Click(object sender, EventArgs e) {
     70      BackgroundWorker worker = new BackgroundWorker();
     71      worker.DoWork += (s, args) => {
     72        HiveEngine.RequestSnapshot();
     73      };
     74      worker.RunWorkerCompleted += (s, args) => {
     75        this.Cursor = Cursors.Default;
     76        abortButton.Enabled = true;
     77      };
     78      this.Cursor = Cursors.WaitCursor;
     79      abortButton.Enabled = false;
     80      worker.RunWorkerAsync();
    6681    }
    6782
    6883    void executeButton_Click(object sender, EventArgs e) {
    69       snapshotButton.Enabled = true;
     84      abortButton.Enabled = true;
    7085    }
    7186
     
    87102
    88103    void Engine_Initialized(object sender, EventArgs e) {
    89       snapshotButton.Enabled = false;
     104      abortButton.Enabled = false;
    90105    }
    91106
    92107    void Engine_Finished(object sender, EventArgs e) {
    93       snapshotButton.Enabled = false;
    94     }
    95 
    96     private void snapshotButton_Click(object sender, EventArgs e) {
    97       HiveEngine.RequestSnapshot();
     108      abortButton.Enabled = false;
    98109    }
    99110  }
Note: See TracChangeset for help on using the changeset viewer.