Use switch instead of chained if/else in OffsetsForLeaderEpochClient
Reviewers: Ismael Juma
@@ -72,31 +72,40 @@ public class OffsetsForLeaderEpochClient extends AsyncClient<
partitionsToRetry.add(topicPartition);
continue;
}
+
Errors error = epochEndOffset.error();
- if (error == Errors.NONE) {
+ switch (error) {
+ case NONE:
logger().debug("Handling OffsetsForLeaderEpoch response for {}. Got offset {} for epoch {}",
topicPartition, epochEndOffset.endOffset(), epochEndOffset.leaderEpoch());
endOffsets.put(topicPartition, epochEndOffset);
- } else if (error == Errors.NOT_LEADER_FOR_PARTITION ||
- error == Errors.REPLICA_NOT_AVAILABLE ||
- error == Errors.KAFKA_STORAGE_ERROR ||
- error == Errors.OFFSET_NOT_AVAILABLE ||
- error == Errors.LEADER_NOT_AVAILABLE) {
+ break;
+ case NOT_LEADER_FOR_PARTITION:
+ case REPLICA_NOT_AVAILABLE:
+ case KAFKA_STORAGE_ERROR:
+ case OFFSET_NOT_AVAILABLE:
+ case LEADER_NOT_AVAILABLE:
logger().debug("Attempt to fetch offsets for partition {} failed due to {}, retrying.",
topicPartition, error);
partitionsToRetry.add(topicPartition);
- } else if (error == Errors.FENCED_LEADER_EPOCH ||
- error == Errors.UNKNOWN_LEADER_EPOCH) {
+ break;
+ case FENCED_LEADER_EPOCH:
+ case UNKNOWN_LEADER_EPOCH:
logger().debug("Attempt to fetch offsets for partition {} failed due to {}, retrying.",
topicPartition, error);
partitionsToRetry.add(topicPartition);
- } else if (error == Errors.UNKNOWN_TOPIC_OR_PARTITION) {
- logger().warn("Received unknown topic or partition error in ListOffset request for partition {}", topicPartition);
+ break;
+ case UNKNOWN_TOPIC_OR_PARTITION:
+ logger().warn("Received unknown topic or partition error in ListOffset request for partition {}",
+ topicPartition);
partitionsToRetry.add(topicPartition);
- } else if (error == Errors.TOPIC_AUTHORIZATION_FAILED) {
+ break;
+ case TOPIC_AUTHORIZATION_FAILED:
unauthorizedTopics.add(topicPartition.topic());
- } else {
- logger().warn("Attempt to fetch offsets for partition {} failed due to: {}, retrying.", topicPartition, error.message());
+ break;
+ default:
+ logger().warn("Attempt to fetch offsets for partition {} failed due to: {}, retrying.",
+ topicPartition, error.message());
partitionsToRetry.add(topicPartition);
}
}
