Changeset 33 for trunk/sources/HeuristicLab.Grid
- Timestamp:
- 03/01/08 15:05:37 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Grid
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Grid/EngineStore.cs
r32 r33 32 32 private Dictionary<Guid, byte[]> waitingEngines; 33 33 private Dictionary<Guid, byte[]> runningEngines; 34 private Dictionary<Guid, ManualResetEvent> waitHandles; 34 35 private Dictionary<Guid, byte[]> results; 35 36 private Dictionary<Guid, string> runningClients; 36 37 private object bigLock; 37 38 private ChannelFactory<IClient> clientChannelFactory; 38 39 private event EventHandler ResultRecieved;40 41 39 public int WaitingJobs { 42 40 get { … … 62 60 runningEngines = new Dictionary<Guid, byte[]>(); 63 61 runningClients = new Dictionary<Guid, string>(); 62 waitHandles = new Dictionary<Guid, ManualResetEvent>(); 64 63 results = new Dictionary<Guid, byte[]>(); 65 64 bigLock = new object(); … … 98 97 runningClients.Remove(guid); 99 98 results[guid] = result; 100 OnResultRecieved(guid);99 waitHandles[guid].Set(); 101 100 } 102 101 } … … 106 105 engineQueue.Enqueue(guid); 107 106 waitingEngines.Add(guid, engine); 107 waitHandles.Add(guid, new ManualResetEvent(false)); 108 108 } 109 109 } … … 118 118 119 119 internal byte[] GetResult(Guid guid) { 120 ManualResetEvent waitHandle = new ManualResetEvent(false); 120 return GetResult(guid, System.Threading.Timeout.Infinite); 121 } 122 internal byte[] GetResult(Guid guid, int timeout) { 121 123 lock(bigLock) { 122 if(results.ContainsKey(guid)) { 123 byte[] result = results[guid]; 124 results.Remove(guid); 125 return result; 124 if(waitHandles.ContainsKey(guid)) { 125 ManualResetEvent waitHandle = waitHandles[guid]; 126 if(waitHandle.WaitOne(timeout, false)) { 127 waitHandle.Close(); 128 waitHandles.Remove(guid); 129 byte[] result = results[guid]; 130 results.Remove(guid); 131 return result; 132 } else { 133 return null; 134 } 126 135 } else { 127 ResultRecieved += delegate(object source, EventArgs args) { 128 ResultRecievedEventArgs resultArgs = (ResultRecievedEventArgs)args; 129 if(resultArgs.resultGuid == guid) { 130 waitHandle.Set(); 131 } 132 }; 136 return null; 133 137 } 134 }135 136 waitHandle.WaitOne();137 waitHandle.Close();138 139 lock(bigLock) {140 byte[] result = results[guid];141 results.Remove(guid);142 return result;143 138 } 144 139 } … … 157 152 } 158 153 } 159 160 private void OnResultRecieved(Guid guid) {161 ResultRecievedEventArgs args = new ResultRecievedEventArgs();162 args.resultGuid = guid;163 if(ResultRecieved != null) {164 ResultRecieved(this, args);165 }166 }167 168 private class ResultRecievedEventArgs : EventArgs {169 public Guid resultGuid;170 }171 154 } 172 155 } -
trunk/sources/HeuristicLab.Grid/GridServer.cs
r32 r33 44 44 return engineStore.GetResult(guid); 45 45 } 46 public byte[] TryEndExecuteEngine(Guid guid, int timeout) { 47 return engineStore.GetResult(guid, timeout); 48 } 46 49 47 50 public void AbortEngine(Guid engine) { -
trunk/sources/HeuristicLab.Grid/IGridServer.cs
r2 r33 30 30 [OperationContract] 31 31 Guid BeginExecuteEngine(byte[] engine); 32 33 32 [OperationContract] 34 33 byte[] EndExecuteEngine(Guid engineGuid); 35 34 [OperationContract] 35 byte[] TryEndExecuteEngine(Guid engineGuid, int timeout); 36 36 [OperationContract] 37 37 void AbortEngine(Guid engineGuid);
Note: See TracChangeset
for help on using the changeset viewer.