Java Code Examples for com.alipay.sofa.rpc.client.ProviderInfo#setWeight()
The following examples show how to use
com.alipay.sofa.rpc.client.ProviderInfo#setWeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SofaRegistrySubscribeCallback.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * merge url * * @param userDatas * @param configDatas * @return */ List<ProviderInfo> mergeProviderInfo(List<String> userDatas, List<String> configDatas) { // 是否自己缓存运算后的结果?? TODO List<ProviderInfo> providers = SofaRegistryHelper.parseProviderInfos(userDatas); // 交叉比较 if (CommonUtils.isNotEmpty(providers) && CommonUtils.isNotEmpty(configDatas)) { List<ProviderInfo> override = SofaRegistryHelper.parseProviderInfos(configDatas); Iterator<ProviderInfo> iterator = providers.iterator(); while (iterator.hasNext()) { ProviderInfo origin = iterator.next(); for (ProviderInfo over : override) { if (PROTOCOL_TYPE_OVERRIDE.equals(over.getProtocolType()) && StringUtils.equals(origin.getHost(), over.getHost()) && origin.getPort() == over.getPort()) { // host 和 port 相同 认为是一个地址 if (over.getWeight() != origin.getWeight()) { origin.setWeight(over.getWeight()); } if (CommonUtils.isTrue(over.getAttr(ProviderInfoAttrs.ATTR_DISABLED))) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Provider is disabled by override. {}", origin.toUrl()); } iterator.remove(); // 禁用 删掉 } } } } } return providers; }
Example 2
Source File: BaseLoadBalancerTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
protected List<ProviderInfo> buildDiffWeightProviderList(int size) { List<ProviderInfo> aliveConnections = new ArrayList<ProviderInfo>(); for (int i = 0; i < size; i++) { ProviderInfo provider = new ProviderInfo(); provider.setHost("127.0.0.2"); provider.setPort(9000 + i); provider.setWeight(i * 100); // 权重异常乘以100 aliveConnections.add(provider); } return aliveConnections; }
Example 3
Source File: ProviderInfoWeightManager.java From sofa-rpc with Apache License 2.0 | 2 votes |
/** * Recover weight of provider info * * @param providerInfo ProviderInfo * @param weight recovered weight * @return is recover success */ public static boolean recoverWeight(ProviderInfo providerInfo, int weight) { providerInfo.setStatus(ProviderStatus.RECOVERING); providerInfo.setWeight(weight); return true; }
Example 4
Source File: ProviderInfoWeightManager.java From sofa-rpc with Apache License 2.0 | 2 votes |
/** * Degrade weight of provider info * * @param providerInfo ProviderInfo * @param weight degraded weight * @return is degrade success */ public static boolean degradeWeight(ProviderInfo providerInfo, int weight) { providerInfo.setStatus(ProviderStatus.DEGRADED); providerInfo.setWeight(weight); return true; }
Example 5
Source File: ProviderInfoWeightManager.java From sofa-rpc with Apache License 2.0 | 2 votes |
/** * Recover weight of provider info, and set default status * * @param providerInfo ProviderInfo * @param originWeight origin weight */ public static void recoverOriginWeight(ProviderInfo providerInfo, int originWeight) { providerInfo.setStatus(ProviderStatus.AVAILABLE); providerInfo.setWeight(originWeight); }