Java Code Examples for com.alipay.sofa.rpc.config.ProviderConfig#getServer()
The following examples show how to use
com.alipay.sofa.rpc.config.ProviderConfig#getServer() .
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: ConsulRegistry.java From sofa-rpc with Apache License 2.0 | 7 votes |
private List<NewService> buildNewServices(ProviderConfig<?> config) { List<ServerConfig> servers = config.getServer(); if (CommonUtils.isEmpty(servers)) { return Collections.emptyList(); } return servers.stream().map(server -> { NewService service = new NewService(); service.setId(buildServiceId(config, server)); service.setName(buildServiceName(config)); String host = getServerHost(server); int port = server.getPort(); service.setAddress(host); service.setPort(port); Map<String, String> metaData = RegistryUtils.convertProviderToMap(config, server).entrySet().stream() .filter(e -> ConsulUtils.isValidMetaKey(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); service.setMeta(metaData); service.setTags(Collections.singletonList(buildUniqueName(config, server.getProtocol()))); service.setCheck(buildCheck(host, port)); return service; }).collect(Collectors.toList()); }
Example 2
Source File: MockTestRegistry.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public void register(ProviderConfig config) { String key = buildKey(config); ProviderGroup group = memoryCache.get(key); if (group == null) { group = buildProviderGroup(); ProviderGroup old = memoryCache.putIfAbsent(key, group); if (old != null) { group = old; } } List<ServerConfig> serverConfigs = config.getServer(); if (CommonUtils.isNotEmpty(serverConfigs)) { for (ServerConfig server : serverConfigs) { group.add(ProviderHelper.toProviderInfo(convertProviderToUrls(config, server))); } } Map<ConsumerConfig, ProviderInfoListener> listeners = notifyListeners.get(key); if (listeners != null) { for (ProviderInfoListener listener : listeners.values()) { listener.updateProviders(group); } } }
Example 3
Source File: MockTestRegistry.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public void unRegister(ProviderConfig config) { String key = buildKey(config); ProviderGroup group = memoryCache.get(key); if (group != null) { List<ServerConfig> serverConfigs = config.getServer(); if (CommonUtils.isNotEmpty(serverConfigs)) { for (ServerConfig server : serverConfigs) { group.remove(ProviderHelper.toProviderInfo(convertProviderToUrls(config, server))); } } } Map<ConsumerConfig, ProviderInfoListener> listeners = notifyListeners.get(key); if (listeners != null) { for (ProviderInfoListener listener : listeners.values()) { listener.updateProviders(group); } } }
Example 4
Source File: GenerateService.java From sofa-rpc with Apache License 2.0 | 5 votes |
public String generate(String protocol) { if (protocol == null) { protocol = defaultProtocol; } Swagger swagger = new Swagger(); swagger.setInfo(getInfo()); swagger.setBasePath(basePath); Map<Class<?>, Object> interfaceMapRef = new HashMap<>(); List<ProviderBootstrap> providerBootstraps = RpcRuntimeContext.getProviderConfigs(); for (ProviderBootstrap providerBootstrap : providerBootstraps) { ProviderConfig providerConfig = providerBootstrap.getProviderConfig(); List<ServerConfig> server = providerConfig.getServer(); for (ServerConfig serverConfig : server) { if (serverConfig.getProtocol().equals(protocol)) { interfaceMapRef.put(providerConfig.getProxyClass(), providerConfig.getRef()); break; } } } Reader.read(swagger, interfaceMapRef, ""); String result = null; try { result = Json.mapper().writeValueAsString(swagger); } catch (JsonProcessingException e) { e.printStackTrace(); } return result; }
Example 5
Source File: MulticastRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 6
Source File: MulticastRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 7
Source File: ConsulUtils.java From sofa-rpc with Apache License 2.0 | 5 votes |
public static List<String> buildServiceIds(ProviderConfig<?> config) { List<ServerConfig> servers = config.getServer(); if (CommonUtils.isEmpty(servers)) { return Collections.emptyList(); } return servers.stream() .map(server -> buildServiceId(config, server)) .collect(Collectors.toList()); }
Example 8
Source File: LocalRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 9
Source File: LocalRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 10
Source File: SofaRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 11
Source File: SofaRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 12
Source File: NacosRegistryHelper.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Convert provider to instances list. * * @param providerConfig the provider config * @return the list */ static List<Instance> convertProviderToInstances(ProviderConfig providerConfig) { @SuppressWarnings("unchecked") List<ServerConfig> servers = providerConfig.getServer(); if (servers != null && !servers.isEmpty()) { List<Instance> instances = new ArrayList<Instance>(); for (ServerConfig server : servers) { String serviceName = buildServiceName(providerConfig, server.getProtocol()); Instance instance = new Instance(); instance.setClusterName(DEFAULT_CLUSTER); instance.setServiceName(serviceName); // set host port String host = server.getVirtualHost(); if (host == null) { host = server.getHost(); if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) { host = SystemInfo.getLocalHost(); } } instance.setIp(host); instance.setPort(server.getPort()); // set meta data Map<String, String> metaData = RegistryUtils.convertProviderToMap(providerConfig, server); instance.setMetadata(metaData); instances.add(instance); } return instances; } return null; }
Example 13
Source File: MeshRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 14
Source File: MeshRegistry.java From sofa-rpc with Apache License 2.0 | 5 votes |
@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 = MeshRegistryHelper.buildMeshKey(config, server.getProtocol()); ProviderInfo providerInfo = MeshRegistryHelper.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: RegistryUtils.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Convert provider to url. * * @param providerConfig the ProviderConfig * @return the url list */ public static List<String> convertProviderToUrls(ProviderConfig providerConfig) { @SuppressWarnings("unchecked") List<ServerConfig> servers = providerConfig.getServer(); if (servers != null && !servers.isEmpty()) { List<String> urls = new ArrayList<String>(); for (ServerConfig server : servers) { StringBuilder sb = new StringBuilder(200); String host = server.getVirtualHost(); // 虚拟ip if (host == null) { host = server.getHost(); if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) { host = SystemInfo.getLocalHost(); } } Integer port = server.getVirtualPort(); if (port == null) { port = server.getPort(); } Map<String, String> metaData = convertProviderToMap(providerConfig, server); //noinspection unchecked sb.append(server.getProtocol()).append("://").append(host).append(":") .append(port).append(server.getContextPath()).append("?version=1.0") .append(convertMap2Pair(metaData)); urls.add(sb.toString()); } return urls; } return null; }