Source:
private Channel getNextChannel(InetSocketAddress remoteServer) { Channel channel = addressChannelMap.get(remoteServer).nextChannel(); if (channel == null) { LOG.warn("getNextChannel: No channel exists for " + remoteServer); } if (channel != null) { if (channel.isActive()) { return channel; } if (addressChannelMap.get(remoteServer).removeChannel(channel)) { LOG.warn("getNextChannel: Unlikely event that the channel " + channel + " was already removed!"); } if (LOG.isInfoEnabled()) { LOG.info("getNextChannel: Fixing disconnected channel to " + remoteServer + ", open = " + channel.isOpen() + ", " + "bound = " + channel.isRegistered()); } } int reconnectFailures = 0; while (reconnectFailures < maxConnectionFailures) { ChannelFuture connectionFuture = bootstrap.connect(remoteServer); try { ProgressableUtils.awaitChannelFuture(connectionFuture, context); } catch (BlockingOperationException e) { LOG.warn("getNextChannel: Failed connecting to " + remoteServer, e); } if (connectionFuture.isSuccess()) { if (LOG.isInfoEnabled()) { LOG.info("getNextChannel: Connected to " + remoteServer + "!"); } addressChannelMap.get(remoteServer).addChannel( connectionFuture.channel()); return connectionFuture.channel(); } ++reconnectFailures; LOG.warn("getNextChannel: Failed to reconnect to " + remoteServer + " on attempt " + reconnectFailures + " out of " + maxConnectionFailures + " max attempts, sleeping for 5 secs", connectionFuture.cause()); ThreadUtils.trySleep(5000); } throw new IllegalStateException("getNextChannel: Failed to connect " + "to " + remoteServer + " in " + reconnectFailures + " connect attempts"); }

Target:
private Channel getNextChannel(InetSocketAddress remoteServer) { Channel channel = addressChannelMap.get(remoteServer).nextChannel(); if (channel == null) { LOG.warn("getNextChannel: No channel exists for " + remoteServer); } else { if (channel.isActive()) { return channel; } if (addressChannelMap.get(remoteServer).removeChannel(channel)) { LOG.warn("getNextChannel: Unlikely event that the channel " + channel + " was already removed!"); } if (LOG.isInfoEnabled()) { LOG.info("getNextChannel: Fixing disconnected channel to " + remoteServer + ", open = " + channel.isOpen() + ", " + "bound = " + channel.isRegistered()); } } while (reconnectFailures < maxConnectionFailures) { ChannelFuture connectionFuture = bootstrap.connect(remoteServer); try { ProgressableUtils.awaitChannelFuture(connectionFuture, context); } catch (BlockingOperationException e) { LOG.warn("getNextChannel: Failed connecting to " + remoteServer, e); } if (connectionFuture.isSuccess()) { if (LOG.isInfoEnabled()) { LOG.info("getNextChannel: Connected to " + remoteServer + "!"); } addressChannelMap.get(remoteServer).addChannel( connectionFuture.channel()); return connectionFuture.channel(); } ++reconnectFailures; LOG.warn("getNextChannel: Failed to reconnect to " + remoteServer + " on attempt " + reconnectFailures + " out of " + maxConnectionFailures + " max attempts, sleeping for 5 secs", connectionFuture.cause()); ThreadUtils.trySleep(5000); } throw new IllegalStateException("getNextChannel: Failed to connect " + "to " + remoteServer + " in " + reconnectFailures + " connect attempts"); }