Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/30/10 18:58:01 (15 years ago)
Author:
abeham
Message:

#866

  • Updated external evaluation problem
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/ExternalEvaluationStreamDriver.cs

    r3865 r3870  
    3333    public override bool CanChangeDescription { get { return false; } }
    3434
    35     private CodedInputStream inputStream;
    3635    private Stream input;
    37     private CodedOutputStream outputStream;
    3836    private Stream output;
    3937
     
    4240      : base() {
    4341      if (!input.CanRead) throw new ArgumentException("Input stream cannot be read", "input");
    44       this.inputStream = CodedInputStream.CreateInstance(input);
    4542      this.input = input;
    4643      if (!output.CanWrite) throw new ArgumentException("Output stream cannot be written", "output");
    47       this.outputStream = CodedOutputStream.CreateInstance(output);
    4844      this.output = output;
    4945    }
     
    5147    #region Overrides
    5248    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);
    5751      return message;
    5852    }
    5953
    6054    public override void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) {
    61       solution.WriteTo(outputStream);
    62       outputStream.Flush();
    63       output.Flush();
     55      Send(solution);
    6456      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      }
    6564    }
    6665
    6766    public override void Stop() {
    6867      base.Stop();
    69       inputStream = null;
    7068      input.Close();
    71       outputStream = null;
    7269      output.Close();
    7370    }
     
    7673    private void ReceiveAsync(object callback) {
    7774      QualityMessage message;
    78       lock (inputStream) { // only one thread can read from the stream at one time
    79         message = QualityMessage.ParseFrom(inputStream);
     75      lock (input) { // only one thread can read from the stream at one time
     76        message = QualityMessage.ParseDelimitedFrom(input);
    8077      }
    8178      ((Action<QualityMessage>)callback).Invoke(message);
Note: See TracChangeset for help on using the changeset viewer.