private IRpcClient GetOrAdd(EndPoint endPoint) { try { return(_clients.GetOrAdd(endPoint, ep => { return new Lazy <IRpcClient>(() => { var clientService = new DotNettyClientService(); var bootstrap = _bootstrap; var channel = bootstrap.ConnectAsync(ep).Result; channel.GetAttribute(origEndPointKey).Set(ep); channel.GetAttribute(_clientServiceAttributeKey).Set(clientService); return new DotNettyClient(channel, clientService); }); }).Value); } catch (Exception e) { _clients.TryRemove(endPoint, out var value); var ipEndPoint = endPoint as IPEndPoint; if (ipEndPoint != null) { _healthCheckService.MarkFailure(new IpAddressModel(ipEndPoint.Address.ToString(), ipEndPoint.Port)); } throw new RpcConnectedException("与服务端连接时发生异常。", e); } }
private IRpcClient GetOrAdd(EndPoint endPoint) { try { return(_clients.GetOrAdd(endPoint, ep => { return new Lazy <IRpcClient>(() => { var clientService = new DotNettyClientService(); var bootstrap = _bootstrap; var channel = bootstrap.ConnectAsync(ep).Result; channel.GetAttribute(origEndPointKey).Set(ep); channel.GetAttribute(_clientServiceAttributeKey).Set(clientService); return new DotNettyClient(channel, clientService); }); }).Value); } catch (Exception e) { Console.WriteLine(e); throw; } }