check subscribeRateLimiter.isPresent firstly, to avoid unnecessary operation.
@@ -751,11 +751,12 @@ public class PersistentTopic extends AbstractTopic implements Topic, AddEntryCal
new NamingException("Subscription with reserved subscription name attempted"));
}
- if (cnx.clientAddress() != null && cnx.clientAddress().toString().contains(":")) {
+ if (cnx.clientAddress() != null && cnx.clientAddress().toString().contains(":")
+ && subscribeRateLimiter.isPresent()) {
SubscribeRateLimiter.ConsumerIdentifier consumer = new SubscribeRateLimiter.ConsumerIdentifier(
cnx.clientAddress().toString().split(":")[0], consumerName, consumerId);
- if (subscribeRateLimiter.isPresent() && (!subscribeRateLimiter.get().subscribeAvailable(consumer)
- || !subscribeRateLimiter.get().tryAcquire(consumer))) {
+ if (!subscribeRateLimiter.get().subscribeAvailable(consumer)
+ || !subscribeRateLimiter.get().tryAcquire(consumer)) {
log.warn("[{}] Failed to create subscription for {} {} limited by {}, available {}",
topic, subscriptionName, consumer, subscribeRateLimiter.get().getSubscribeRate(),
subscribeRateLimiter.get().getAvailableSubscribeRateLimit(consumer));
