kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [kafka] 04/04: Unroll flatMap to avoid spotbugs warning
Date Fri, 10 Jan 2020 01:04:46 GMT
This is an automated email from the ASF dual-hosted git repository.

jgus pushed a commit to branch KAFKA-9261
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit 907b03b717441b4fd3101253d17b4c2cf922bbad
Author: Jason Gustafson <jason@confluent.io>
AuthorDate: Wed Dec 4 11:28:03 2019 -0800

    Unroll flatMap to avoid spotbugs warning
---
 .../src/main/java/org/apache/kafka/clients/Metadata.java    | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/clients/Metadata.java b/clients/src/main/java/org/apache/kafka/clients/Metadata.java
index 59351ee..3da7c2b 100644
--- a/clients/src/main/java/org/apache/kafka/clients/Metadata.java
+++ b/clients/src/main/java/org/apache/kafka/clients/Metadata.java
@@ -212,11 +212,14 @@ public class Metadata implements Closeable {
     }
 
     public synchronized Optional<LeaderAndEpoch> currentLeader(TopicPartition topicPartition)
{
-        return partitionMetadataIfCurrent(topicPartition).flatMap(partitionMetadata ->
{
-            Optional<Integer> leaderEpoch = partitionMetadata.leaderEpoch;
-            Optional<Node> leaderNodeOpt = cache.nodeById(partitionMetadata.leaderId);
-            return leaderNodeOpt.map(leaderNode -> new LeaderAndEpoch(leaderNode, leaderEpoch));
-        });
+        Optional<MetadataResponse.PartitionMetadata> maybeMetadata = partitionMetadataIfCurrent(topicPartition);
+        if (!maybeMetadata.isPresent())
+            return Optional.empty();
+
+        MetadataResponse.PartitionMetadata partitionMetadata = maybeMetadata.get();
+        Optional<Integer> leaderEpoch = partitionMetadata.leaderEpoch;
+        Optional<Node> leaderNodeOpt = cache.nodeById(partitionMetadata.leaderId);
+        return leaderNodeOpt.map(leaderNode -> new LeaderAndEpoch(leaderNode, leaderEpoch));
     }
 
     public synchronized LeaderAndEpoch currentLeaderOrEmpty(TopicPartition tp) {


Mime
View raw message