Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/12 03:22:03 (12 years ago)
Author:
abeham
Message:

#1896:

  • Added tags 1000 to max which can be used as extensions to the quality message
  • Updated the evaluator to allow better subclassing in case extensions are used
  • Updated the method signatures to pipe the extension registry down to the channel
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  
    5151    public abstract void Send(IMessage message);
    5252
    53     public abstract IMessage Receive(IBuilder builder);
     53    public abstract IMessage Receive(IBuilder builder, ExtensionRegistry extensions);
    5454
    5555    public virtual void Close() {
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs

    r7259 r8298  
    111111      try {
    112112        streamingChannel.Send(message);
    113       }
    114       catch {
     113      } catch {
    115114        Close();
    116115        throw;
     
    118117    }
    119118
    120     public override IMessage Receive(IBuilder builder) {
     119    public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) {
    121120      try {
    122         return streamingChannel.Receive(builder);
    123       }
    124       catch {
     121        return streamingChannel.Receive(builder, extensions);
     122      } catch {
    125123        Close();
    126124        throw;
     
    138136              process.WaitForExit(1000);
    139137              process.Close();
    140             }
    141             catch { }
     138            } catch { }
    142139          }
    143140          // for some reasons the event process_Exited does not fire
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r7259 r8298  
    2121
    2222using System;
     23using System.IO;
     24using Google.ProtocolBuffers;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    7375
    7476    #region IEvaluationServiceClient Members
    75     public QualityMessage Evaluate(SolutionMessage solution) {
     77    public QualityMessage Evaluate(SolutionMessage solution, ExtensionRegistry qualityExtensions) {
    7678      int tries = 0, maxTries = RetryParameter.Value.Value;
    7779      bool success = false;
     
    8284          CheckAndOpenChannel();
    8385          Channel.Send(solution);
    84           result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder());
     86          result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), qualityExtensions);
    8587          success = true;
    8688        } catch (InvalidOperationException) {
     
    9193        }
    9294      }
     95      if (result != null && result.SolutionId != solution.SolutionId) throw new InvalidDataException(Name + ": Received a quality for a different solution.");
    9396      return result;
    9497    }
    9598
    96     public void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) {
     99    public void EvaluateAsync(SolutionMessage solution, ExtensionRegistry qualityExtensions, Action<QualityMessage> callback) {
    97100      int tries = 0, maxTries = RetryParameter.Value.Value;
    98101      bool success = false;
     
    110113        }
    111114      }
    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));
    113116    }
    114117    #endregion
     
    126129    }
    127130
    128     private void ReceiveAsync(object callback) {
     131    private void ReceiveAsync(object callbackInfo) {
     132      var info = (ReceiveAsyncInfo)callbackInfo;
    129133      QualityMessage message = null;
    130134      try {
    131         message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder());
     135        message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder(), info.QualityExtensions);
    132136      } 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);
    134139    }
    135140
     
    146151    }
    147152    #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    }
    148164  }
    149165}
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationStreamChannel.cs

    r7259 r8298  
    6060    }
    6161
    62     public override IMessage Receive(IBuilder builder) {
     62    public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) {
    6363      QualityMessage message;
    6464      lock (input) { // only one thread can read from the stream at one time
    65         message = QualityMessage.ParseDelimitedFrom(input);
     65        message = QualityMessage.ParseDelimitedFrom(input, extensions);
    6666      }
    6767      return message;
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs

    r7259 r8298  
    8888    #endregion
    8989
    90    
     90
    9191
    9292    #region IExternalEvaluationChannel Members
     
    105105        byte[] buffer = EncodeDelimited(message);
    106106        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) {
    113111        socket = null;
    114112        Close();
     
    138136    }
    139137
    140     public override IMessage Receive(IBuilder builder) {
     138    public override IMessage Receive(IBuilder builder, ExtensionRegistry extensions) {
    141139      try {
    142140        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) {
    150146        socket = null;
    151147        Close();
     
    186182            socket.Disconnect(false);
    187183          socket.Close();
    188         }
    189         catch { }
     184        } catch { }
    190185        socket = null;
    191186      }
Note: See TracChangeset for help on using the changeset viewer.