Changeset 1379 for trunk/sources/HeuristicLab.Hive.Client.Core/Core.cs
- Timestamp:
- 03/20/09 13:56:55 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Client.Core/Core.cs
r1371 r1379 50 50 /// The core component of the Hive Client 51 51 /// </summary> 52 public class Core: MarshalByRefObject { 53 //Todo: Ask wagner 54 public static Object Locker { get; set; } 52 public class Core: MarshalByRefObject { 55 53 public static bool abortRequested { get; set; } 56 54 … … 65 63 /// Main Method for the client 66 64 /// </summary> 67 public void Start() { 68 Core.Locker = new Object(); 65 public void Start() { 69 66 abortRequested = false; 70 67 … … 79 76 wcfService = WcfService.Instance; 80 77 wcfService.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(wcfService_LoginCompleted); 81 wcfService.SendJobCompleted += new EventHandler<SendJobCompletedEventArgs>(wcfService_PullJobCompleted); 82 wcfService.ProcessJobResultCompleted += new EventHandler<ProcessJobResultCompletedEventArgs>(wcfService_SendJobResultCompleted); 78 wcfService.SendJobCompleted += new EventHandler<SendJobCompletedEventArgs>(wcfService_SendJobCompleted); 79 wcfService.StoreFinishedJobResultCompleted += new EventHandler<StoreFinishedJobResultCompletedEventArgs>(wcfService_StoreFinishedJobResultCompleted); 80 wcfService.ProcessSnapshotCompleted += new EventHandler<ProcessSnapshotCompletedEventArgs>(wcfService_ProcessSnapshotCompleted); 83 81 wcfService.ConnectionRestored += new EventHandler(wcfService_ConnectionRestored); 84 82 wcfService.ServerChanged += new EventHandler(wcfService_ServerChanged); … … 105 103 DetermineAction(container); 106 104 } 107 } 105 } 108 106 109 107 /// <summary> … … 127 125 //Snapshot is ready and can be sent back to the Server 128 126 case MessageContainer.MessageType.SnapshotReady: 129 ThreadPool.QueueUserWorkItem(new WaitCallback(GetSnapshot), container.JobId); 130 //Thread ssr = new Thread(new ParameterizedThreadStart(GetSnapshot)); 131 //ssr.Start(container.JobId); 127 ThreadPool.QueueUserWorkItem(new WaitCallback(GetSnapshot), container.JobId); 132 128 break; 133 129 //Pull a Job from the Server … … 137 133 //A Job has finished and can be sent back to the server 138 134 case MessageContainer.MessageType.FinishedJob: 139 ThreadPool.QueueUserWorkItem(new WaitCallback(GetFinishedJob), container.JobId); 140 //Thread finThread = new Thread(new ParameterizedThreadStart(GetFinishedJob)); 141 //finThread.Start(container.JobId); 135 ThreadPool.QueueUserWorkItem(new WaitCallback(GetFinishedJob), container.JobId); 142 136 break; 143 137 //Hard shutdown of the client … … 158 152 159 153 if (WcfService.Instance.ConnState == NetworkEnum.WcfConnState.Loggedin) { 160 wcfService. ProcessJobResultAsync(ConfigManager.Instance.GetClientInfo().ClientId,154 wcfService.StoreFinishedJobResultAsync(ConfigManager.Instance.GetClientInfo().ClientId, 161 155 jId, 162 156 sJob, … … 166 160 } else { 167 161 JobStorageManager.PersistObjectToDisc(wcfService.ServerIP, wcfService.ServerPort, jId, sJob); 168 lock ( Core.Locker) {162 lock (engines) { 169 163 AppDomain.Unload(appDomains[jId]); 170 164 appDomains.Remove(jId); … … 182 176 long jId = (long)jobId; 183 177 byte[] obj = engines[jId].GetSnapshot(); 184 wcfService.Process JobResultAsync(ConfigManager.Instance.GetClientInfo().ClientId,178 wcfService.ProcessSnapshotAsync(ConfigManager.Instance.GetClientInfo().ClientId, 185 179 jId, 186 180 obj, … … 202 196 } 203 197 204 void wcfService_ PullJobCompleted(object sender, SendJobCompletedEventArgs e) {198 void wcfService_SendJobCompleted(object sender, SendJobCompletedEventArgs e) { 205 199 if (e.Result.StatusMessage != ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT) { 206 200 bool sandboxed = true; … … 209 203 AppDomain appDomain = PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.Id.ToString(), sandboxed, typeof(TestJob)); 210 204 appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException); 211 lock ( Locker) {205 lock (engines) { 212 206 if (!jobs.ContainsKey(e.Result.Job.Id)) { 213 207 jobs.Add(e.Result.Job.Id, e.Result.Job); … … 228 222 } 229 223 230 //Todo: Seperate this method into 2: Finished jobs and Snapshots 231 void wcfService_S endJobResultCompleted(object sender, ProcessJobResultCompletedEventArgs e) {224 225 void wcfService_StoreFinishedJobResultCompleted(object sender, StoreFinishedJobResultCompletedEventArgs e) { 232 226 if (e.Result.Success) { 233 lock (Locker) {227 lock(engines) { 234 228 //if the engine is running again -> we sent an snapshot. Otherwise the job was finished 235 229 //this method has a risk concerning race conditions. 236 230 //better expand the sendjobresultcompltedeventargs with a boolean "snapshot?" flag 237 if (e.Result.finished == false) { 238 Logging.Instance.Info(this.ToString(), "Snapshot for Job " + e.Result.JobId + " transmitted"); 239 } else { 240 AppDomain.Unload(appDomains[e.Result.JobId]); 241 appDomains.Remove(e.Result.JobId); 242 engines.Remove(e.Result.JobId); 243 jobs.Remove(e.Result.JobId); 244 ClientStatusInfo.JobsProcessed++; 245 Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed); 246 } 231 AppDomain.Unload(appDomains[e.Result.JobId]); 232 appDomains.Remove(e.Result.JobId); 233 engines.Remove(e.Result.JobId); 234 jobs.Remove(e.Result.JobId); 235 ClientStatusInfo.JobsProcessed++; 236 Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed); 247 237 } 248 238 } else { … … 251 241 } 252 242 243 void wcfService_ProcessSnapshotCompleted(object sender, ProcessSnapshotCompletedEventArgs e) { 244 Logging.Instance.Info(this.ToString(), "Snapshot " + e.Result.JobId + " has been transmitted according to plan"); 245 } 246 253 247 //Todo: First stop all threads, then terminate 254 248 void wcfService_ServerChanged(object sender, EventArgs e) { 255 249 Logging.Instance.Info(this.ToString(), "ServerChanged has been called"); 256 lock ( Locker) {250 lock (engines) { 257 251 foreach (KeyValuePair<long, AppDomain> entries in appDomains) 258 252 AppDomain.Unload(appDomains[entries.Key]);
Note: See TracChangeset
for help on using the changeset viewer.