use of com.tencent.polaris.client.pojo.InstanceByProto in project polaris-java by polarismesh.
the class ConsecutiveCircuitBreaker 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);
ConsecutiveCounter consecutiveCounter = (ConsecutiveCounter) pluginValue;
RetStatus retStatus = gauge.getRetStatus();
int failCount;
if (retStatus == RetStatus.RetFail) {
failCount = consecutiveCounter.onFail(statusDimension);
} else {
consecutiveCounter.resetCounter(statusDimension);
failCount = 0;
}
return failCount == configSet.getPlugConfig().getContinuousErrorThreshold();
} 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;
}
Aggregations