Index: /trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLab.Hive.Engine-3.2.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLab.Hive.Engine-3.2.csproj (revision 2031)
+++ /trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLab.Hive.Engine-3.2.csproj (revision 2032)
@@ -126,4 +126,8 @@
HeuristicLab.SequentialEngine-3.2
+
+ {EE2034D9-6E27-48A1-B855-42D45F69A4FC}
+ HeuristicLab.Tracing-3.2
+
Index: /trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLabHiveEnginePlugin.cs
===================================================================
--- /trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLabHiveEnginePlugin.cs (revision 2031)
+++ /trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLabHiveEnginePlugin.cs (revision 2032)
@@ -37,4 +37,5 @@
[Dependency(Dependency = "HeuristicLab.Hive.JobBase-3.2")]
[Dependency(Dependency = "HeuristicLab.SequentialEngine-3.2")]
+ [Dependency(Dependency = "HeuristicLab.Tracing-3.2")]
public class HeuristicLabHiveEnginePlugin : PluginBase {
}
Index: /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs
===================================================================
--- /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs (revision 2031)
+++ /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs (revision 2032)
@@ -33,4 +33,5 @@
using System.Xml;
using System.IO.Compression;
+using HeuristicLab.Tracing;
namespace HeuristicLab.Hive.Engine {
@@ -44,8 +45,12 @@
private Guid jobId;
private Job job;
+ private object locker = new object();
+ private volatile bool abortRequested;
+
public string HiveServerUrl { get; set; }
public HiveEngine() {
job = new Job();
+ abortRequested = false;
}
@@ -96,21 +101,30 @@
IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
ResponseObject response = null;
+ Job restoredJob = null;
do {
- response = executionEngineFacade.GetLastResult(jobId, true);
- if (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) {
- Thread.Sleep(RESULT_POLLING_INTERVAL_MS);
+ Thread.Sleep(RESULT_POLLING_INTERVAL_MS);
+ lock (locker) {
+ HiveLogger.Debug("HiveEngine: Results-polling - GetLastResult");
+ response = executionEngineFacade.GetLastResult(jobId, false);
+ HiveLogger.Debug("HiveEngine: Results-polling - Server: " + response.StatusMessage + " success: " + response.Success);
+ // loop while
+ // 1. the user doesn't request an abort
+ // 2. there is a problem with server communication (success==false)
+ // 3. no result for the job is available yet (response.Obj==null)
+ // 4. the result that we get from the server is a snapshot and not the final result
+ if (abortRequested) return;
+ if (response.Success && response.Obj != null) {
+ HiveLogger.Debug("HiveEngine: Results-polling - Got result!");
+ restoredJob = (Job)PersistenceManager.RestoreFromGZip(response.Obj.Result);
+ HiveLogger.Debug("HiveEngine: Results-polling - IsSnapshotResult: " + restoredJob.Engine.Canceled);
+ }
}
- } while (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE);
- if (response.Success) {
- JobResult jobResult = response.Obj;
- if (jobResult != null) {
- job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
- OnFinished();
- }
- } else {
- Exception ex = new Exception(response.Obj.Exception.Message);
- ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
- }
+ } while (restoredJob == null || restoredJob.Engine.Canceled);
+
+ job = restoredJob;
+ OnChanged();
+ OnFinished();
});
+ HiveLogger.Debug("HiveEngine: Starting results-polling thread");
t.Start();
}
@@ -119,29 +133,38 @@
IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
- // poll until snapshot is ready
ResponseObject response;
-
- // request snapshot
- Response snapShotResponse = executionEngineFacade.RequestSnapshot(jobId);
- if (snapShotResponse.StatusMessage == ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED) {
- response = executionEngineFacade.GetLastResult(jobId, false);
- } else {
- do {
- response = executionEngineFacade.GetLastResult(jobId, true);
- if (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) {
+ lock (locker) {
+ HiveLogger.Debug("HiveEngine: Abort - RequestSnapshot");
+ Response snapShotResponse = executionEngineFacade.RequestSnapshot(jobId);
+ if (snapShotResponse.StatusMessage == ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED) {
+ // job is finished already
+ HiveLogger.Debug("HiveEngine: Abort - GetLastResult(false)");
+ response = executionEngineFacade.GetLastResult(jobId, false);
+ HiveLogger.Debug("HiveEngine: Abort - Server: " + response.StatusMessage + " success: " + response.Success);
+ } else {
+ // server sent snapshot request to client
+ // poll until snapshot is ready
+ do {
Thread.Sleep(SNAPSHOT_POLLING_INTERVAL_MS);
- }
- } while (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE);
+ HiveLogger.Debug("HiveEngine: Abort - GetLastResult(true)");
+ response = executionEngineFacade.GetLastResult(jobId, true);
+ HiveLogger.Debug("HiveEngine: Abort - Server: " + response.StatusMessage + " success: " + response.Success);
+ // loop while
+ // 1. problem with communication with server
+ // 2. job result not yet ready
+ } while (
+ !response.Success ||
+ response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE);
+ }
}
- if (response.Success) {
- JobResult jobResult = response.Obj;
- if (jobResult != null) {
- job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
- //PluginManager.ControlManager.ShowControl(job.Engine.CreateView());
- }
- } else {
- Exception ex = new Exception(response.Obj.Exception.Message);
- ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
+ JobResult jobResult = response.Obj;
+ if (jobResult != null) {
+ HiveLogger.Debug("HiveEngine: Results-polling - Got result!");
+ job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
+ //PluginManager.ControlManager.ShowControl(job.Engine.CreateView());
}
+ //HiveLogger.Debug("HiveEngine: Results-polling - Exception!");
+ //Exception ex = new Exception(response.Obj.Exception.Message);
+ //ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
}
@@ -155,10 +178,14 @@
public void Abort() {
+ abortRequested = true;
+ RequestSnapshot();
IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
executionEngineFacade.AbortJob(jobId);
+ OnChanged();
OnFinished();
}
public void Reset() {
+ abortRequested = false;
job.Engine.Reset();
jobId = Guid.NewGuid();
Index: /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs (revision 2031)
+++ /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs (revision 2032)
@@ -47,4 +47,5 @@
this.urlTextBox = new System.Windows.Forms.TextBox();
this.urlLabel = new System.Windows.Forms.Label();
+ this.snapshotButton = new System.Windows.Forms.Button();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -101,8 +102,21 @@
this.urlLabel.Text = "Hive Server Url:";
//
+ // snapshotButton
+ //
+ this.snapshotButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.snapshotButton.Enabled = false;
+ this.snapshotButton.Location = new System.Drawing.Point(294, 457);
+ this.snapshotButton.Name = "snapshotButton";
+ this.snapshotButton.Size = new System.Drawing.Size(75, 23);
+ this.snapshotButton.TabIndex = 9;
+ this.snapshotButton.Text = "Sna&pshot";
+ this.snapshotButton.UseVisualStyleBackColor = true;
+ this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click);
+ //
// HiveEngineEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.snapshotButton);
this.Controls.Add(this.urlTextBox);
this.Controls.Add(this.urlLabel);
@@ -117,4 +131,5 @@
this.Controls.SetChildIndex(this.urlLabel, 0);
this.Controls.SetChildIndex(this.urlTextBox, 0);
+ this.Controls.SetChildIndex(this.snapshotButton, 0);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
@@ -131,4 +146,5 @@
private System.Windows.Forms.TextBox urlTextBox;
private System.Windows.Forms.Label urlLabel;
+ private System.Windows.Forms.Button snapshotButton;
}
}
Index: /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs
===================================================================
--- /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs (revision 2031)
+++ /trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs (revision 2032)
@@ -28,4 +28,5 @@
using System.Windows.Forms;
using HeuristicLab.Core;
+using HeuristicLab.Tracing;
namespace HeuristicLab.Hive.Engine {
@@ -68,19 +69,10 @@
void abortButton_Click(object sender, EventArgs e) {
- BackgroundWorker worker = new BackgroundWorker();
- worker.DoWork += (s, args) => {
- HiveEngine.RequestSnapshot();
- };
- worker.RunWorkerCompleted += (s, args) => {
- this.Cursor = Cursors.Default;
- abortButton.Enabled = true;
- };
- this.Cursor = Cursors.WaitCursor;
- abortButton.Enabled = false;
- worker.RunWorkerAsync();
+ snapshotButton.Enabled = false;
}
void executeButton_Click(object sender, EventArgs e) {
abortButton.Enabled = true;
+ snapshotButton.Enabled = true;
}
@@ -102,9 +94,37 @@
void Engine_Initialized(object sender, EventArgs e) {
- abortButton.Enabled = false;
+ if (InvokeRequired) {
+ Invoke((EventHandler)Engine_Initialized, sender, e);
+ } else {
+ abortButton.Enabled = false;
+ snapshotButton.Enabled = false;
+ }
}
void Engine_Finished(object sender, EventArgs e) {
+ if (InvokeRequired) {
+ Invoke((EventHandler)Engine_Initialized, sender, e);
+ } else {
+ abortButton.Enabled = false;
+ snapshotButton.Enabled = false;
+ }
+ }
+
+ private void snapshotButton_Click(object sender, EventArgs e) {
+ BackgroundWorker worker = new BackgroundWorker();
+ worker.DoWork += (s, args) => {
+ HiveEngine.RequestSnapshot();
+ };
+ worker.RunWorkerCompleted += (s, args) => {
+ Logger.Debug("HiveEngineEditor: RunWorkerCompleted");
+ this.Cursor = Cursors.Default;
+ abortButton.Enabled = true;
+ snapshotButton.Enabled = true;
+ };
+ this.Cursor = Cursors.WaitCursor;
abortButton.Enabled = false;
+ snapshotButton.Enabled = false;
+ Logger.Debug("HiveEngineEditor: RunWorkerAsync");
+ worker.RunWorkerAsync();
}
}