Java Code Examples for com.alipay.sofa.rpc.config.ProviderConfig#getAppName()

The following examples show how to use com.alipay.sofa.rpc.config.ProviderConfig#getAppName() . 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: ZookeeperRegistry.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }

    //发布
    if (config.isRegister()) {
        registerProviderUrls(config);
    }

    if (config.isSubscribe()) {
        // 订阅配置节点
        if (!INTERFACE_CONFIG_CACHE.containsKey(buildConfigPath(rootPath, config))) {
            //订阅接口级配置
            subscribeConfig(config, config.getConfigListener());
        }
    }
}
 
Example 2
Source File: Curator4ZookeeperRegistry.java    From spring-cloud-sofastack-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_CONFREG_IGNORE));
        }
        return;
    }

    //发布
    if (config.isRegister()) {
        registerProviderUrls(config);
    }

    if (config.isSubscribe()) {
        // 订阅配置节点
        if (!INTERFACE_CONFIG_CACHE.containsKey(buildConfigPath(rootPath, config))) {
            //订阅接口级配置
            subscribeConfig(config, config.getConfigListener());
        }
    }
}
 
Example 3
Source File: LocalRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnRegister(List<ProviderConfig> configs) {
    for (ProviderConfig config : configs) {
        String appName = config.getAppName();
        try {
            unRegister(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unregistry", e);
        }
    }
}
 
Example 4
Source File: MeshRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) { // 注册中心不注册或者服务不注册
        return;
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            String serviceName = MeshRegistryHelper.buildMeshKey(config, server.getProtocol());
            ProviderInfo providerInfo = MeshRegistryHelper.convertProviderToProviderInfo(config, server);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
            }
            doRegister(appName, serviceName, providerInfo, server.getProtocol());

            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
            }
        }
        if (EventBus.isEnable(ProviderPubEvent.class)) {
            ProviderPubEvent event = new ProviderPubEvent(config);
            EventBus.post(event);
        }

    }
}
 
Example 5
Source File: NacosRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnRegister(List<ProviderConfig> configs) {
    for (ProviderConfig config : configs) {
        String appName = config.getAppName();
        try {
            unRegister(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Batch unregister from nacos error", e);
        }
    }
}
 
Example 6
Source File: NacosRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void unRegister(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        // registry ignored
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }

    // unregister publisher
    if (config.isRegister()) {
        try {
            List<Instance> instances = providerInstances.remove(config);
            if (CommonUtils.isNotEmpty(instances)) {
                for (Instance instance : instances) {
                    String serviceName = instance.getServiceName();
                    namingService.deregisterInstance(serviceName, instance.getIp(), instance.getPort(),
                        instance.getClusterName());
                    if (LOGGER.isInfoEnabled(appName)) {
                        LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB,
                            serviceName, instances.size()));
                    }
                }
            }

        } catch (Exception e) {
            if (!RpcRunningState.isShuttingDown()) {
                if (e instanceof SofaRpcRuntimeException) {
                    throw (SofaRpcRuntimeException) e;
                } else {
                    throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNREG_PROVIDER, EXT_NAME), e);
                }
            }
        }
    }

}
 
Example 7
Source File: SofaRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnRegister(List<ProviderConfig> configs) {
    // 不支持批量反注册,那就一个个来吧
    for (ProviderConfig config : configs) {
        String appName = config.getAppName();
        try {
            unRegister(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unregistry", e);
        }
    }
}
 
Example 8
Source File: SofaRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void unRegister(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        // 注册中心不注册
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        // 服务不注册
        return;
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            String serviceName = SofaRegistryHelper.buildListDataId(config, server.getProtocol());
            try {
                String groupId = config.getParameter(SofaRegistryConstants.SOFA_GROUP_KEY);
                groupId = groupId == null ? SofaRegistryHelper.SUBSCRIBER_LIST_GROUP_ID : groupId;
                doUnRegister(appName, serviceName, groupId);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB,
                        serviceName, "1"));
                }
            } catch (Exception e) {
                LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB,
                    serviceName, "0"), e);
            }
        }
    }
}
 
Example 9
Source File: SofaRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        // 注册中心不注册或者服务不注册
        return;
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            String serviceName = SofaRegistryHelper.buildListDataId(config, server.getProtocol());
            String serviceData = SofaRegistryHelper.convertProviderToUrls(config, server);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
            }
            String groupId = config.getParameter(SofaRegistryConstants.SOFA_GROUP_KEY);
            groupId = groupId == null ? SofaRegistryHelper.SUBSCRIBER_LIST_GROUP_ID : groupId;
            doRegister(appName, serviceName, serviceData, groupId);

            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
            }
        }
    }
}
 
Example 10
Source File: LocalRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void unRegister(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) { // 注册中心不注册
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) { // 服务不注册
        return;
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            String serviceName = LocalRegistryHelper.buildListDataId(config, server.getProtocol());
            ProviderInfo providerInfo = LocalRegistryHelper.convertProviderToProviderInfo(config, server);
            try {
                doUnRegister(serviceName, providerInfo);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName,
                        LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "1"));
                }
            } catch (Exception e) {
                LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "0"),
                    e);
            }
        }
    }
}
 
Example 11
Source File: LocalRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) { // 注册中心不注册或者服务不注册
        return;
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            String serviceName = LocalRegistryHelper.buildListDataId(config, server.getProtocol());
            ProviderInfo providerInfo = LocalRegistryHelper.convertProviderToProviderInfo(config, server);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
            }
            doRegister(appName, serviceName, providerInfo);

            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
            }
        }
        if (EventBus.isEnable(ProviderPubEvent.class)) {
            ProviderPubEvent event = new ProviderPubEvent(config);
            EventBus.post(event);
        }

    }
}
 
Example 12
Source File: ConsulRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void unRegister(ProviderConfig config) {
    String appName = config.getAppName();

    if (!registryConfig.isRegister()) {
        // 注册中心不注册
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    // 反注册服务端节点
    if (!config.isRegister()) {
        return;
    }
    try {
        List<String> ids = buildServiceIds(config);
        if (CommonUtils.isNotEmpty(ids)) {
            ids.forEach(this::deregisterConsulService);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB,
                        config.getInterfaceId(), ids.size()));
            }
        }
    } catch (Exception e) {
        if (!RpcRunningState.isShuttingDown()) {
            if ( e instanceof SofaRpcRuntimeException){
                throw e;
            }else{
            throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNREG_PROVIDER ,EXT_NAME), e);
        }}
    }
}
 
Example 13
Source File: MulticastRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnRegister(List<ProviderConfig> configs) {
    for (ProviderConfig config : configs) {
        String appName = config.getAppName();
        try {
            unRegister(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unregistry", e);
        }
    }
}
 
Example 14
Source File: MulticastRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void unRegister(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) { // 注册中心不注册
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (config.isRegister()) { // 服务不注册
        List<ServerConfig> serverConfigs = config.getServer();
        if (CommonUtils.isNotEmpty(serverConfigs)) {
            for (ServerConfig server : serverConfigs) {
                String serviceName = MulticastRegistryHelper.buildListDataId(config, server.getProtocol());
                ProviderInfo providerInfo = MulticastRegistryHelper.convertProviderToProviderInfo(config, server);
                try {
                    doUnRegister(serviceName, providerInfo);
                    if (LOGGER.isInfoEnabled(appName)) {
                        LOGGER.infoWithApp(appName,
                                LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "1"));
                    }
                } catch (Exception e) {
                    LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_UNPUB, serviceName, "0"),
                            e);
                }
            }
        }
    }

}
 
Example 15
Source File: MulticastRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (config.isRegister()) {
        List<ServerConfig> serverConfigs = config.getServer();
        if (CommonUtils.isNotEmpty(serverConfigs)) {
            for (ServerConfig server : serverConfigs) {
                String serviceName = MulticastRegistryHelper.buildListDataId(config, server.getProtocol());
                ProviderInfo providerInfo = MulticastRegistryHelper.convertProviderToProviderInfo(config, server);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
                }
                doRegister(appName, serviceName, providerInfo);

                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
                }
            }
            if (EventBus.isEnable(ProviderPubEvent.class)) {
                ProviderPubEvent event = new ProviderPubEvent(config);
                EventBus.post(event);
            }

        }
    }

}
 
Example 16
Source File: SofaResourceFactory.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public SofaResourceFactory(ProviderConfig providerConfig, Object object) {
    super(object);
    this.providerConfig = providerConfig;
    // 缓存服务名计算和应用名计算
    this.serviceName = ConfigUniqueNameGenerator.getServiceName(providerConfig);
    this.appName = providerConfig.getAppName();
}
 
Example 17
Source File: MeshRegistry.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public void batchUnRegister(List<ProviderConfig> configs) {
    for (ProviderConfig config : configs) {
        String appName = config.getAppName();
        try {
            unRegister(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unregistry", e);
        }
    }
}
 
Example 18
Source File: SofaRegistryHelper.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
/**
 * Convert provider to url.
 *
 * @param providerConfig the ProviderConfig
 * @return the url list
 */
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();
}
 
Example 19
Source File: MockTestRegistry.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
/**
 * Convert provider to url.
 *
 * @param providerConfig the ProviderConfig
 * @return the url list
 */
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());
    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(ATTR_WARMUP_TIME, providerConfig.getParameter(ATTR_WARMUP_TIME.toString())));
    sb.append(getKeyPairs(ATTR_WARMUP_WEIGHT, providerConfig.getParameter(ATTR_WARMUP_WEIGHT.toString())));

    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 = "[clientTimeout" + "#" + methodConfig.getTimeout() + "]";
            sb.append(getKeyPairs(key, value));
        }
    }
    sb.append(getKeyPairs(ATTR_START_TIME, RpcRuntimeContext.now()));
    return sb.toString();
}
 
Example 20
Source File: Curator4ZookeeperRegistry.java    From spring-cloud-sofastack-samples with Apache License 2.0 4 votes vote down vote up
/***
 * 注册 服务信息
 * @param config
 * @return
 * @throws Exception
 */
protected void registerProviderUrls(ProviderConfig config) {
    String appName = config.getAppName();

    // 注册服务端节点
    try {
        // 避免重复计算
        List<String> urls;
        if (providerUrls.containsKey(config)) {
            urls = providerUrls.get(config);
        } else {
            urls = ZookeeperRegistryHelper.convertProviderToUrls(config);
            providerUrls.put(config, urls);
        }
        if (CommonUtils.isNotEmpty(urls)) {

            String providerPath = buildProviderPath(rootPath, config);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName,
                    LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, providerPath));
            }
            for (String url : urls) {
                url = URLEncoder.encode(url, "UTF-8");
                String providerUrl = providerPath + CONTEXT_SEP + url;

                try {
                    getAndCheckZkClient()
                        .create()
                        .creatingParentContainersIfNeeded()
                        .withMode(ephemeralNode ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT)
                        // 是否永久节点
                        .forPath(providerUrl,
                            config.isDynamic() ? PROVIDER_ONLINE : PROVIDER_OFFLINE);
                    if (LOGGER.isInfoEnabled(appName)) {
                        LOGGER.infoWithApp(appName,
                            LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, providerUrl));
                    }
                } catch (KeeperException.NodeExistsException nodeExistsException) {
                    if (LOGGER.isWarnEnabled(appName)) {
                        LOGGER.warnWithApp(appName,
                            "provider has exists in zookeeper, provider=" + providerUrl);
                    }
                }
            }

            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName,
                    LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, providerPath));
            }

        }
    } catch (Throwable t) {
        throw new SofaRpcRuntimeException("Failed to register provider to zookeeperRegistry!",
            t);
    }
}