@Override public void operationComplete(ChannelFuture channelFuture) throws Exception { if (!channelFuture.isSuccess()) { channelFuture.channel().close(); if (count.incrementAndGet() < MAX_RETRY) { final EventLoop loop = channelFuture.channel().eventLoop(); loop.schedule(() -> { controller.connectRetry(this.ip, this.port, this); }, 1L, TimeUnit.SECONDS); } else { log.info("Connection to the ovsdb {}:{} failed", this.ip.toString(), this.port.toString()); } } else { handleNewNodeConnection(channelFuture.channel()); } } }
private void connectRetry(IpAddress ip, TpPort port, ChannelFutureListener listener) { try { Bootstrap b = new Bootstrap(); b.group(workerGroup) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) throws Exception { ChannelPipeline p = channel.pipeline(); p.addLast(new MessageDecoder(), new StringEncoder(CharsetUtil.UTF_8), new IdleStateHandler(IDLE_TIMEOUT_SEC, 0, 0), new ConnectionHandler()); } }); b.remoteAddress(ip.toString(), port.toInt()); b.connect().addListener(listener); } catch (Exception e) { log.warn("Connection to the ovsdb server {}:{} failed", ip.toString(), port.toString()); } }