private static void handleNewPassiveConnection(OvsdbClient client) { ListenableFuture<List<String>> echoFuture = client.echo(); LOG.debug("Send echo message to probe the OVSDB switch {}",client.getConnectionInfo()); Futures.addCallback(echoFuture, new FutureCallback<List<String>>() { @Override public void onSuccess(@Nullable List<String> result) { LOG.debug("Probe was successful to OVSDB switch {}",client.getConnectionInfo()); List<OvsdbClient> clientsFromSameNode = getPassiveClientsFromSameNode(client); if (clientsFromSameNode.size() == 0) { notifyListenerForPassiveConnection(client); } else { STALE_PASSIVE_CONNECTION_SERVICE.handleNewPassiveConnection(client, clientsFromSameNode); } } @Override public void onFailure(Throwable failureException) { LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo()); client.disconnect(); } }, connectionNotifierService); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { LOG.debug("Get idle state event"); IdleStateEvent event = (IdleStateEvent) evt; if (event.state() == IdleState.READER_IDLE) { LOG.debug("Reader idle state. Send echo message to peer"); //Send echo message to peer OvsdbClient client = OvsdbConnectionService.getService().getClient(ctx.channel()); client.echo(); } } } }
Futures.addCallback(clientFuture, createStaleConnectionFutureCallback(client, newOvsdbClient, clientFutureMap, echoTimeoutFuture)); Futures.addCallback(client.echo(), createStaleConnectionFutureCallback(client, newOvsdbClient, clientFutureMap, echoTimeoutFuture));