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

The following examples show how to use com.alipay.sofa.rpc.client.ProviderInfo#getStaticAttr() . 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: ProviderNodeChangeListener.java    From sofa-dashboard with Apache License 2.0 6 votes vote down vote up
private RpcProvider convert2Provider(String serviceName, String providerData) {

        try {
            providerData = URLDecoder.decode(providerData, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        RpcProvider rpcProvider = new RpcProvider();
        ProviderInfo providerInfo = ProviderHelper.toProviderInfo(providerData);

        rpcProvider.setServiceName(serviceName);
        rpcProvider.setAddress(providerInfo.getHost());
        rpcProvider.setPort(providerInfo.getPort());
        String appName = providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_APP_NAME);
        rpcProvider.setAppName(appName);
        rpcProvider.setWeight(providerInfo.getWeight());
        return rpcProvider;
    }
 
Example 2
Source File: ConsumerNodeChangeListener.java    From sofa-dashboard with Apache License 2.0 6 votes vote down vote up
private RpcConsumer convert2Consumer(String serviceName, String providerData) {

        try {
            providerData = URLDecoder.decode(providerData, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        RpcConsumer rpcConsumer = new RpcConsumer();
        ProviderInfo consumerInfo = ProviderHelper.toProviderInfo(providerData);
        String appName = consumerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_APP_NAME);
        rpcConsumer.setAppName(appName);
        rpcConsumer.setServiceName(serviceName);
        rpcConsumer.setAddress(consumerInfo.getHost());
        rpcConsumer.setPort(consumerInfo.getPort());
        return rpcConsumer;
    }
 
Example 3
Source File: DefaultConsumerBootstrap.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribe provider list from direct url
 *
 * @param directUrl direct url of consume config
 * @return Provider group list
 */
protected List<ProviderGroup> subscribeFromDirectUrl(String directUrl) {
    List<ProviderGroup> result = new ArrayList<ProviderGroup>();
    List<ProviderInfo> tmpProviderInfoList = new ArrayList<ProviderInfo>();
    String[] providerStrs = StringUtils.splitWithCommaOrSemicolon(directUrl);
    for (String providerStr : providerStrs) {
        ProviderInfo providerInfo = convertToProviderInfo(providerStr);
        if (providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_SOURCE) == null) {
            providerInfo.setStaticAttr(ProviderInfoAttrs.ATTR_SOURCE, "direct");
        }
        tmpProviderInfoList.add(providerInfo);
    }

    result.add(new ProviderGroup(RpcConstants.ADDRESS_DIRECT_GROUP, tmpProviderInfoList));
    return result;
}
 
Example 4
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 5
Source File: ConsumerInvoker.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public SofaResponse invoke(SofaRequest sofaRequest) throws SofaRpcException {
    // 设置下服务器应用
    ProviderInfo providerInfo = RpcInternalContext.getContext().getProviderInfo();
    String appName = providerInfo.getStaticAttr(ProviderInfoAttrs.ATTR_APP_NAME);
    if (StringUtils.isNotEmpty(appName)) {
        sofaRequest.setTargetAppName(appName);
    }

    // 目前只是通过client发送给服务端
    return consumerBootstrap.getCluster().sendMsg(providerInfo, sofaRequest);
}