We really should not be catching Exceptions here and once connect()
returns we should be completely asynchronous. Reduce the amount of
code protected by the try/catch block.
Change-Id: I673cc4f0a52cefd2659a5db5a96417e00fd89422
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
LOG.debug("Promise {} attempting connect for {}ms", this, timeout);
LOG.debug("Promise {} attempting connect for {}ms", this, timeout);
+ final ChannelFuture connectFuture;
try {
if (address.isUnresolved()) {
address = new InetSocketAddress(address.getHostName(), address.getPort());
}
try {
if (address.isUnresolved()) {
address = new InetSocketAddress(address.getHostName(), address.getPort());
}
- final ChannelFuture connectFuture = bootstrap.connect(address);
- pending = connectFuture;
- // Add listener that attempts reconnect by invoking this method again.
- connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);
+ connectFuture = bootstrap.connect(address);
} catch (final Exception e) {
LOG.info("Failed to connect to {}", address, e);
setFailure(e);
} catch (final Exception e) {
LOG.info("Failed to connect to {}", address, e);
setFailure(e);
+
+ pending = connectFuture;
+ // Add listener that attempts reconnect by invoking this method again.
+ connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);