dajac commented on a change in pull request #8311:
URL: https://github.com/apache/kafka/pull/8311#discussion_r420664331



##########
File path: 
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java
##########
@@ -1402,6 +1407,15 @@ int numPendingCalls() {
         return runnable.pendingCalls.size();
     }
 
+    /**
+     * Fail the given future when a response handler expected a result for an 
entity but no result was present.
+     * @param future The future to fail.
+     * @param message The message to fail the future with
+     */
+    private void partialResponse(KafkaFutureImpl<?> future, String message) {

Review comment:
       I see your point. I am definitely for reusing logic as much as possible 
for those cases. What about going an extra step and do something like this then 
(code not tested)? Just an idea...
   
   ```
   public static <K, V> void completeUnrealizedFutures(
               Map<K, KafkaFutureImpl<V>> futures,
               Function<K, Boolean> filter,
               Function<K, String> messageFormatter) {
           for (Map.Entry<K, KafkaFutureImpl<V>> entry : futures.entrySet()) {
               K key = entry.getKey();
               KafkaFutureImpl<V> future = entry.getValue();
               if (!future.isDone() && filter.apply(key)) {
                   future.completeExceptionally(new 
ApiException(messageFormatter.apply(key)));
               }
           }
       }
   
       public static  <K, V> void completeUnrealizedFutures(
               Map<K, KafkaFutureImpl<V>> futures,
               unction<K, String> messageFormatter) {
           completeUnrealizedFutures(futures, (key) -> true, messageFormatter);
       }
   ```
   
   It would allow the following:
   
   ```
   completeUnrealizedFutures(topicFutures,
        replica -> replica.brokerId() == brokerId,
        topic -> "The response from broker " + brokerId + " did not contain a 
result for replica " + replica);
   
   completeUnrealizedFutures(topicFutures,
        topic -> "The server response did not contain a reference to node " + 
topic);
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to