public boolean isReady() { if (authException != null) { log.debug("Metadata is not usable: failed to get metadata.", authException); throw authException; } if (cluster.nodes().isEmpty()) { log.trace("Metadata is not ready: bootstrap nodes have not been " + "initialized yet."); return false; } if (cluster.isBootstrapConfigured()) { log.trace("Metadata is not ready: we have not fetched metadata from " + "the bootstrap nodes yet."); return false; } log.trace("Metadata is ready to use."); return true; }
/** * Receive new metadata, and transition into the QUIESCENT state. * Updates lastMetadataUpdateMs, cluster, and authException. */ public void update(Cluster cluster, long now) { if (cluster.isBootstrapConfigured()) { log.debug("Setting bootstrap cluster metadata {}.", cluster); } else { log.debug("Updating cluster metadata to {}", cluster); this.lastMetadataUpdateMs = now; } this.state = State.QUIESCENT; this.authException = null; if (!cluster.nodes().isEmpty()) { this.cluster = cluster; } } }
@Override public void handleDisconnection(String destination) { Cluster cluster = metadata.fetch(); // 'processDisconnection' generates warnings for misconfigured bootstrap server configuration // resulting in 'Connection Refused' and misconfigured security resulting in authentication failures. // The warning below handles the case where connection to a broker was established, but was disconnected // before metadata could be obtained. if (cluster.isBootstrapConfigured()) { int nodeId = Integer.parseInt(destination); Node node = cluster.nodeById(nodeId); if (node != null) log.warn("Bootstrap broker {} disconnected", node); } metadataFetchInProgress = false; }