Java Code Examples for com.alipay.sofa.rpc.client.ProviderInfo#setStatus()

The following examples show how to use com.alipay.sofa.rpc.client.ProviderInfo#setStatus() . 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: RegistryUtils.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * Read the warmUp weight parameter,
 * decide whether to switch the state to the preheating period,
 * and set the corresponding parameters during the preheating period.
 *
 * @param providerInfo the provider info
 */
public static void processWarmUpWeight(ProviderInfo providerInfo) {

    String warmupTimeStr = providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME);
    String warmupWeightStr = providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT);
    String startTimeStr = providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_START_TIME);

    if (StringUtils.isNotBlank(warmupTimeStr) && StringUtils.isNotBlank(warmupWeightStr) &&
        StringUtils.isNotBlank(startTimeStr)) {

        long warmupTime = CommonUtils.parseLong(warmupTimeStr, 0);
        int warmupWeight = CommonUtils.parseInt(warmupWeightStr,
            Integer.parseInt(providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_WEIGHT)));
        long startTime = CommonUtils.parseLong(startTimeStr, 0);
        long warmupEndTime = startTime + warmupTime;

        // set for dynamic
        providerInfo.setDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT, warmupWeight);
        providerInfo.setDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME, warmupEndTime);
        providerInfo.setStatus(ProviderStatus.WARMING_UP);
    }

    // remove from static
    providerInfo.getStaticAttrs().remove(ProviderInfoAttrs.ATTR_WARMUP_TIME);
    providerInfo.getStaticAttrs().remove(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT);

}
 
Example 2
Source File: ProviderInfoWeightManager.java    From sofa-rpc with Apache License 2.0 2 votes vote down vote up
/**
 * 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 3
Source File: ProviderInfoWeightManager.java    From sofa-rpc with Apache License 2.0 2 votes vote down vote up
/**
 * 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 4
Source File: ProviderInfoWeightManager.java    From sofa-rpc with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}