版本权重功能的详细设计-中-功能的激活
在配置了版本权重后,还要判断当前调用的服务是否被配置了,因为有可能配置了a和b服务的版本权重,但c服务没配置,当调用c服务时,就没必要激活版本权重功能了 还是直接来到 LinkFlowRoundRobinLoadBalancer#getInstanceResponse 方法
WeightInfoWrapper weightInfoWrapper = linkFlowWeight.parseWeightInfo();
if (linkFlowWeight.isServiceWeight(instances,weightInfoWrapper)) {
ServiceInstance serviceInstance = linkFlowWeight.selectServiceInstance(instances, weightInfoWrapper);
instances.clear();
instances.add(serviceInstance);
}
本章节就是要从 linkFlowWeight.isServiceWeight(instances,weightInfoWrapper) 这里开始进行分析
版本权重的激活
public boolean isServiceWeight(List<ServiceInstance> allServers, WeightInfoWrapper weightInfoWrapper){
for (final ServiceInstance serviceInstance : allServers) {
if (getWeightValue(serviceInstance, weightInfoWrapper) <= 0) {
return false;
}
}
return true;
}
循环服务实例列表,判断如果有个服务实例和配置的版本权重不匹配的话,就直接返回false,不激活版本权重功能