Changeset 3895 for trunk/sources
- Timestamp:
- 06/04/10 15:06:03 (14 years ago)
- 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
r3872 r3895 94 94 95 95 public override void Send(IMessage message) { 96 streamingChannel.Send(message); 96 try { 97 streamingChannel.Send(message); 98 } catch { 99 Close(); 100 throw; 101 } 97 102 } 98 103 99 104 public override IMessage Receive(IBuilder builder) { 100 return streamingChannel.Receive(builder); 105 try { 106 return streamingChannel.Receive(builder); 107 } catch { 108 Close(); 109 throw; 110 } 101 111 } 102 112 … … 107 117 streamingChannel.Close(); 108 118 if (!process.HasExited) { 109 process.CloseMainWindow();110 process.WaitForExit(1000);111 process.Close();112 // for some reasons the event process_Exited does not fire113 OnProcessExited();119 try { 120 process.CloseMainWindow(); 121 process.WaitForExit(1000); 122 process.Close(); 123 } catch { } 114 124 } 125 // for some reasons the event process_Exited does not fire 126 OnProcessExited(); 115 127 } 116 128 process = null; -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs
r3872 r3895 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Data; 29 30 30 31 namespace HeuristicLab.Problems.ExternalEvaluation { … … 38 39 get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; } 39 40 } 41 public IValueParameter<IntValue> RetryParameter { 42 get { return (IValueParameter<IntValue>)Parameters["Retry"]; } 43 } 40 44 41 45 private IEvaluationChannel Channel { … … 46 50 : base() { 47 51 Parameters.Add(new ValueParameter<IEvaluationChannel>("Channel", "The channel over which to call the remote function.")); 52 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))); 48 53 } 49 54 … … 51 56 52 57 public QualityMessage Evaluate(SolutionMessage solution) { 53 CheckAndOpenChannel(); 54 Channel.Send(solution); 55 return (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder()); 58 int tries = 0, maxTries = RetryParameter.Value.Value; 59 bool success = false; 60 QualityMessage result = null; 61 while (!success) { 62 try { 63 tries++; 64 CheckAndOpenChannel(); 65 Channel.Send(solution); 66 result = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder()); 67 success = true; 68 } catch (InvalidOperationException) { 69 throw; 70 } catch { 71 if (tries >= maxTries) 72 throw; 73 } 74 } 75 return result; 56 76 } 57 77 58 78 public void EvaluateAsync(SolutionMessage solution, Action<QualityMessage> callback) { 59 CheckAndOpenChannel(); 60 Channel.Send(solution); 79 int tries = 0, maxTries = RetryParameter.Value.Value; 80 bool success = false; 81 while (!success) { 82 try { 83 tries++; 84 CheckAndOpenChannel(); 85 Channel.Send(solution); 86 success = true; 87 } catch (InvalidOperationException) { 88 throw; 89 } catch { 90 if (tries >= maxTries) 91 throw; 92 } 93 } 61 94 System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback); 62 95 } … … 69 102 try { 70 103 Channel.Open(); 71 } catch (Exception e) { // TODO: Change to specific exception104 } catch (Exception e) { 72 105 throw new InvalidOperationException(Name + ": The channel could not be opened.", e); 73 106 } … … 76 109 77 110 private void ReceiveAsync(object callback) { 78 QualityMessage message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder()); 111 QualityMessage message = null; 112 try { 113 message = (QualityMessage)Channel.Receive(QualityMessage.CreateBuilder()); 114 } catch { } 79 115 ((Action<QualityMessage>)callback).Invoke(message); 80 116 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs
r3893 r3895 89 89 } catch (SocketException) { 90 90 Close(); 91 throw; 91 92 } catch (ObjectDisposedException) { 92 93 socket = null; 93 94 Close(); 95 throw; 94 96 } 95 97 } … … 122 124 } catch (SocketException) { 123 125 Close(); 126 throw; 124 127 } catch (ObjectDisposedException) { 125 128 socket = null; 126 129 Close(); 130 throw; 127 131 } 128 return null;129 132 } 130 133 … … 157 160 public override void Close() { 158 161 if (socket != null) { 159 if (socket.Connected) 160 socket.Disconnect(false); 161 socket.Close(); 162 try { 163 if (socket.Connected) 164 socket.Disconnect(false); 165 socket.Close(); 166 } catch { } 162 167 socket = null; 163 168 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/ExternalEvaluationProblem.cs
r3872 r3895 126 126 UserDefinedSolutionCreator solutionCreator = new UserDefinedSolutionCreator(); 127 127 128 Parameters.Add(new ValueParameter<IEvaluationServiceClient>("Client", "The client that is used to communicate with the external application." ));128 Parameters.Add(new ValueParameter<IEvaluationServiceClient>("Client", "The client that is used to communicate with the external application.", new EvaluationServiceClient())); 129 129 Parameters.Add(new ValueParameter<IExternalEvaluationProblemEvaluator>("Evaluator", "The evaluator that collects the values to exchange.", evaluator)); 130 130 Parameters.Add(new ValueParameter<ISolutionCreator>("SolutionCreator", "An operator to create the solution components.", solutionCreator));
Note: See TracChangeset
for help on using the changeset viewer.