use of org.apache.pulsar.client.impl.Backoff in project pulsar by apache.
the class SystemTopicBasedTopicPoliciesService method createSystemTopicClientWithRetry.
protected CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> createSystemTopicClientWithRetry(NamespaceName namespace) {
CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> result = new CompletableFuture<>();
try {
createSystemTopicFactoryIfNeeded();
} catch (PulsarServerException e) {
result.completeExceptionally(e);
return result;
}
SystemTopicClient<PulsarEvent> systemTopicClient = namespaceEventsSystemTopicFactory.createTopicPoliciesSystemTopicClient(namespace);
Backoff backoff = new Backoff(1, TimeUnit.SECONDS, 3, TimeUnit.SECONDS, 10, TimeUnit.SECONDS);
RetryUtil.retryAsynchronously(systemTopicClient::newReaderAsync, backoff, pulsarService.getExecutor(), result);
return result;
}
use of org.apache.pulsar.client.impl.Backoff in project pulsar by yahoo.
the class SystemTopicBasedTopicPoliciesService method createSystemTopicClientWithRetry.
protected CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> createSystemTopicClientWithRetry(NamespaceName namespace) {
CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> result = new CompletableFuture<>();
try {
createSystemTopicFactoryIfNeeded();
} catch (PulsarServerException e) {
result.completeExceptionally(e);
return result;
}
SystemTopicClient<PulsarEvent> systemTopicClient = namespaceEventsSystemTopicFactory.createTopicPoliciesSystemTopicClient(namespace);
Backoff backoff = new Backoff(1, TimeUnit.SECONDS, 3, TimeUnit.SECONDS, 10, TimeUnit.SECONDS);
RetryUtil.retryAsynchronously(systemTopicClient::newReaderAsync, backoff, pulsarService.getExecutor(), result);
return result;
}
use of org.apache.pulsar.client.impl.Backoff in project pulsar by yahoo.
the class TopicPoliciesService method getTopicPoliciesAsyncWithRetry.
/**
* 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
* @param isGlobal is global policies
* @return CompletableFuture<Optional<TopicPolicies>>
*/
default CompletableFuture<Optional<TopicPolicies>> getTopicPoliciesAsyncWithRetry(TopicName topicName, final Backoff backoff, ScheduledExecutorService scheduledExecutorService, boolean isGlobal) {
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(() -> {
CompletableFuture<Optional<TopicPolicies>> future = new CompletableFuture<>();
try {
future.complete(Optional.ofNullable(getTopicPolicies(topicName, isGlobal)));
} catch (BrokerServiceException.TopicPoliciesCacheNotInitException exception) {
future.completeExceptionally(exception);
}
return future;
}, usedBackoff, scheduledExecutorService, response);
} catch (Exception e) {
response.completeExceptionally(e);
}
return response;
}
use of org.apache.pulsar.client.impl.Backoff in project pulsar by yahoo.
the class SystemTopicBasedTopicPoliciesServiceTest method testGetPolicyTimeout.
@Test
public void testGetPolicyTimeout() throws Exception {
SystemTopicBasedTopicPoliciesService service = (SystemTopicBasedTopicPoliciesService) pulsar.getTopicPoliciesService();
Awaitility.await().untilAsserted(() -> assertTrue(service.policyCacheInitMap.get(TOPIC1.getNamespaceObject())));
service.policyCacheInitMap.put(TOPIC1.getNamespaceObject(), false);
long start = System.currentTimeMillis();
Backoff backoff = new BackoffBuilder().setInitialTime(500, TimeUnit.MILLISECONDS).setMandatoryStop(5000, TimeUnit.MILLISECONDS).setMax(1000, TimeUnit.MILLISECONDS).create();
try {
service.getTopicPoliciesAsyncWithRetry(TOPIC1, backoff, pulsar.getExecutor(), false).get();
} catch (Exception e) {
assertTrue(e.getCause() instanceof TopicPoliciesCacheNotInitException);
}
long cost = System.currentTimeMillis() - start;
assertTrue("actual:" + cost, cost >= 5000 - 1000);
}
use of org.apache.pulsar.client.impl.Backoff in project incubator-pulsar by apache.
the class SystemTopicBasedTopicPoliciesService method createSystemTopicClientWithRetry.
protected CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> createSystemTopicClientWithRetry(NamespaceName namespace) {
CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> result = new CompletableFuture<>();
try {
createSystemTopicFactoryIfNeeded();
} catch (PulsarServerException e) {
result.completeExceptionally(e);
return result;
}
SystemTopicClient<PulsarEvent> systemTopicClient = namespaceEventsSystemTopicFactory.createTopicPoliciesSystemTopicClient(namespace);
Backoff backoff = new Backoff(1, TimeUnit.SECONDS, 3, TimeUnit.SECONDS, 10, TimeUnit.SECONDS);
RetryUtil.retryAsynchronously(systemTopicClient::newReaderAsync, backoff, pulsarService.getExecutor(), result);
return result;
}
Aggregations