class SofaRegistryHelper {

    public static String convertProviderToUrls(ProviderConfig providerConfig, ServerConfig server) {
        StringBuilder sb = new StringBuilder(200);
        String appName = providerConfig.getAppName();
        String host = server.getVirtualHost(); // 虚拟ip
        if (host == null) {
            host = server.getHost();
            if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) {
                host = SystemInfo.getLocalHost();
            }
        } else {
            if (LOGGER.isWarnEnabled(appName)) {
                LOGGER.warnWithApp(appName,
                    "Virtual host is specified, host will be change from {} to {} when register",
                    server.getHost(), host);
            }
        }
        Integer port = server.getVirtualPort(); // 虚拟port
        if (port == null) {
            port = server.getPort();
        } else {
            if (LOGGER.isWarnEnabled(appName)) {
                LOGGER.warnWithApp(appName,
                    "Virtual port is specified, host will be change from {} to {} when register",
                    server.getPort(), port);
            }
        }

        String protocol = server.getProtocol();
        sb.append(host).append(":").append(port).append(server.getContextPath());
        //                .append(providerConfig.getInterfaceId())
        sb.append("?").append(ATTR_RPC_VERSION).append("=").append(Version.RPC_VERSION);
        sb.append(getKeyPairs(ATTR_SERIALIZATION, providerConfig.getSerialization()));
        sb.append(getKeyPairs(ATTR_WEIGHT, providerConfig.getWeight()));
        if (providerConfig.getTimeout() > 0) {
            sb.append(getKeyPairs(ATTR_TIMEOUT, providerConfig.getTimeout()));
        }
        sb.append(getKeyPairs(ATTR_APP_NAME, appName));

        //        sb.append(getKeyPairs("delay", providerConfig.getDelay()))
        //                .append(getKeyPairs("timeout", providerConfig.getTimeout()))
        //                .append(getKeyPairs("delay", providerConfig.getDelay()))
        //                .append(getKeyPairs("id", providerConfig.getId()))
        //                .append(getKeyPairs("dynamic", providerConfig.isDynamic()))
        //                .append(getKeyPairs("weight", providerConfig.getWeight()))
        //                .append(getKeyPairs("crossLang", providerConfig.getParameter("crossLang")))
        //                .append(getKeyPairs("accepts", server.getAccepts()));

        // 兼容老系统，代码是否剥离？
        if (PROTOCOL_TYPE_BOLT.equals(protocol)) {
            sb.append(getKeyPairs(RPC_REMOTING_PROTOCOL, RemotingConstants.PROTOCOL_BOLT)); // p=1
        } else if (PROTOCOL_TYPE_TR.equals(protocol)) {
            sb.append(getKeyPairs(RPC_REMOTING_PROTOCOL, RemotingConstants.PROTOCOL_TR));// p=13
        }
        sb.append(getKeyPairs(RPC_SERVICE_VERSION, SOFA4_RPC_SERVICE_VERSION)); // v=4.0
        sb.append(getKeyPairs(SERIALIZE_TYPE_KEY, providerConfig.getSerialization())); // _SERIALIZETYPE=xx
        sb.append(getKeyPairs(WEIGHT_KEY, providerConfig.getWeight())); // _WEIGHT=100
        if (providerConfig.getTimeout() > 0) {
            sb.append(getKeyPairs(TIMEOUT, providerConfig.getTimeout())); // _TIMEOUT=3000
        }
        sb.append(getKeyPairs(APP_NAME, appName));
        // sb.append(getKeyPairs(SELF_APP_NAME, appName)); //TODO self_app_name
        // sb.append(getKeyPairs(IDLE_TIMEOUT, 27)); //TODO _IDLETIMEOUT
        // sb.append(getKeyPairs(MAX_READ_IDLE, 30)); //TODO _MAXREADIDLETIME

        if (StringUtils.isNotBlank(SystemInfo.getHostMachine())) {
            sb.append(getKeyPairs(HOST_MACHINE_KEY, SystemInfo.getHostMachine()));
        }

        Map<String, MethodConfig> methodConfigs = providerConfig.getMethods();
        if (CommonUtils.isNotEmpty(methodConfigs)) {
            for (Map.Entry<String, MethodConfig> entry : methodConfigs.entrySet()) {
                String methodName = entry.getKey();
                MethodConfig methodConfig = entry.getValue();
                sb.append(getKeyPairs("." + methodName + "." + ATTR_TIMEOUT, methodConfig.getTimeout()));

                // 方法级配置，只能放timeout 
                String key = "[" + methodName + "]";
                String value = "[" + KEY_TIMEOUT + "#" + methodConfig.getTimeout() + "]";
                sb.append(getKeyPairs(key, value));
            }
        }
        sb.append(convertMap2Pair(providerConfig.getParameters()));
        addCommonAttrs(sb);
        return sb.toString();
    }

}