use of com.tencent.polaris.api.plugin.registry.LocalRegistry in project polaris-java by polarismesh.
the class GetResourcesInvoker method complete.
@Override
public void complete(ServiceEventKey svcEventKey) {
LocalRegistry localRegistry = extensions.getLocalRegistry();
ResourceFilter filter = new ResourceFilter(svcEventKey, internalRequest, useCache);
if (svcEventKey.getEventType() == ServiceEventKey.EventType.INSTANCE) {
ServiceInstances instances = localRegistry.getInstances(filter);
resourcesResponse.addServiceInstances(svcEventKey, instances);
} else if (svcEventKey.getEventType() == EventType.SERVICE) {
Services services = localRegistry.getServices(filter);
resourcesResponse.addServices(svcEventKey, services);
} else {
ServiceRule serviceRule = localRegistry.getServiceRule(filter);
resourcesResponse.addServiceRule(svcEventKey, serviceRule);
}
synchronized (notifier) {
int curTotal = responseIncrement.addAndGet(1);
if (totalCallback == curTotal) {
notifier.notifyAll();
}
}
}
use of com.tencent.polaris.api.plugin.registry.LocalRegistry in project polaris-java by polarismesh.
the class ErrRateCircuitBreaker method stat.
@Override
public boolean stat(InstanceGauge gauge) {
InstanceByProto instance = ChangeStateUtils.getInstance(gauge, localRegistry);
if (null == instance) {
return false;
}
InstanceLocalValue instanceLocalValue = instance.getInstanceLocalValue();
if (null == instanceLocalValue) {
return false;
}
ConfigSet<Config> configSet = CircuitBreakUtils.getConfigSet(gauge, this);
StatusDimension statusDimension = ChangeStateUtils.buildStatusDimension(gauge, configSet.getLevel());
if (CircuitBreakUtils.instanceClose(instance, statusDimension)) {
Object pluginValue = instanceLocalValue.getPluginValue(id, create);
ErrRateCounter errRateCounter = (ErrRateCounter) pluginValue;
SliceWindow metricWindow = errRateCounter.getSliceWindow(statusDimension);
metricWindow.addGauge((bucket -> {
bucket.addMetric(Dimension.keyRequestCount.ordinal(), 1);
if (gauge.getRetStatus() == RetStatus.RetFail) {
return bucket.addMetric(Dimension.keyFailCount.ordinal(), 1);
}
return bucket.getMetric(Dimension.keyFailCount.ordinal());
}));
} else if (CircuitBreakUtils.instanceHalfOpen(instance, statusDimension)) {
// 半开计数器
Object pluginValue = instanceLocalValue.getPluginValue(id, create);
HalfOpenCounter consecutiveCounter = (HalfOpenCounter) pluginValue;
RetStatus retStatus = gauge.getRetStatus();
return consecutiveCounter.triggerHalfOpenConversion(statusDimension, retStatus, configSet.getHalfOpenConfig());
}
return false;
}
use of com.tencent.polaris.api.plugin.registry.LocalRegistry in project polaris-java by polarismesh.
the class GetResourcesInvoker method init.
/**
* 初始化invoker
*
* @param paramProvider
* @return 等待的数量
* @throws PolarisException
*/
private int init(ServiceEventKeysProvider paramProvider) throws PolarisException {
LocalRegistry localRegistry = extensions.getLocalRegistry();
int callbacks = 0;
if (!CollectionUtils.isEmpty(paramProvider.getSvcEventKeys())) {
for (ServiceEventKey svcEventKey : paramProvider.getSvcEventKeys()) {
listeningServices.add(svcEventKey);
callbacks = processSvcEventKey(localRegistry, callbacks, svcEventKey);
}
}
if (null != paramProvider.getSvcEventKey()) {
listeningServices.add(paramProvider.getSvcEventKey());
callbacks = processSvcEventKey(localRegistry, callbacks, paramProvider.getSvcEventKey());
}
return callbacks;
}
Aggregations