Changeset 5137 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs
- Timestamp:
- 12/20/10 19:58:01 (14 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources
- Property svn:ignore
-
old new 1 *.suo 1 2 HeuristicLab.Hive-3.4.suo 2 3 TestResults 3 HeuristicLab.Hive 3.4.suo
-
- Property svn:ignore
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/HeartbeatManager.cs
r5105 r5137 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Diagnostics; 24 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 using HeuristicLab. Clients.Hive.Salve;27 using HeuristicLab.Services.Hive.Common; 27 28 using HeuristicLab.Services.Hive.Common.DataTransfer; 28 using HeuristicLab.Services.Hive.Common;29 using System.Collections.Generic;30 29 31 30 namespace HeuristicLab.Clients.Hive.Salve { … … 49 48 private WcfService wcfService; 50 49 51 private bool abortThreadPending;50 private bool threadStopped; 52 51 53 52 ReaderWriterLockSlim heartBeatThreadIsSleepingLock = new ReaderWriterLockSlim(); 54 53 55 54 /// <summary> 56 55 /// Starts the Heartbeat signal. … … 58 57 public void StartHeartbeat() { 59 58 this.waitHandle = new AutoResetEvent(true); 60 wcfService = WcfService.Instance; 61 abortThreadPending= false;59 wcfService = WcfService.Instance; 60 threadStopped = false; 62 61 heartBeatThread = new Thread(RunHeartBeatThread); 63 62 heartBeatThread.Start(); … … 68 67 /// </summary> 69 68 public void StopHeartBeat() { 70 abortThreadPending= true;69 threadStopped = true; 71 70 waitHandle.Set(); 72 71 heartBeatThread.Join(); 73 72 } 74 73 75 74 /// <summary> 76 75 /// use this method to singalize there is work to do (to avoid the waiting period if its clear that actions are required) 77 76 /// </summary> 78 77 public void AwakeHeartBeatThread() { 79 waitHandle.Set(); 78 if (!threadStopped) 79 waitHandle.Set(); 80 80 } 81 81 82 82 private void RunHeartBeatThread() { 83 while (! abortThreadPending) {83 while (!threadStopped) { 84 84 try { 85 85 lock (locker) { … … 87 87 wcfService.Connect(ConfigManager.Instance.GetClientInfo()); // Login happens automatically upon successfull connection 88 88 } 89 if (wcfService.ConnState == NetworkEnum.WcfConnState.Connected) {89 if (wcfService.ConnState == NetworkEnum.WcfConnState.Connected) { 90 90 HeuristicLab.Services.Hive.Common.DataTransfer.Slave info = ConfigManager.Instance.GetClientInfo(); 91 91 92 Heartbeat heartBeatData = new Heartbeat 93 { 92 Heartbeat heartBeatData = new Heartbeat { 94 93 SlaveId = info.Id, 95 94 FreeCores = info.Cores.HasValue ? info.Cores.Value - ConfigManager.Instance.GetUsedCores() : 0, 96 95 FreeMemory = GetFreeMemory(), 97 JobProgress = ConfigManager.Instance.GetExecutionTimeOfAllJobs() 96 JobProgress = ConfigManager.Instance.GetExecutionTimeOfAllJobs() 98 97 }; 99 98 100 99 Logger.Debug("Sending Heartbeat: " + heartBeatData); 101 List<MessageContainer> msgs = 102 100 List<MessageContainer> msgs = wcfService.SendHeartbeat(heartBeatData); 101 103 102 if (msgs == null) { 104 103 Logger.Debug("Error getting response from Heartbeat"); … … 108 107 Logger.Debug("Heartbeat Response received: "); 109 108 msgs.ForEach(mc => Logger.Debug(mc.Message.ToString())); 110 msgs.ForEach(mc => MessageQueue.GetInstance().AddMessage(mc)); 109 msgs.ForEach(mc => MessageQueue.GetInstance().AddMessage(mc)); 111 110 } 112 } // lock111 } 113 112 } 114 113 catch (Exception e) { … … 117 116 } 118 117 waitHandle.WaitOne(this.Interval); 119 } // while118 } 120 119 waitHandle.Close(); 121 abortThreadPending = false;122 120 Logger.Debug("Heartbeat thread stopped"); 123 121 } 124 122 125 123 126 124 #region Eventhandler
Note: See TracChangeset
for help on using the changeset viewer.