private IEnumerable <Address> GetPossibleMemberAddresses() { var memberList = _client.GetClientClusterService().GetMemberList(); var addresses = memberList.Select(member => member.GetAddress()).ToList(); if (_shuffleMemberList) { addresses = AddressUtil.Shuffle(addresses); } var configAddresses = _client.GetAddressProvider().GetAddresses(); if (_shuffleMemberList) { configAddresses = AddressUtil.Shuffle(configAddresses); } addresses.AddRange(configAddresses); if (_prevOwnerConnectionAddress != null) { /* * Previous owner address is moved to last item in set so that client will not try to connect to same one immediately. * It could be the case that address is removed because it is healthy(it not responding to heartbeat/pings) * In that case, trying other addresses first to upgrade make more sense. */ addresses.Remove(_prevOwnerConnectionAddress); addresses.Add(_prevOwnerConnectionAddress); } return(addresses); }
private ClientConnection InitializeConnection(Address address, bool isOwner) { CheckLive(); ClientConnection connection = null; var id = _nextConnectionId; var publicAddress = _client.GetAddressProvider().TranslateToPublic(address); try { if (Logger.IsFinestEnabled()) { Logger.Finest("Creating new connection for " + publicAddress + " with id " + id); } connection = new ClientConnection(this, (ClientInvocationService)_client.GetInvocationService(), id, publicAddress, _networkConfig); connection.Init(_socketInterceptor); Authenticate(connection, isOwner); Interlocked.Increment(ref _nextConnectionId); Logger.Finest("Authenticated to " + connection); return(connection); } catch (Exception e) { if (Logger.IsFinestEnabled()) { Logger.Finest("Error connecting to " + publicAddress + " with id " + id, e); } if (connection != null) { connection.Close(); } throw ExceptionUtil.Rethrow(e, typeof(IOException), typeof(SocketException), typeof(TargetDisconnectedException)); } }