Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6470


Ignore:
Timestamp:
06/22/11 17:11:27 (12 years ago)
Author:
epitzer
Message:

Automatically generate TCPChannel, ProcessChannel and ServiceClient names form parameters (#1526).

Location:
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3
Files:
4 edited

Legend:

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

    r5445 r6470  
    3333  public class EvaluationProcessChannel : EvaluationChannel {
    3434
     35    #region Fields & Properties
    3536    private Process process;
    3637    [Storable]
     
    4041      set {
    4142        if (IsInitialized) throw new InvalidOperationException(Name + ": Cannot change the executable path as the process has already been started.");
    42         string oldExecutable = executable;
     43        if (value == executable) return;
    4344        executable = value;
    44         if (!oldExecutable.Equals(executable)) OnExecutableChanged();
     45        UpdateName();
     46        OnExecutableChanged();
    4547      }
    4648    }
     
    5153      set {
    5254        if (IsInitialized) throw new InvalidOperationException(Name + ": Cannot change the arguments as the process has already been started.");
    53         string oldArguments = arguments;
     55        if (value == arguments) return;
    5456        arguments = value;
    55         if (!oldArguments.Equals(arguments)) OnArgumentsChanged();
     57        UpdateName();
     58        OnArgumentsChanged();
    5659      }
    5760    }
    5861    private EvaluationStreamChannel streamingChannel;
     62    #endregion
    5963
     64    #region Construction & Cloning
    6065    [StorableConstructor]
    6166    protected EvaluationProcessChannel(bool deserializing) : base(deserializing) { }
     
    6469      executable = original.executable;
    6570      arguments = original.arguments;
     71      UpdateName();
    6672    }
    6773    public override IDeepCloneable Clone(Cloner cloner) {
     
    7480      this.executable = executable;
    7581      this.arguments = arguments;
     82      UpdateName();
    7683    }
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      UpdateName();
     87    }
     88    #endregion
    7789
    7890    #region IExternalEvaluationChannel Members
    79 
    8091    public override void Open() {
    8192      if (!String.IsNullOrEmpty(executable.Trim())) {
     
    175186    }
    176187    #endregion
     188
     189    #region Auxiliary Methods
     190    private void UpdateName() {
     191      name = string.Format("ProcessChannel {0} {1}", Path.GetFileNameWithoutExtension(executable), arguments);
     192      OnNameChanged();
     193    }
     194    #endregion
    177195  }
    178196}
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r5445 r6470  
    3131  [StorableClass]
    3232  public class EvaluationServiceClient : ParameterizedNamedItem, IEvaluationServiceClient {
     33
    3334    public override bool CanChangeName { get { return false; } }
    3435    public override bool CanChangeDescription { get { return false; } }
    3536
     37    #region Parameters
    3638    public IValueParameter<IEvaluationChannel> ChannelParameter {
    3739      get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; }
     
    4446      get { return ChannelParameter.Value; }
    4547    }
     48    #endregion
    4649
    4750
     51    #region Construction & Cloning
    4852    [StorableConstructor]
    4953    protected EvaluationServiceClient(bool deserializing) : base(deserializing) { }
    50     protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) : base(original, cloner) { }
    51     public override IDeepCloneable Clone(Cloner cloner) {
    52       return new EvaluationServiceClient(this, cloner);
    53     }
     54    protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) : base(original, cloner) {
     55      RegisterEvents();
     56    }   
    5457    public EvaluationServiceClient()
    5558      : base() {
    5659      Parameters.Add(new ValueParameter<IEvaluationChannel>("Channel", "The channel over which to call the remote function."));
    5760      Parameters.Add(new ValueParameter<IntValue>("Retry", "How many times the client should retry obtaining a quality in case there is an exception. Note that it immediately aborts when the channel cannot be opened.", new IntValue(10)));
     61      RegisterEvents();
    5862    }
     63    public override IDeepCloneable Clone(Cloner cloner) {
     64      return new EvaluationServiceClient(this, cloner);
     65    }
     66    [StorableHook(HookType.AfterDeserialization)]
     67    private void AfterDeserialization() {
     68      ChannelParameter_ValueChanged(this, EventArgs.Empty);
     69      RegisterEvents();
     70    }
     71    #endregion
    5972
    6073    #region IEvaluationServiceClient Members
    61 
    6274    public QualityMessage Evaluate(SolutionMessage solution) {
    6375      int tries = 0, maxTries = RetryParameter.Value.Value;
     
    103115      System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback);
    104116    }
    105 
    106117    #endregion
    107118
     119    #region Auxiliary Methods
    108120    private void CheckAndOpenChannel() {
    109121      if (Channel == null) throw new InvalidOperationException(Name + ": The channel is not defined.");
     
    126138      ((Action<QualityMessage>)callback).Invoke(message);
    127139    }
     140
     141    private void RegisterEvents() {
     142      ChannelParameter.ValueChanged += new EventHandler(ChannelParameter_ValueChanged);
     143    }
     144
     145    void ChannelParameter_ValueChanged(object sender, EventArgs e) {
     146      if (ChannelParameter.Value == null)
     147        name = "Empty EvaluationServiceClient";
     148      else
     149        name = String.Format("{0} ServiceClient", ChannelParameter.Value.Name);
     150      OnNameChanged();
     151    }
     152    #endregion
    128153  }
    129154}
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs

    r5445 r6470  
    3232  [StorableClass]
    3333  public class EvaluationTCPChannel : EvaluationChannel {
     34
    3435    public const int MAX_VARINT32_SIZE = 5;
    3536
     37    #region Fields & Properties
    3638    [Storable]
    3739    private string ipAddress;
     
    3941      get { return ipAddress; }
    4042      set {
    41         bool changed = !ipAddress.Equals(value);
     43        if (value == ipAddress) return;
    4244        ipAddress = value;
    43         if (changed)
    44           OnIpAddressChanged();
     45        UpdateName();
     46        OnIpAddressChanged();
    4547      }
    4648    }
     
    5052      get { return port; }
    5153      set {
    52         bool changed = port != value;
     54        if (value == port) return;
    5355        port = value;
    54         if (changed)
    55           OnPortChanged();
     56        UpdateName();
     57        OnPortChanged();
    5658      }
    5759    }
    5860    private Socket socket;
    59 
     61    #endregion
     62
     63    #region Construction & Cloning
    6064    [StorableConstructor]
    6165    protected EvaluationTCPChannel(bool deserializing) : base(deserializing) { }
     
    6468      ipAddress = original.ipAddress;
    6569      port = original.port;
    66     }
     70      UpdateName();
     71    }
     72
    6773    public override IDeepCloneable Clone(Cloner cloner) {
    6874      return new EvaluationTCPChannel(this, cloner);
     
    7480      this.ipAddress = ip;
    7581      this.port = port;
    76     }
     82      UpdateName();
     83    }
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      UpdateName();
     87    }
     88    #endregion
     89
     90   
    7791
    7892    #region IExternalEvaluationChannel Members
     
    183197    #endregion
    184198
     199    #region Auxiliary Methods
     200    private void UpdateName() {
     201      name = string.Format("TCPChannel {0}:{1}", ipAddress, port);
     202      OnNameChanged();
     203    }
     204    #endregion
     205
    185206    #region Events
    186207    public event EventHandler IpAddressChanged;
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Interfaces/IEvaluationChannel.cs

    r5445 r6470  
    2424
    2525namespace HeuristicLab.Problems.ExternalEvaluation {
    26   public interface IEvaluationChannel : IItem {
     26  public interface IEvaluationChannel : INamedItem {
    2727    /// <summary>
    2828    /// A flag that describes whether the channel has been initialized or not.
Note: See TracChangeset for help on using the changeset viewer.