You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/08/02 05:15:03 UTC

[GitHub] [pulsar] 315157973 commented on a change in pull request #11518: Make getTopicPoliciesAsyncWithRetry as a default method

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: commits-unsubscribe@pulsar.apache.org

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