- Timestamp:
- 07/18/12 03:22:03 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationChannel.cs
r7259 r8298 51 51 public abstract void Send(IMessage message); 52 52 53 public abstract IMessage Receive(IBuilder builder );53 public abstract IMessage Receive(IBuilder builder, ExtensionRegistry extensions); 54 54 55 55 public virtual void Close() { -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs
r7259 r8298 111 111 try { 112 112 streamingChannel.Send(message); 113 } 114 catch { 113 } catch { 115 114 Close(); 116 115 throw; … … 118 117 } 119 118 120 public override IMessage Receive(IBuilder builder ) {119 public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) { 121 120 try { 122 return streamingChannel.Receive(builder); 123 } 124 catch { 121 return streamingChannel.Receive(builder, extensions); 122 } catch { 125 123 Close(); 126 124 throw; … … 138 136 process.WaitForExit(1000); 139 137 process.Close(); 140 } 141 catch { } 138 } catch { } 142 139 } 143 140 // for some reasons the event process_Exited does not fire -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
r7259 r8298 21 21 22 22 using System; 23 using System.IO; 24 using Google.ProtocolBuffers; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 73 75 74 76 #region IEvaluationServiceClient Members 75 public QualityMessage Evaluate(SolutionMessage solution ) {77 public QualityMessage Evaluate(SolutionMessage solution, ExtensionRegistry qualityExtensions) { 76 78 int tries = 0, maxTries = RetryParameter.Value.Value; 77 79 bool success = false; … … 82 84 CheckAndOpenChannel(); 83 85 Channel.Send(solution); 84 result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder() );86 result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), qualityExtensions); 85 87 success = true; 86 88 } catch (InvalidOperationException) { … … 91 93 } 92 94 } 95 if (result != null && result.SolutionId != solution.SolutionId) throw new InvalidDataException(Name + ": Received a quality for a different solution."); 93 96 return result; 94 97 } 95 98 96 public void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) {99 public void EvaluateAsync(SolutionMessage solution, ExtensionRegistry qualityExtensions, Action<QualityMessage> callback) { 97 100 int tries = 0, maxTries = RetryParameter.Value.Value; 98 101 bool success = false; … … 110 113 } 111 114 } 112 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback);115 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), new ReceiveAsyncInfo(solution, callback, qualityExtensions)); 113 116 } 114 117 #endregion … … 126 129 } 127 130 128 private void ReceiveAsync(object callback) { 131 private void ReceiveAsync(object callbackInfo) { 132 var info = (ReceiveAsyncInfo)callbackInfo; 129 133 QualityMessage message = null; 130 134 try { 131 message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder() );135 message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), info.QualityExtensions); 132 136 } catch { } 133 ((Action<QualityMessage>)callback).Invoke(message); 137 if (message != null && message.SolutionId != info.SolutionMessage.SolutionId) throw new InvalidDataException(Name + ": Received a quality for a different solution."); 138 info.CallbackDelegate.Invoke(message); 134 139 } 135 140 … … 146 151 } 147 152 #endregion 153 154 private class ReceiveAsyncInfo { 155 public SolutionMessage SolutionMessage { get; set; } 156 public Action<QualityMessage> CallbackDelegate { get; set; } 157 public ExtensionRegistry QualityExtensions { get; set; } 158 public ReceiveAsyncInfo(SolutionMessage solutionMessage, Action<QualityMessage> callbackDelegate, ExtensionRegistry qualityExtensions) { 159 SolutionMessage = solutionMessage; 160 CallbackDelegate = callbackDelegate; 161 QualityExtensions = qualityExtensions; 162 } 163 } 148 164 } 149 165 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationStreamChannel.cs
r7259 r8298 60 60 } 61 61 62 public override IMessage Receive(IBuilder builder ) {62 public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) { 63 63 QualityMessage message; 64 64 lock (input) { // only one thread can read from the stream at one time 65 message = QualityMessage.ParseDelimitedFrom(input );65 message = QualityMessage.ParseDelimitedFrom(input, extensions); 66 66 } 67 67 return message; -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs
r7259 r8298 88 88 #endregion 89 89 90 90 91 91 92 92 #region IExternalEvaluationChannel Members … … 105 105 byte[] buffer = EncodeDelimited(message); 106 106 socket.Send(buffer); 107 } 108 catch (SocketException) { 109 Close(); 110 throw; 111 } 112 catch (ObjectDisposedException) { 107 } catch (SocketException) { 108 Close(); 109 throw; 110 } catch (ObjectDisposedException) { 113 111 socket = null; 114 112 Close(); … … 138 136 } 139 137 140 public override IMessage Receive(IBuilder builder ) {138 public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) { 141 139 try { 142 140 byte[] buffer = GetMessageBuffer(); 143 return builder.WeakMergeFrom(ByteString.CopyFrom(buffer)).WeakBuild(); 144 } 145 catch (SocketException) { 146 Close(); 147 throw; 148 } 149 catch (ObjectDisposedException) { 141 return builder.WeakMergeFrom(ByteString.CopyFrom(buffer), extensions).WeakBuild(); 142 } catch (SocketException) { 143 Close(); 144 throw; 145 } catch (ObjectDisposedException) { 150 146 socket = null; 151 147 Close(); … … 186 182 socket.Disconnect(false); 187 183 socket.Close(); 188 } 189 catch { } 184 } catch { } 190 185 socket = null; 191 186 }
Note: See TracChangeset
for help on using the changeset viewer.