- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/PersistenceSpeedUp/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationProcessChannel.cs
r5445 r6760 33 33 public class EvaluationProcessChannel : EvaluationChannel { 34 34 35 #region Fields & Properties 35 36 private Process process; 36 37 [Storable] … … 40 41 set { 41 42 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; 43 44 executable = value; 44 if (!oldExecutable.Equals(executable)) OnExecutableChanged(); 45 UpdateName(); 46 OnExecutableChanged(); 45 47 } 46 48 } … … 51 53 set { 52 54 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; 54 56 arguments = value; 55 if (!oldArguments.Equals(arguments)) OnArgumentsChanged(); 57 UpdateName(); 58 OnArgumentsChanged(); 56 59 } 57 60 } 58 61 private EvaluationStreamChannel streamingChannel; 62 #endregion 59 63 64 #region Construction & Cloning 60 65 [StorableConstructor] 61 66 protected EvaluationProcessChannel(bool deserializing) : base(deserializing) { } … … 64 69 executable = original.executable; 65 70 arguments = original.arguments; 71 UpdateName(); 66 72 } 67 73 public override IDeepCloneable Clone(Cloner cloner) { … … 74 80 this.executable = executable; 75 81 this.arguments = arguments; 82 UpdateName(); 76 83 } 84 [StorableHook(HookType.AfterDeserialization)] 85 private void AfterDeserialization() { 86 UpdateName(); 87 } 88 #endregion 77 89 78 90 #region IExternalEvaluationChannel Members 79 80 91 public override void Open() { 81 92 if (!String.IsNullOrEmpty(executable.Trim())) { … … 175 186 } 176 187 #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 177 195 } 178 196 } -
branches/PersistenceSpeedUp/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
r5445 r6760 31 31 [StorableClass] 32 32 public class EvaluationServiceClient : ParameterizedNamedItem, IEvaluationServiceClient { 33 33 34 public override bool CanChangeName { get { return false; } } 34 35 public override bool CanChangeDescription { get { return false; } } 35 36 37 #region Parameters 36 38 public IValueParameter<IEvaluationChannel> ChannelParameter { 37 39 get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; } … … 44 46 get { return ChannelParameter.Value; } 45 47 } 48 #endregion 46 49 47 50 51 #region Construction & Cloning 48 52 [StorableConstructor] 49 53 protected EvaluationServiceClient(bool deserializing) : base(deserializing) { } 50 protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) : base(original, cloner) { }51 public override IDeepCloneable Clone(Clonercloner) {52 return new EvaluationServiceClient(this, cloner);54 protected EvaluationServiceClient(EvaluationServiceClient original, Cloner cloner) 55 : base(original, cloner) { 56 RegisterEvents(); 53 57 } 54 58 public EvaluationServiceClient() … … 56 60 Parameters.Add(new ValueParameter<IEvaluationChannel>("Channel", "The channel over which to call the remote function.")); 57 61 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))); 62 RegisterEvents(); 58 63 } 64 public override IDeepCloneable Clone(Cloner cloner) { 65 return new EvaluationServiceClient(this, cloner); 66 } 67 [StorableHook(HookType.AfterDeserialization)] 68 private void AfterDeserialization() { 69 ChannelParameter_ValueChanged(this, EventArgs.Empty); 70 RegisterEvents(); 71 } 72 #endregion 59 73 60 74 #region IEvaluationServiceClient Members 61 62 75 public QualityMessage Evaluate(SolutionMessage solution) { 63 76 int tries = 0, maxTries = RetryParameter.Value.Value; … … 71 84 result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder()); 72 85 success = true; 73 } 74 catch (InvalidOperationException) { 86 } catch (InvalidOperationException) { 75 87 throw; 76 } 77 catch { 88 } catch { 78 89 if (tries >= maxTries) 79 90 throw; … … 92 103 Channel.Send(solution); 93 104 success = true; 94 } 95 catch (InvalidOperationException) { 105 } catch (InvalidOperationException) { 96 106 throw; 97 } 98 catch { 107 } catch { 99 108 if (tries >= maxTries) 100 109 throw; … … 103 112 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback); 104 113 } 105 106 114 #endregion 107 115 116 #region Auxiliary Methods 108 117 private void CheckAndOpenChannel() { 109 118 if (Channel == null) throw new InvalidOperationException(Name + ": The channel is not defined."); … … 111 120 try { 112 121 Channel.Open(); 113 } 114 catch (Exception e) { 122 } catch (Exception e) { 115 123 throw new InvalidOperationException(Name + ": The channel could not be opened.", e); 116 124 } … … 122 130 try { 123 131 message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder()); 124 } 125 catch { } 132 } catch { } 126 133 ((Action<QualityMessage>)callback).Invoke(message); 127 134 } 135 136 private void RegisterEvents() { 137 ChannelParameter.ValueChanged += new EventHandler(ChannelParameter_ValueChanged); 138 } 139 140 void ChannelParameter_ValueChanged(object sender, EventArgs e) { 141 if (ChannelParameter.Value == null) 142 name = "Empty EvaluationServiceClient"; 143 else 144 name = String.Format("{0} ServiceClient", ChannelParameter.Value.Name); 145 OnNameChanged(); 146 } 147 #endregion 128 148 } 129 149 } -
branches/PersistenceSpeedUp/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs
r5445 r6760 32 32 [StorableClass] 33 33 public class EvaluationTCPChannel : EvaluationChannel { 34 34 35 public const int MAX_VARINT32_SIZE = 5; 35 36 37 #region Fields & Properties 36 38 [Storable] 37 39 private string ipAddress; … … 39 41 get { return ipAddress; } 40 42 set { 41 bool changed = !ipAddress.Equals(value);43 if (value == ipAddress) return; 42 44 ipAddress = value; 43 if (changed)44 45 UpdateName(); 46 OnIpAddressChanged(); 45 47 } 46 48 } … … 50 52 get { return port; } 51 53 set { 52 bool changed = port != value;54 if (value == port) return; 53 55 port = value; 54 if (changed)55 56 UpdateName(); 57 OnPortChanged(); 56 58 } 57 59 } 58 60 private Socket socket; 59 61 #endregion 62 63 #region Construction & Cloning 60 64 [StorableConstructor] 61 65 protected EvaluationTCPChannel(bool deserializing) : base(deserializing) { } … … 64 68 ipAddress = original.ipAddress; 65 69 port = original.port; 66 } 70 UpdateName(); 71 } 72 67 73 public override IDeepCloneable Clone(Cloner cloner) { 68 74 return new EvaluationTCPChannel(this, cloner); … … 74 80 this.ipAddress = ip; 75 81 this.port = port; 76 } 82 UpdateName(); 83 } 84 [StorableHook(HookType.AfterDeserialization)] 85 private void AfterDeserialization() { 86 UpdateName(); 87 } 88 #endregion 89 90 77 91 78 92 #region IExternalEvaluationChannel Members … … 183 197 #endregion 184 198 199 #region Auxiliary Methods 200 private void UpdateName() { 201 name = string.Format("TCPChannel {0}:{1}", ipAddress, port); 202 OnNameChanged(); 203 } 204 #endregion 205 185 206 #region Events 186 207 public event EventHandler IpAddressChanged;
Note: See TracChangeset
for help on using the changeset viewer.