Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/10 15:06:03 (14 years ago)
Author:
abeham
Message:

#866

  • Improved exception handling and added default client
Location:
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers
Files:
3 edited

Legend:

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

    r3872 r3895  
    9494
    9595    public override void Send(IMessage message) {
    96       streamingChannel.Send(message);
     96      try {
     97        streamingChannel.Send(message);
     98      } catch {
     99        Close();
     100        throw;
     101      }
    97102    }
    98103
    99104    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      }
    101111    }
    102112
     
    107117          streamingChannel.Close();
    108118          if (!process.HasExited) {
    109             process.CloseMainWindow();
    110             process.WaitForExit(1000);
    111             process.Close();
    112             // for some reasons the event process_Exited does not fire
    113             OnProcessExited();
     119            try {
     120              process.CloseMainWindow();
     121              process.WaitForExit(1000);
     122              process.Close();
     123            } catch { }
    114124          }
     125          // for some reasons the event process_Exited does not fire
     126          OnProcessExited();
    115127        }
    116128        process = null;
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationServiceClient.cs

    r3872 r3895  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828using HeuristicLab.Parameters;
     29using HeuristicLab.Data;
    2930
    3031namespace HeuristicLab.Problems.ExternalEvaluation {
     
    3839      get { return (IValueParameter<IEvaluationChannel>)Parameters["Channel"]; }
    3940    }
     41    public IValueParameter<IntValue> RetryParameter {
     42      get { return (IValueParameter<IntValue>)Parameters["Retry"]; }
     43    }
    4044
    4145    private IEvaluationChannel Channel {
     
    4650      : base() {
    4751      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)));
    4853    }
    4954
     
    5156   
    5257    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;
    5676    }
    5777
    5878    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      }
    6194      System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ReceiveAsync), callback);
    6295    }
     
    69102        try {
    70103          Channel.Open();
    71         } catch (Exception e) { // TODO: Change to specific exception
     104        } catch (Exception e) {
    72105          throw new InvalidOperationException(Name + ": The channel could not be opened.", e);
    73106        }
     
    76109
    77110    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 { }
    79115      ((Action<QualityMessage>)callback).Invoke(message);
    80116    }
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/Drivers/EvaluationTCPChannel.cs

    r3893 r3895  
    8989      } catch (SocketException) {
    9090        Close();
     91        throw;
    9192      } catch (ObjectDisposedException) {
    9293        socket = null;
    9394        Close();
     95        throw;
    9496      }
    9597    }
     
    122124      } catch (SocketException) {
    123125        Close();
     126        throw;
    124127      } catch (ObjectDisposedException) {
    125128        socket = null;
    126129        Close();
     130        throw;
    127131      }
    128       return null;
    129132    }
    130133
     
    157160    public override void Close() {
    158161      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 { }
    162167        socket = null;
    163168      }
Note: See TracChangeset for help on using the changeset viewer.