Changeset 2032
- Timestamp:
- 06/08/09 18:34:28 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Hive.Engine/3.2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLab.Hive.Engine-3.2.csproj
r1761 r2032 126 126 <Name>HeuristicLab.SequentialEngine-3.2</Name> 127 127 </ProjectReference> 128 <ProjectReference Include="..\..\HeuristicLab.Tracing\3.2\HeuristicLab.Tracing-3.2.csproj"> 129 <Project>{EE2034D9-6E27-48A1-B855-42D45F69A4FC}</Project> 130 <Name>HeuristicLab.Tracing-3.2</Name> 131 </ProjectReference> 128 132 </ItemGroup> 129 133 <ItemGroup> -
trunk/sources/HeuristicLab.Hive.Engine/3.2/HeuristicLabHiveEnginePlugin.cs
r1927 r2032 37 37 [Dependency(Dependency = "HeuristicLab.Hive.JobBase-3.2")] 38 38 [Dependency(Dependency = "HeuristicLab.SequentialEngine-3.2")] 39 [Dependency(Dependency = "HeuristicLab.Tracing-3.2")] 39 40 public class HeuristicLabHiveEnginePlugin : PluginBase { 40 41 } -
trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs
r2018 r2032 33 33 using System.Xml; 34 34 using System.IO.Compression; 35 using HeuristicLab.Tracing; 35 36 36 37 namespace HeuristicLab.Hive.Engine { … … 44 45 private Guid jobId; 45 46 private Job job; 47 private object locker = new object(); 48 private volatile bool abortRequested; 49 46 50 public string HiveServerUrl { get; set; } 47 51 48 52 public HiveEngine() { 49 53 job = new Job(); 54 abortRequested = false; 50 55 } 51 56 … … 96 101 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl); 97 102 ResponseObject<JobResult> response = null; 103 Job restoredJob = null; 98 104 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); 105 Thread.Sleep(RESULT_POLLING_INTERVAL_MS); 106 lock (locker) { 107 HiveLogger.Debug("HiveEngine: Results-polling - GetLastResult"); 108 response = executionEngineFacade.GetLastResult(jobId, false); 109 HiveLogger.Debug("HiveEngine: Results-polling - Server: " + response.StatusMessage + " success: " + response.Success); 110 // loop while 111 // 1. the user doesn't request an abort 112 // 2. there is a problem with server communication (success==false) 113 // 3. no result for the job is available yet (response.Obj==null) 114 // 4. the result that we get from the server is a snapshot and not the final result 115 if (abortRequested) return; 116 if (response.Success && response.Obj != null) { 117 HiveLogger.Debug("HiveEngine: Results-polling - Got result!"); 118 restoredJob = (Job)PersistenceManager.RestoreFromGZip(response.Obj.Result); 119 HiveLogger.Debug("HiveEngine: Results-polling - IsSnapshotResult: " + restoredJob.Engine.Canceled); 120 } 102 121 } 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 } 122 } while (restoredJob == null || restoredJob.Engine.Canceled); 123 124 job = restoredJob; 125 OnChanged(); 126 OnFinished(); 114 127 }); 128 HiveLogger.Debug("HiveEngine: Starting results-polling thread"); 115 129 t.Start(); 116 130 } … … 119 133 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl); 120 134 121 // poll until snapshot is ready122 135 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) { 136 lock (locker) { 137 HiveLogger.Debug("HiveEngine: Abort - RequestSnapshot"); 138 Response snapShotResponse = executionEngineFacade.RequestSnapshot(jobId); 139 if (snapShotResponse.StatusMessage == ApplicationConstants.RESPONSE_JOB_IS_NOT_BEEING_CALCULATED) { 140 // job is finished already 141 HiveLogger.Debug("HiveEngine: Abort - GetLastResult(false)"); 142 response = executionEngineFacade.GetLastResult(jobId, false); 143 HiveLogger.Debug("HiveEngine: Abort - Server: " + response.StatusMessage + " success: " + response.Success); 144 } else { 145 // server sent snapshot request to client 146 // poll until snapshot is ready 147 do { 132 148 Thread.Sleep(SNAPSHOT_POLLING_INTERVAL_MS); 133 } 134 } while (response.Success && response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE); 149 HiveLogger.Debug("HiveEngine: Abort - GetLastResult(true)"); 150 response = executionEngineFacade.GetLastResult(jobId, true); 151 HiveLogger.Debug("HiveEngine: Abort - Server: " + response.StatusMessage + " success: " + response.Success); 152 // loop while 153 // 1. problem with communication with server 154 // 2. job result not yet ready 155 } while ( 156 !response.Success || 157 response.StatusMessage == ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE); 158 } 135 159 } 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); }); 160 JobResult jobResult = response.Obj; 161 if (jobResult != null) { 162 HiveLogger.Debug("HiveEngine: Results-polling - Got result!"); 163 job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result); 164 //PluginManager.ControlManager.ShowControl(job.Engine.CreateView()); 145 165 } 166 //HiveLogger.Debug("HiveEngine: Results-polling - Exception!"); 167 //Exception ex = new Exception(response.Obj.Exception.Message); 168 //ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); }); 146 169 } 147 170 … … 155 178 156 179 public void Abort() { 180 abortRequested = true; 181 RequestSnapshot(); 157 182 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl); 158 183 executionEngineFacade.AbortJob(jobId); 184 OnChanged(); 159 185 OnFinished(); 160 186 } 161 187 162 188 public void Reset() { 189 abortRequested = false; 163 190 job.Engine.Reset(); 164 191 jobId = Guid.NewGuid(); -
trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs
r2018 r2032 47 47 this.urlTextBox = new System.Windows.Forms.TextBox(); 48 48 this.urlLabel = new System.Windows.Forms.Label(); 49 this.snapshotButton = new System.Windows.Forms.Button(); 49 50 this.splitContainer1.Panel1.SuspendLayout(); 50 51 this.splitContainer1.Panel2.SuspendLayout(); … … 101 102 this.urlLabel.Text = "Hive Server Url:"; 102 103 // 104 // snapshotButton 105 // 106 this.snapshotButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 107 this.snapshotButton.Enabled = false; 108 this.snapshotButton.Location = new System.Drawing.Point(294, 457); 109 this.snapshotButton.Name = "snapshotButton"; 110 this.snapshotButton.Size = new System.Drawing.Size(75, 23); 111 this.snapshotButton.TabIndex = 9; 112 this.snapshotButton.Text = "Sna&pshot"; 113 this.snapshotButton.UseVisualStyleBackColor = true; 114 this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click); 115 // 103 116 // HiveEngineEditor 104 117 // 105 118 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 106 119 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 120 this.Controls.Add(this.snapshotButton); 107 121 this.Controls.Add(this.urlTextBox); 108 122 this.Controls.Add(this.urlLabel); … … 117 131 this.Controls.SetChildIndex(this.urlLabel, 0); 118 132 this.Controls.SetChildIndex(this.urlTextBox, 0); 133 this.Controls.SetChildIndex(this.snapshotButton, 0); 119 134 this.splitContainer1.Panel1.ResumeLayout(false); 120 135 this.splitContainer1.Panel2.ResumeLayout(false); … … 131 146 private System.Windows.Forms.TextBox urlTextBox; 132 147 private System.Windows.Forms.Label urlLabel; 148 private System.Windows.Forms.Button snapshotButton; 133 149 } 134 150 } -
trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs
r2018 r2032 28 28 using System.Windows.Forms; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Tracing; 30 31 31 32 namespace HeuristicLab.Hive.Engine { … … 68 69 69 70 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(); 71 snapshotButton.Enabled = false; 81 72 } 82 73 83 74 void executeButton_Click(object sender, EventArgs e) { 84 75 abortButton.Enabled = true; 76 snapshotButton.Enabled = true; 85 77 } 86 78 … … 102 94 103 95 void Engine_Initialized(object sender, EventArgs e) { 104 abortButton.Enabled = false; 96 if (InvokeRequired) { 97 Invoke((EventHandler)Engine_Initialized, sender, e); 98 } else { 99 abortButton.Enabled = false; 100 snapshotButton.Enabled = false; 101 } 105 102 } 106 103 107 104 void Engine_Finished(object sender, EventArgs e) { 105 if (InvokeRequired) { 106 Invoke((EventHandler)Engine_Initialized, sender, e); 107 } else { 108 abortButton.Enabled = false; 109 snapshotButton.Enabled = false; 110 } 111 } 112 113 private void snapshotButton_Click(object sender, EventArgs e) { 114 BackgroundWorker worker = new BackgroundWorker(); 115 worker.DoWork += (s, args) => { 116 HiveEngine.RequestSnapshot(); 117 }; 118 worker.RunWorkerCompleted += (s, args) => { 119 Logger.Debug("HiveEngineEditor: RunWorkerCompleted"); 120 this.Cursor = Cursors.Default; 121 abortButton.Enabled = true; 122 snapshotButton.Enabled = true; 123 }; 124 this.Cursor = Cursors.WaitCursor; 108 125 abortButton.Enabled = false; 126 snapshotButton.Enabled = false; 127 Logger.Debug("HiveEngineEditor: RunWorkerAsync"); 128 worker.RunWorkerAsync(); 109 129 } 110 130 }
Note: See TracChangeset
for help on using the changeset viewer.