use of org.apache.pulsar.broker.resourcegroup.ResourceGroup in project pulsar by apache.
the class AbstractTopic method updateResourceGroupLimiter.
public void updateResourceGroupLimiter(Optional<Policies> optPolicies) {
Policies policies;
try {
policies = optPolicies.orElseGet(() -> brokerService.pulsar().getPulsarResources().getNamespaceResources().getPoliciesIfCached(TopicName.get(topic).getNamespaceObject()).orElseGet(Policies::new));
} catch (Exception e) {
log.warn("[{}] Error getting policies {} and publish throttling will be disabled", topic, e.getMessage());
policies = new Policies();
}
// attach the resource-group level rate limiters, if set
String rgName = policies.resource_group_name != null ? policies.resource_group_name : null;
if (rgName != null) {
final ResourceGroup resourceGroup = brokerService.getPulsar().getResourceGroupServiceManager().resourceGroupGet(rgName);
if (resourceGroup != null) {
this.resourceGroupRateLimitingEnabled = true;
this.resourceGroupPublishLimiter = resourceGroup.getResourceGroupPublishLimiter();
this.resourceGroupPublishLimiter.registerRateLimitFunction(this.getName(), () -> this.enableCnxAutoRead());
log.info("Using resource group {} rate limiter for topic {}", rgName, topic);
return;
}
} else {
if (this.resourceGroupRateLimitingEnabled) {
this.resourceGroupPublishLimiter.unregisterRateLimitFunction(this.getName());
this.resourceGroupPublishLimiter = null;
this.resourceGroupRateLimitingEnabled = false;
}
/* Namespace detached from resource group. Enable the producer read */
enableProducerReadForPublishRateLimiting();
}
}
use of org.apache.pulsar.broker.resourcegroup.ResourceGroup in project incubator-pulsar by apache.
the class AbstractTopic method updateResourceGroupLimiter.
public void updateResourceGroupLimiter(Optional<Policies> optPolicies) {
Policies policies;
try {
policies = optPolicies.orElseGet(() -> brokerService.pulsar().getPulsarResources().getNamespaceResources().getPoliciesIfCached(TopicName.get(topic).getNamespaceObject()).orElseGet(Policies::new));
} catch (Exception e) {
log.warn("[{}] Error getting policies {} and publish throttling will be disabled", topic, e.getMessage());
policies = new Policies();
}
// attach the resource-group level rate limiters, if set
String rgName = policies.resource_group_name;
if (rgName != null) {
final ResourceGroup resourceGroup = brokerService.getPulsar().getResourceGroupServiceManager().resourceGroupGet(rgName);
if (resourceGroup != null) {
this.resourceGroupRateLimitingEnabled = true;
this.resourceGroupPublishLimiter = resourceGroup.getResourceGroupPublishLimiter();
this.resourceGroupPublishLimiter.registerRateLimitFunction(this.getName(), () -> this.enableCnxAutoRead());
log.info("Using resource group {} rate limiter for topic {}", rgName, topic);
return;
}
} else {
if (this.resourceGroupRateLimitingEnabled) {
this.resourceGroupPublishLimiter.unregisterRateLimitFunction(this.getName());
this.resourceGroupPublishLimiter = null;
this.resourceGroupRateLimitingEnabled = false;
}
/* Namespace detached from resource group. Enable the producer read */
enableProducerReadForPublishRateLimiting();
}
}
use of org.apache.pulsar.broker.resourcegroup.ResourceGroup in project pulsar by yahoo.
the class AbstractTopic method updateResourceGroupLimiter.
public void updateResourceGroupLimiter(Optional<Policies> optPolicies) {
Policies policies;
try {
policies = optPolicies.orElseGet(() -> brokerService.pulsar().getPulsarResources().getNamespaceResources().getPoliciesIfCached(TopicName.get(topic).getNamespaceObject()).orElseGet(Policies::new));
} catch (Exception e) {
log.warn("[{}] Error getting policies {} and publish throttling will be disabled", topic, e.getMessage());
policies = new Policies();
}
// attach the resource-group level rate limiters, if set
String rgName = policies.resource_group_name;
if (rgName != null) {
final ResourceGroup resourceGroup = brokerService.getPulsar().getResourceGroupServiceManager().resourceGroupGet(rgName);
if (resourceGroup != null) {
this.resourceGroupRateLimitingEnabled = true;
this.resourceGroupPublishLimiter = resourceGroup.getResourceGroupPublishLimiter();
this.resourceGroupPublishLimiter.registerRateLimitFunction(this.getName(), () -> this.enableCnxAutoRead());
log.info("Using resource group {} rate limiter for topic {}", rgName, topic);
return;
}
} else {
if (this.resourceGroupRateLimitingEnabled) {
this.resourceGroupPublishLimiter.unregisterRateLimitFunction(this.getName());
this.resourceGroupPublishLimiter = null;
this.resourceGroupRateLimitingEnabled = false;
}
/* Namespace detached from resource group. Enable the producer read */
enableProducerReadForPublishRateLimiting();
}
}
Aggregations