@Override public ListTopicsResult listTopics(ListTopicsOptions options) { Map<String, TopicListing> topicListings = new HashMap<>(); if (timeoutNextRequests > 0) { KafkaFutureImpl<Map<String, TopicListing>> future = new KafkaFutureImpl<>(); future.completeExceptionally(new TimeoutException()); --timeoutNextRequests; return new ListTopicsResult(future); } for (Map.Entry<String, TopicMetadata> topicDescription : allTopics.entrySet()) { String topicName = topicDescription.getKey(); topicListings.put(topicName, new TopicListing(topicName, topicDescription.getValue().isInternalTopic)); } KafkaFutureImpl<Map<String, TopicListing>> future = new KafkaFutureImpl<>(); future.complete(topicListings); return new ListTopicsResult(future); }
@Override public ListTopicsResult listTopics(final ListTopicsOptions options) { final KafkaFutureImpl<Map<String, TopicListing>> topicListingFuture = new KafkaFutureImpl<>(); final long now = time.milliseconds(); runnable.call(new Call("listTopics", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) { @Override AbstractRequest.Builder createRequest(int timeoutMs) { return MetadataRequest.Builder.allTopics(); } @Override void handleResponse(AbstractResponse abstractResponse) { MetadataResponse response = (MetadataResponse) abstractResponse; Map<String, TopicListing> topicListing = new HashMap<>(); for (MetadataResponse.TopicMetadata topicMetadata : response.topicMetadata()) { String topicName = topicMetadata.topic(); boolean isInternal = topicMetadata.isInternal(); if (!topicMetadata.isInternal() || options.shouldListInternal()) topicListing.put(topicName, new TopicListing(topicName, isInternal)); } topicListingFuture.complete(topicListing); } @Override void handleFailure(Throwable throwable) { topicListingFuture.completeExceptionally(throwable); } }, now); return new ListTopicsResult(topicListingFuture); }