Changeset 6760 for branches/PersistenceSpeedUp/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 2 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/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 }
Note: See TracChangeset
for help on using the changeset viewer.