315157973 commented on a change in pull request #11518:
URL: https://github.com/apache/pulsar/pull/11518#discussion_r680658929



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
##########
@@ -54,6 +61,35 @@
      */
     TopicPolicies getTopicPolicies(TopicName topicName) throws 
TopicPoliciesCacheNotInitException;
 
+    /**
+     * When getting TopicPolicies, if the initialization has not been 
completed,
+     * we will go back off and try again until time out.
+     * @param topicName topic name
+     * @param backoff back off policy
+     * @return CompletableFuture<Optional<TopicPolicies>>
+     */
+    default CompletableFuture<Optional<TopicPolicies>> 
getTopicPoliciesAsyncWithRetry(TopicName topicName,
+              final Backoff backoff, ScheduledExecutorService 
scheduledExecutorService) {
+        CompletableFuture<Optional<TopicPolicies>> response = new 
CompletableFuture<>();
+        Backoff usedBackoff = backoff == null ? new BackoffBuilder()
+                .setInitialTime(500, TimeUnit.MILLISECONDS)
+                .setMandatoryStop(DEFAULT_GET_TOPIC_POLICY_TIMEOUT, 
TimeUnit.MILLISECONDS)
+                .setMax(DEFAULT_GET_TOPIC_POLICY_TIMEOUT, 
TimeUnit.MILLISECONDS)
+                .create() : backoff;
+        try {
+            RetryUtil.retryAsynchronously(() -> {
+                try {
+                    return Optional.ofNullable(getTopicPolicies(topicName));
+                } catch 
(BrokerServiceException.TopicPoliciesCacheNotInitException exception) {
+                    throw new RuntimeException(exception);
+                }
+            }, usedBackoff, scheduledExecutorService, response);
+        } catch (Exception e) {
+            response.completeExceptionally(e);

Review comment:
       Only IllegalArgumentException, NullPointerException, 
RejectedExecutionHandler will appear here, there will be no nested exceptions, 
so getCause is not needed




-- 
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]


Reply via email to