BewareMyPower commented on code in PR #24658:
URL: https://github.com/apache/pulsar/pull/24658#discussion_r2297269968
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java:
##########
@@ -419,6 +418,22 @@ public void addOwnedNamespaceBundleAsync(NamespaceBundle
namespaceBundle) {
});
}
+ private CompletableFuture<SystemTopicClient.Reader<PulsarEvent>>
newReader(NamespaceName ns) {
+ return readerCaches.compute(ns, (__, existingFuture) -> {
+ if (existingFuture == null) {
+ return createSystemTopicClient(ns);
+ }
+
+ if (existingFuture.isCompletedExceptionally()) {
+ if (isAlreadyClosedException(existingFuture)) {
+ return existingFuture;
+ }
+ return createSystemTopicClient(ns);
+ }
Review Comment:
A minor suggestion but not by force. When handling a failed future, you
don't have to call `CompletableFuture#get` and handle the
`InterruptedException` or `ExecutionException`.
```java
if (existingFuture.isCompletedExceptionally()) {
return existingFuture.exceptionallyCompose(e -> {
if (isAlreadyClosedException(e)) {
return existingFuture;
} else {
return createSystemTopicClient(ns);
}
});
}
```
Then you won't need a complicated overload of `isAlreadyClosedException`
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]