Changeset 4120 for branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment
- Timestamp:
- 07/29/10 16:58:35 (14 years ago)
- Location:
- branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3
- Property svn:ignore
-
old new 1 1 bin 2 2 obj 3 HeuristicLab.Hive.Experiment-3.3.csproj.user
-
- Property svn:ignore
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HeuristicLab.Hive.Experiment-3.3.csproj
r4119 r4120 96 96 </ItemGroup> 97 97 <ItemGroup> 98 <Compile Include="JobItemList.cs" /> 99 <Compile Include="JobItem.cs" /> 98 100 <Compile Include="OptimizerJob.cs" /> 99 101 <Compile Include="HeuristicLabHiveExperimentPlugin.cs" /> -
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
r4119 r4120 54 54 private const int resultPollingIntervalMs = 10000; 55 55 56 private object locker = new object(); 56 57 private const int maxSnapshotRetries = 20; 57 58 [Storable] 59 private IDictionary<Guid, IOptimizer> sentOptimizers = null; 60 61 private object locker = new object(); 62 private DateTime startTime; 58 private System.Timers.Timer timer; 59 private bool pausePending, stopPending; 60 private DateTime lastUpdateTime; 61 62 [Storable] 63 private IDictionary<Guid, IOptimizer> pendingOptimizers = new Dictionary<Guid, IOptimizer>(); 64 65 [Storable] 66 private JobItemList jobItems; 67 public JobItemList JobItems { 68 get { return jobItems; } 69 } 70 63 71 64 72 [Storable] … … 66 74 public string ServerUrl { 67 75 get { return serverUrl; } 68 set { serverUrl = value; OnServerUrlChanged(); } 76 set { 77 if (serverUrl != value) { 78 serverUrl = value; 79 OnServerUrlChanged(); 80 } 81 } 69 82 } 70 83 … … 73 86 public string ResourceIds { 74 87 get { return resourceIds; } 75 set { resourceIds = value; OnResourceIdsChanged(); } 88 set { 89 if (resourceIds != value) { 90 resourceIds = value; 91 OnResourceIdsChanged(); 92 } 93 } 76 94 } 77 95 … … 80 98 public HeuristicLab.Optimization.Experiment Experiment { 81 99 get { return experiment; } 82 set { experiment = value; OnExperimentChanged(); } 100 set { 101 if (experiment != value) { 102 experiment = value; 103 OnExperimentChanged(); 104 } 105 } 106 } 107 108 [Storable] 109 private ILog log; 110 public ILog Log { 111 get { return log; } 83 112 } 84 113 … … 92 121 this.ServerUrl = HeuristicLab.Hive.Experiment.Properties.Settings.Default.HiveServerUrl; 93 122 this.ResourceIds = HeuristicLab.Hive.Experiment.Properties.Settings.Default.ResourceIds; 123 this.log = new Log(); 124 pausePending = stopPending = false; 125 jobItems = new JobItemList(); 126 InitTimer(); 94 127 } 95 128 96 129 public override IDeepCloneable Clone(Cloner cloner) { 130 log.LogMessage("I am beeing cloned"); 97 131 HiveExperiment clone = (HiveExperiment)base.Clone(cloner); 98 132 clone.resourceIds = this.resourceIds; … … 101 135 clone.executionState = this.executionState; 102 136 clone.executionTime = this.executionTime; 103 clone.sentOptimizers = new Dictionary<Guid, IOptimizer>(); 104 foreach (var pair in this.sentOptimizers) 105 clone.sentOptimizers[pair.Key] = (IOptimizer)cloner.Clone(pair.Value); 137 clone.pendingOptimizers = new Dictionary<Guid, IOptimizer>(); 138 foreach (var pair in this.pendingOptimizers) 139 clone.pendingOptimizers[pair.Key] = (IOptimizer)cloner.Clone(pair.Value); 140 clone.log = (ILog)cloner.Clone(log); 141 clone.stopPending = this.stopPending; 142 clone.pausePending = this.pausePending; 143 clone.jobItems = (JobItemList)cloner.Clone(jobItems); 106 144 return clone; 145 } 146 147 [StorableHook(HookType.AfterDeserialization)] 148 private void AfterDeserialization() { 149 InitTimer(); 150 log.LogMessage("I was deserialized."); 151 } 152 153 private void InitTimer() { 154 timer = new System.Timers.Timer(100); 155 timer.AutoReset = true; 156 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 157 } 158 159 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 160 DateTime now = DateTime.Now; 161 ExecutionTime += now - lastUpdateTime; 162 lastUpdateTime = now; 107 163 } 108 164 … … 135 191 get { return executionTime; } 136 192 private set { 137 executionTime = value; 138 OnExecutionTimeChanged(); 193 if (executionTime != value) { 194 executionTime = value; 195 OnExecutionTimeChanged(); 196 } 139 197 } 140 198 } … … 145 203 146 204 public void Prepare() { 147 // [chn] needed?148 205 if (experiment != null) { 149 206 experiment.Prepare(); 207 this.ExecutionState = Core.ExecutionState.Prepared; 150 208 OnPrepared(); 151 209 } … … 153 211 154 212 public void Start() { 155 this.startTime = DateTime.Now; 213 OnStarted(); 214 lastUpdateTime = DateTime.Now; 156 215 this.ExecutionState = Core.ExecutionState.Started; 157 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(ServerUrl); 158 159 sentOptimizers = new Dictionary<Guid, IOptimizer>(); 160 IEnumerable<string> groups = ResourceGroups; 161 162 foreach (IOptimizer optimizer in Experiment.Optimizers) { 163 SerializedJob serializedJob = CreateSerializedJob(optimizer); 164 ResponseObject<JobDto> response = executionEngineFacade.AddJobWithGroupStrings(serializedJob, groups); 165 sentOptimizers.Add(response.Obj.Id, optimizer); 166 StartResultPollingThread(response.Obj); 167 } 216 Thread t = new Thread(() => { 217 IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(ServerUrl); 218 219 pendingOptimizers = new Dictionary<Guid, IOptimizer>(); 220 IEnumerable<string> groups = ResourceGroups; 221 222 foreach (IOptimizer optimizer in GetOptimizers(false)) { 223 SerializedJob serializedJob = CreateSerializedJob(optimizer); 224 ResponseObject<JobDto> response = executionEngineFacade.AddJobWithGroupStrings(serializedJob, groups); 225 pendingOptimizers.Add(response.Obj.Id, optimizer); 226 StartResultPollingThread(response.Obj); 227 228 JobItem jobItem = new JobItem() { 229 JobDto = response.Obj, 230 LatestSnapshot = new ResponseObject<SerializedJob>() { 231 Obj = serializedJob, 232 StatusMessage = "Initial Snapshot", 233 Success = true 234 } 235 }; 236 jobItems.Add(jobItem); 237 238 log.LogMessage("Sent job to server (jobId: " + response.Obj.Id + ")"); 239 } 240 }); 241 t.Start(); 242 } 243 244 /// <summary> 245 /// Returns all optimizers in the current Experiment 246 /// </summary> 247 /// <param name="flatout">if false only top level optimizers are returned, if true the optimizer-tree is flatted</param> 248 /// <returns></returns> 249 private IEnumerable<IOptimizer> GetOptimizers(bool flatout) { 250 if (!flatout) { 251 return experiment.Optimizers; 252 } else { 253 throw new NotImplementedException(); 254 } 255 } 256 257 private void ReplaceOptimizer(IOptimizer originalOptimizer, IOptimizer newOptimizer) { 258 int originalOptimizerIndex = experiment.Optimizers.IndexOf(originalOptimizer); 259 experiment.Optimizers[originalOptimizerIndex] = newOptimizer; 168 260 } 169 261 … … 171 263 // todo 172 264 } 173 174 private bool abortRequested; 175 265 176 266 #endregion 177 267 … … 219 309 Thread.Sleep(resultPollingIntervalMs); 220 310 lock (locker) { 221 if ( abortRequested) return;222 311 if (stopPending) return; 312 223 313 ResponseObject<SerializedJob> response = executionEngineFacade.GetLastSerializedResult(job.Id, false, false); 224 314 log.LogMessage("Received response for job: " + response.StatusMessage + " (jobId: " + job.Id + ")"); 315 316 225 317 // loop while 226 318 // 1. the user doesn't request an abort … … 229 321 // 4. the result that we get from the server is a snapshot and not the final result 230 322 if (response.Success && response.Obj != null && response.StatusMessage != ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) { 231 232 // [chn] todo: deserialization into interface is not possible! how to find out correct static type?233 323 restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(response.Obj.SerializedJobData)); 234 324 } … … 236 326 } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped); 237 327 328 log.LogMessage("Job finished (jobId: " + job.Id + ")"); 238 329 // job retrieved... replace the existing optimizers with the finished one 239 IOptimizer originalOptimizer = sentOptimizers[job.Id];330 IOptimizer originalOptimizer = pendingOptimizers[job.Id]; 240 331 IOptimizer restoredOptimizer = ((OptimizerJob)restoredObject).Optimizer; 241 332 242 int originalOptimizerIndex = experiment.Optimizers.IndexOf(originalOptimizer); 243 experiment.Optimizers[originalOptimizerIndex] = restoredOptimizer; 244 sentOptimizers.Remove(job.Id); 245 246 if (sentOptimizers.Count == 0) { 333 ReplaceOptimizer(originalOptimizer, restoredOptimizer); 334 pendingOptimizers.Remove(job.Id); 335 336 if (pendingOptimizers.Count == 0) { 247 337 // finished 248 338 this.ExecutionState = Core.ExecutionState.Stopped; … … 254 344 t.Start(); 255 345 } 256 257 346 258 347 #region Required Plugin Search 259 348 /// <summary> … … 351 440 public event EventHandler ExecutionStateChanged; 352 441 private void OnExecutionStateChanged() { 442 log.LogMessage("ExecutionState changed to " + executionState.ToString()); 353 443 EventHandler handler = ExecutionStateChanged; 354 444 if (handler != null) handler(this, EventArgs.Empty); … … 359 449 public event EventHandler Started; 360 450 private void OnStarted() { 451 log.LogMessage("Started"); 452 timer.Start(); 361 453 EventHandler handler = Started; 362 454 if (handler != null) handler(this, EventArgs.Empty); … … 365 457 public event EventHandler Stopped; 366 458 private void OnStopped() { 459 timer.Stop(); 460 log.LogMessage("Stopped"); 367 461 EventHandler handler = Stopped; 368 462 if (handler != null) handler(this, EventArgs.Empty); … … 371 465 public event EventHandler Paused; 372 466 private void OnPaused() { 467 timer.Stop(); 468 log.LogMessage("Paused"); 373 469 EventHandler handler = Paused; 374 470 if (handler != null) handler(this, EventArgs.Empty); … … 377 473 public event EventHandler Prepared; 378 474 protected virtual void OnPrepared() { 475 log.LogMessage("Prepared"); 379 476 EventHandler handler = Prepared; 380 477 if (handler != null) handler(this, EventArgs.Empty); … … 389 486 public event EventHandler ExperimentChanged; 390 487 protected virtual void OnExperimentChanged() { 488 log.LogMessage("Experiment changed"); 391 489 EventHandler handler = ExperimentChanged; 392 490 if (handler != null) handler(this, EventArgs.Empty); … … 399 497 } 400 498 401 402 499 #endregion 403 500 } -
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/OptimizerJob.cs
r4119 r4120 10 10 namespace HeuristicLab.Hive.Experiment { 11 11 [StorableClass] 12 class OptimizerJob : IJob {12 public class OptimizerJob : IJob { 13 13 14 14 [Storable] -
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/Properties/AssemblyInfo.cs
r4119 r4120 55 55 // You can specify all the values or you can default the Revision and Build Numbers 56 56 // by using the '*' as shown below: 57 [assembly: AssemblyVersion("3.3.0.411 6")]58 [assembly: AssemblyFileVersion("3.3.0.411 6")]59 [assembly: AssemblyBuildDate("2010/07/2 8 17:42:02")]57 [assembly: AssemblyVersion("3.3.0.4119")] 58 [assembly: AssemblyFileVersion("3.3.0.4119")] 59 [assembly: AssemblyBuildDate("2010/07/29 16:49:01")] -
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/ServiceLocator.cs
r4116 r4120 31 31 internal class ServiceLocator { 32 32 internal static IExecutionEngineFacade CreateExecutionEngineFacade(string url) { 33 ChannelFactory<IExecutionEngineFacade> factory = 34 new ChannelFactory<IExecutionEngineFacade>( 33 ChannelFactory<IExecutionEngineFacade> factory = new ChannelFactory<IExecutionEngineFacade>( 35 34 WcfSettings.GetStreamedBinding(), 36 35 new EndpointAddress(url)); 37 38 36 return factory.CreateChannel(); 39 37 }
Note: See TracChangeset
for help on using the changeset viewer.