- Timestamp:
- 05/30/10 18:58:01 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/ExternalEvaluationStreamDriver.cs
r3865 r3870 33 33 public override bool CanChangeDescription { get { return false; } } 34 34 35 private CodedInputStream inputStream;36 35 private Stream input; 37 private CodedOutputStream outputStream;38 36 private Stream output; 39 37 … … 42 40 : base() { 43 41 if (!input.CanRead) throw new ArgumentException("Input stream cannot be read", "input"); 44 this.inputStream = CodedInputStream.CreateInstance(input);45 42 this.input = input; 46 43 if (!output.CanWrite) throw new ArgumentException("Output stream cannot be written", "output"); 47 this.outputStream = CodedOutputStream.CreateInstance(output);48 44 this.output = output; 49 45 } … … 51 47 #region Overrides 52 48 public override QualityMessage Evaluate(SolutionMessage solution) { 53 solution.WriteTo(outputStream); 54 outputStream.Flush(); 55 output.Flush(); 56 QualityMessage message = QualityMessage.ParseFrom(inputStream); 49 Send(solution); 50 QualityMessage message = QualityMessage.ParseDelimitedFrom(input); 57 51 return message; 58 52 } 59 53 60 54 public override void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) { 61 solution.WriteTo(outputStream); 62 outputStream.Flush(); 63 output.Flush(); 55 Send(solution); 64 56 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback); 57 } 58 59 private void Send(SolutionMessage solution) { 60 lock (output) { 61 solution.WriteDelimitedTo(output); 62 output.Flush(); 63 } 65 64 } 66 65 67 66 public override void Stop() { 68 67 base.Stop(); 69 inputStream = null;70 68 input.Close(); 71 outputStream = null;72 69 output.Close(); 73 70 } … … 76 73 private void ReceiveAsync(object callback) { 77 74 QualityMessage message; 78 lock (input Stream) { // only one thread can read from the stream at one time79 message = QualityMessage.Parse From(inputStream);75 lock (input) { // only one thread can read from the stream at one time 76 message = QualityMessage.ParseDelimitedFrom(input); 80 77 } 81 78 ((Action<QualityMessage>)callback).Invoke(message);
Note: See TracChangeset
for help on using the changeset viewer.