Changeset 2588
- Timestamp:
- 01/04/10 22:47:22 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Core/3.2/Core.cs
r2117 r2588 102 102 //Rly?! 103 103 while (!abortRequested) { 104 MessageContainer container = queue.GetMessage(); 105 Debug.WriteLine("Main loop received this message: " + container.Message.ToString()); 106 Logging.Instance.Info(this.ToString(), container.Message.ToString()); 104 MessageContainer container = queue.GetMessage(); 107 105 DetermineAction(container); 108 106 } … … 114 112 /// </summary> 115 113 /// <param name="container">The Container, containing the message</param> 116 private void DetermineAction(MessageContainer container) { 114 private void DetermineAction(MessageContainer container) { 115 Logging.Instance.Info(this.ToString(), "Message: " + container.Message.ToString() + " for job: " + container.JobId); 117 116 switch (container.Message) { 118 117 //Server requests to abort a job 119 case MessageContainer.MessageType.AbortJob: 118 case MessageContainer.MessageType.AbortJob: 120 119 if(engines.ContainsKey(container.JobId)) 121 120 engines[container.JobId].Abort(); … … 127 126 128 127 case MessageContainer.MessageType.JobAborted: 129 //todo: thread this 130 Debug.WriteLine("Job aborted, he's dead"); 128 //todo: thread this 131 129 lock (engines) { 132 130 Guid jobId = new Guid(container.JobId.ToString()); … … 145 143 146 144 //Request a Snapshot from the Execution Engine 147 case MessageContainer.MessageType.RequestSnapshot: 145 case MessageContainer.MessageType.RequestSnapshot: 148 146 if (engines.ContainsKey(container.JobId)) 149 147 engines[container.JobId].RequestSnapshot(); … … 154 152 155 153 //Snapshot is ready and can be sent back to the Server 156 case MessageContainer.MessageType.SnapshotReady: 154 case MessageContainer.MessageType.SnapshotReady: 157 155 ThreadPool.QueueUserWorkItem(new WaitCallback(GetSnapshot), container.JobId); 158 156 break; … … 160 158 161 159 //Pull a Job from the Server 162 case MessageContainer.MessageType.FetchJob: 160 case MessageContainer.MessageType.FetchJob: 163 161 if (!currentlyFetching) { 164 162 wcfService.SendJobAsync(ConfigManager.Instance.GetClientInfo().Id); 165 163 currentlyFetching = true; 166 } 164 } else 165 Logging.Instance.Info(this.ToString(), "Currently fetching, won't fetch this time!"); 167 166 break; 168 167 169 168 170 169 //A Job has finished and can be sent back to the server 171 case MessageContainer.MessageType.FinishedJob: 170 case MessageContainer.MessageType.FinishedJob: 172 171 ThreadPool.QueueUserWorkItem(new WaitCallback(GetFinishedJob), container.JobId); 173 172 break; … … 218 217 /// <param name="jobId"></param> 219 218 private void GetFinishedJob(object jobId) { 220 Guid jId = (Guid)jobId; 219 Guid jId = (Guid)jobId; 220 Logging.Instance.Info(this.ToString(), "Getting the finished job with id: " + jId); 221 221 try { 222 222 if (!engines.ContainsKey(jId)) { … … 228 228 229 229 if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) { 230 Logging.Instance.Info(this.ToString(), "Sending the finished job with id: " + jId); 230 231 wcfService.StoreFinishedJobResultAsync(ConfigManager.Instance.GetClientInfo().Id, 231 232 jId, … … 235 236 true); 236 237 } else { 238 Logging.Instance.Info(this.ToString(), "Storing the finished job with id: " + jId + " to hdd"); 237 239 JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob); 238 240 lock (engines) { … … 251 253 252 254 private void GetSnapshot(object jobId) { 255 Logging.Instance.Info(this.ToString(), "Fetching a snapshot for job " + jobId); 253 256 Guid jId = (Guid)jobId; 254 257 byte[] obj = engines[jId].GetSnapshot(); 258 Logging.Instance.Info(this.ToString(), "BEGIN: Sending snapshot sync"); 255 259 wcfService.ProcessSnapshotSync(ConfigManager.Instance.GetClientInfo().Id, 256 260 jId, … … 258 262 engines[jId].Progress, 259 263 null); 260 264 Logging.Instance.Info(this.ToString(), "END: Sended snapshot sync"); 261 265 //Uptime Limit reached, now is a good time to destroy this jobs. 262 266 if (!UptimeManager.Instance.isOnline()) { … … 267 271 268 272 } else { 273 Logging.Instance.Info(this.ToString(), "Restarting the job" + jobId); 269 274 engines[jId].StartOnlyJob(); 270 275 } … … 294 299 /// <param name="e"></param> 295 300 void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) { 301 Logging.Instance.Info(this.ToString(), "Received new job with id " + e.Result.Job.Id); 296 302 if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) { 297 303 bool sandboxed = false; 298 304 List<byte[]> files = new List<byte[]>(); 305 Logging.Instance.Info(this.ToString(), "Fetching plugins for job " + e.Result.Job.Id); 299 306 foreach (CachedHivePluginInfo plugininfo in PluginCache.Instance.GetPlugins(e.Result.Job.PluginsNeeded)) 300 307 files.AddRange(plugininfo.PluginFiles); 301 308 Logging.Instance.Info(this.ToString(), "Plugins fetched for job " + e.Result.Job.Id); 302 309 AppDomain appDomain = PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.Id.ToString(), sandboxed, null, files); 303 310 appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException); … … 306 313 jobs.Add(e.Result.Job.Id, e.Result.Job); 307 314 appDomains.Add(e.Result.Job.Id, appDomain); 308 315 Logging.Instance.Info(this.ToString(), "Creating AppDomain"); 309 316 Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName); 317 Logging.Instance.Info(this.ToString(), "Created AppDomain"); 310 318 engine.JobId = e.Result.Job.Id; 311 engine.Queue = MessageQueue.GetInstance(); 319 engine.Queue = MessageQueue.GetInstance(); 320 Logging.Instance.Info(this.ToString(), "Starting Engine for job " + e.Result.Job.Id); 312 321 engine.Start(e.Data); 313 322 engines.Add(e.Result.Job.Id, engine); … … 318 327 } 319 328 } 320 } 329 } else 330 Logging.Instance.Info(this.ToString(), "No more jobs left!"); 321 331 currentlyFetching = false; 322 332 } … … 328 338 /// <param name="e"></param> 329 339 void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) { 340 Logging.Instance.Info(this.ToString(), "Job submitted with id " + e.Result.JobId); 330 341 KillAppDomain(e.Result.JobId); 331 342 if (e.Result.Success) { … … 408 419 /// <param name="id">the GUID of the job</param> 409 420 private void KillAppDomain(Guid id) { 421 Logging.Instance.Info(this.ToString(), "Shutting down Appdomain for Job " + id); 410 422 lock (engines) { 411 423 try {
Note: See TracChangeset
for help on using the changeset viewer.