Source:
public CompletionStage<Iterable<NodeInfo>> refreshNodeList() { if (closeFuture.isDone()) { return CompletableFutures.failedFuture(new IllegalStateException("closed")); } LOG.debug("[{}] Refreshing node list", logPrefix); DriverChannel channel = controlConnection.channel(); EndPoint localEndPoint = channel.getEndPoint(); CompletionStage<AdminResult> localQuery = query(channel, "SELECT * FROM system.local"); CompletionStage<AdminResult> peersV2Query = query(channel, "SELECT * FROM system.peers_v2"); CompletableFuture<AdminResult> peersQuery = new CompletableFuture<>(); peersV2Query.whenComplete( (r, t) -> { if (t != null) { if (t instanceof UnexpectedResponseException && ((UnexpectedResponseException) t).message instanceof Error) { Error error = (Error) ((UnexpectedResponseException) t).message; if (error.code == ProtocolConstants.ErrorCode.INVALID || (error.code == ProtocolConstants.ErrorCode.SERVER_ERROR && error.message.contains("Unknown keyspace/cf pair (system.peers_v2)"))) { this.isSchemaV2 = false; CompletableFutures.completeFrom( query(channel, "SELECT * FROM system.peers"), peersQuery); return; } } peersQuery.completeExceptionally(t); } else { peersQuery.complete(r); } }); return localQuery.thenCombine( peersQuery, (controlNodeResult, peersResult) -> { List<NodeInfo> nodeInfos = new ArrayList<>(); AdminRow localRow = controlNodeResult.iterator().next(); InetSocketAddress localBroadcastRpcAddress = getBroadcastRpcAddress(localRow, localEndPoint); nodeInfos.add(nodeInfoBuilder(localRow, localBroadcastRpcAddress, localEndPoint).build()); for (AdminRow peerRow : peersResult) { if (isPeerValid(peerRow)) { InetSocketAddress peerBroadcastRpcAddress = getBroadcastRpcAddress(peerRow, localEndPoint); if (peerBroadcastRpcAddress != null) { NodeInfo nodeInfo = nodeInfoBuilder(peerRow, peerBroadcastRpcAddress, localEndPoint).build(); nodeInfos.add(nodeInfo); } } } return nodeInfos; }); }

Target:
public CompletionStage<Iterable<NodeInfo>> refreshNodeList() { if (closeFuture.isDone()) { return CompletableFutures.failedFuture(new IllegalStateException("closed")); } LOG.debug("[{}] Refreshing node list", logPrefix); DriverChannel channel = controlConnection.channel(); EndPoint localEndPoint = channel.getEndPoint(); savePort(channel); CompletionStage<AdminResult> localQuery = query(channel, "SELECT * FROM system.local"); CompletionStage<AdminResult> peersV2Query = query(channel, "SELECT * FROM system.peers_v2"); CompletableFuture<AdminResult> peersQuery = new CompletableFuture<>(); peersV2Query.whenComplete( (r, t) -> { if (t != null) { if (t instanceof UnexpectedResponseException && ((UnexpectedResponseException) t).message instanceof Error) { Error error = (Error) ((UnexpectedResponseException) t).message; if (error.code == ProtocolConstants.ErrorCode.INVALID || (error.code == ProtocolConstants.ErrorCode.SERVER_ERROR && error.message.contains("Unknown keyspace/cf pair (system.peers_v2)"))) { this.isSchemaV2 = false; CompletableFutures.completeFrom( query(channel, "SELECT * FROM system.peers"), peersQuery); return; } } peersQuery.completeExceptionally(t); } else { peersQuery.complete(r); } }); return localQuery.thenCombine( peersQuery, (controlNodeResult, peersResult) -> { List<NodeInfo> nodeInfos = new ArrayList<>(); AdminRow localRow = controlNodeResult.iterator().next(); InetSocketAddress localBroadcastRpcAddress = getBroadcastRpcAddress(localRow, localEndPoint); nodeInfos.add(nodeInfoBuilder(localRow, localBroadcastRpcAddress, localEndPoint).build()); for (AdminRow peerRow : peersResult) { if (isPeerValid(peerRow)) { InetSocketAddress peerBroadcastRpcAddress = getBroadcastRpcAddress(peerRow, localEndPoint); if (peerBroadcastRpcAddress != null) { NodeInfo nodeInfo = nodeInfoBuilder(peerRow, peerBroadcastRpcAddress, localEndPoint).build(); nodeInfos.add(nodeInfo); } } } return nodeInfos; }); }