Changeset 2018
- Timestamp:
- 06/04/09 20:58:08 (16 years ago)
- 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 40 40 /// </summary> 41 41 public class HiveEngine : ItemBase, IEngine, IEditable { 42 private const int SNAPSHOT_POLLING_INTERVAL_MS = 1000; 43 private const int RESULT_POLLING_INTERVAL_MS = 10000; 42 44 private Guid jobId; 43 45 private Job job; … … 85 87 ResponseObject<Contracts.BusinessObjects.Job> res = executionEngineFacade.AddJob(jobObj); 86 88 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(); 87 166 } 88 167 … … 131 210 } 132 211 133 public void RequestSnapshot() {134 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);135 136 // poll until snapshot is ready137 ResponseObject<JobResult> response;138 139 // request snapshot140 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 184 212 public event EventHandler Initialized; 185 213 /// <summary> -
trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs
r1726 r2018 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.snapshotButton = new System.Windows.Forms.Button();48 47 this.urlTextBox = new System.Windows.Forms.TextBox(); 49 48 this.urlLabel = new System.Windows.Forms.Label(); … … 84 83 this.scopeView.Size = new System.Drawing.Size(178, 422); 85 84 // 86 // snapshotButton87 //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 //98 85 // urlTextBox 99 86 // … … 118 105 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 119 106 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 120 this.Controls.Add(this.snapshotButton);121 107 this.Controls.Add(this.urlTextBox); 122 108 this.Controls.Add(this.urlLabel); … … 131 117 this.Controls.SetChildIndex(this.urlLabel, 0); 132 118 this.Controls.SetChildIndex(this.urlTextBox, 0); 133 this.Controls.SetChildIndex(this.snapshotButton, 0);134 119 this.splitContainer1.Panel1.ResumeLayout(false); 135 120 this.splitContainer1.Panel2.ResumeLayout(false); … … 144 129 #endregion 145 130 146 private System.Windows.Forms.Button snapshotButton;147 131 private System.Windows.Forms.TextBox urlTextBox; 148 132 private System.Windows.Forms.Label urlLabel; -
trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs
r1726 r2018 64 64 HiveEngine = hiveEngine; 65 65 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(); 66 81 } 67 82 68 83 void executeButton_Click(object sender, EventArgs e) { 69 snapshotButton.Enabled = true;84 abortButton.Enabled = true; 70 85 } 71 86 … … 87 102 88 103 void Engine_Initialized(object sender, EventArgs e) { 89 snapshotButton.Enabled = false;104 abortButton.Enabled = false; 90 105 } 91 106 92 107 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; 98 109 } 99 110 }
Note: See TracChangeset
for help on using the changeset viewer.