com.alipay.sofa.rpc.registry.zk.ZookeeperRegistryHelper类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中com.alipay.sofa.rpc.registry.zk.ZookeeperRegistryHelper类的一些代码示例,展示了ZookeeperRegistryHelper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZookeeperRegistryHelper类的具体详情如下:
包路径:com.alipay.sofa.rpc.registry.zk.ZookeeperRegistryHelper
类名称:ZookeeperRegistryHelper

ZookeeperRegistryHelper介绍

[英]Helper for ZookeeperRegistry
[中]ZookeeperRegistry助手

代码示例

代码示例来源:origin: alipay/sofa-rpc

/***
 * 订阅
 * @param config
 */
protected void subscribeConsumerUrls(ConsumerConfig config) {
  // 注册Consumer节点
  String url = null;
  if (config.isRegister()) {
    try {
      String consumerPath = buildConsumerPath(rootPath, config);
      if (consumerUrls.containsKey(config)) {
        url = consumerUrls.get(config);
      } else {
        url = ZookeeperRegistryHelper.convertConsumerToUrl(config);
        consumerUrls.put(config, url);
      }
      String encodeUrl = URLEncoder.encode(url, "UTF-8");
      getAndCheckZkClient().create().creatingParentContainersIfNeeded()
        .withMode(CreateMode.EPHEMERAL) // Consumer临时节点
        .forPath(consumerPath + CONTEXT_SEP + encodeUrl);
    } catch (KeeperException.NodeExistsException nodeExistsException) {
      if (LOGGER.isWarnEnabled()) {
        LOGGER.warn("consumer has exists in zookeeper, consumer=" + url);
      }
    } catch (Exception e) {
      throw new SofaRpcRuntimeException("Failed to register consumer to zookeeperRegistry!", e);
    }
  }
}

代码示例来源:origin: alipay/sofa-rpc

/**
 * Convert child data to attribute list.
 *
 * @param configPath  the config path
 * @param currentData the current data
 * @return the attribute list
 */
static List<Map<String, String>> convertConfigToAttributes(String configPath,
                              List<ChildData> currentData) {
  List<Map<String, String>> attributes = new ArrayList<Map<String, String>>();
  if (CommonUtils.isEmpty(currentData)) {
    return attributes;
  }
  for (ChildData childData : currentData) {
    attributes.add(convertConfigToAttribute(configPath, childData, false));
  }
  return attributes;
}

代码示例来源:origin: alipay/sofa-rpc

private void notifyListeners(AbstractInterfaceConfig config, String overridePath, ChildData data,
                 boolean removeType, AbstractInterfaceConfig interfaceConfig)
    throws Exception {
    List<ConfigListener> configListeners = configListenerMap.get(config);
    if (CommonUtils.isNotEmpty(configListeners)) {
      //转换子节点Data为IP级配置<配置属性名,配置属性值>,例如<timeout,200>
      Map<String, String> attribute = ZookeeperRegistryHelper.convertOverrideToAttribute(overridePath, data,
        removeType, interfaceConfig);
      for (ConfigListener listener : configListeners) {
        listener.attrUpdated(attribute);
      }
    }
  }
}

代码示例来源:origin: alipay/sofa-rpc

if (!INTERFACE_CONFIG_CACHE.containsKey(buildConfigPath(rootPath, config))) {
if (!INTERFACE_OVERRIDE_CACHE.containsKey(buildOverridePath(rootPath, config))) {
    providerObserver = new ZookeeperProviderObserver();
  final String providerPath = buildProviderPath(rootPath, config);
  if (LOGGER.isInfoEnabled(appName)) {
    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_SUB, providerPath));
    INTERFACE_PROVIDER_CACHE.put(config, pathChildrenCache);
  List<ProviderInfo> providerInfos = ZookeeperRegistryHelper.convertUrlsToProviders(
    providerPath, pathChildrenCache.getCurrentData());
  matchProviders = ZookeeperRegistryHelper.matchProviderInfos(config, providerInfos);
} catch (Exception e) {
  throw new SofaRpcRuntimeException("Failed to subscribe provider from zookeeperRegistry!", e);

代码示例来源:origin: alipay/sofa-rpc

urls = providerUrls.get(config);
} else {
  urls = ZookeeperRegistryHelper.convertProviderToUrls(config);
  providerUrls.put(config, urls);
  String providerPath = buildProviderPath(rootPath, config);
  if (LOGGER.isInfoEnabled(appName)) {
    LOGGER.infoWithApp(appName,

代码示例来源:origin: alipay/sofa-rpc

@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());
    }
  }
}

代码示例来源:origin: alipay/sofa-rpc

/**
 * 获取注册配置
 *
 * @param config consumer config
 * @return
 */
private AbstractInterfaceConfig getRegisterConfig(ConsumerConfig config) {
  String url = ZookeeperRegistryHelper.convertConsumerToUrl(config);
  String addr = url.substring(0, url.indexOf("?"));
  for (Map.Entry<ConsumerConfig, String> consumerUrl : consumerUrls.entrySet()) {
    if (consumerUrl.getValue().contains(addr)) {
      return consumerUrl.getKey();
    }
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

List<Map<String, String>> attributes = ZookeeperRegistryHelper.convertConfigToAttributes(configPath,
  currentData);
for (ConfigListener listener : configListeners) {

代码示例来源:origin: alipay/sofa-rpc

List<Map<String, String>> attributes = ZookeeperRegistryHelper.convertOverrideToAttributes(
  config, overridePath, currentData);
for (ConfigListener listener : configListeners) {

代码示例来源:origin: alipay/sofa-rpc

final String overridePath = buildOverridePath(rootPath, config);
final AbstractInterfaceConfig registerConfig = getRegisterConfig(config);

代码示例来源:origin: alipay/sofa-rpc

List<String> urls = providerUrls.remove(config);
if (CommonUtils.isNotEmpty(urls)) {
  String providerPath = buildProviderPath(rootPath, config);
  for (String url : urls) {
    url = URLEncoder.encode(url, "UTF-8");

代码示例来源:origin: alipay/sofa-rpc

String url = consumerUrls.remove(config);
if (url != null) {
  String consumerPath = buildConsumerPath(rootPath, config);
  url = URLEncoder.encode(url, "UTF-8");
  getAndCheckZkClient().delete().forPath(consumerPath + CONTEXT_SEP + url);

代码示例来源:origin: alipay/sofa-rpc

if (!INTERFACE_CONFIG_CACHE.containsKey(buildConfigPath(rootPath, config))) {
if (!INTERFACE_OVERRIDE_CACHE.containsKey(buildOverridePath(rootPath, config))) {
    providerObserver = new ZookeeperProviderObserver();
  final String providerPath = buildProviderPath(rootPath, config);
  if (LOGGER.isInfoEnabled(appName)) {
    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_SUB, providerPath));
    INTERFACE_PROVIDER_CACHE.put(config, pathChildrenCache);
  List<ProviderInfo> providerInfos = ZookeeperRegistryHelper.convertUrlsToProviders(
    providerPath, pathChildrenCache.getCurrentData());
  matchProviders = ZookeeperRegistryHelper.matchProviderInfos(config, providerInfos);
} catch (Exception e) {
  throw new SofaRpcRuntimeException("Failed to subscribe provider from zookeeperRegistry!", e);

代码示例来源:origin: alipay/sofa-rpc

urls = providerUrls.get(config);
} else {
  urls = ZookeeperRegistryHelper.convertProviderToUrls(config);
  providerUrls.put(config, urls);
  String providerPath = buildProviderPath(rootPath, config);
  if (LOGGER.isInfoEnabled(appName)) {
    LOGGER.infoWithApp(appName,

代码示例来源:origin: alipay/sofa-rpc

@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());
    }
  }
}

代码示例来源:origin: alipay/sofa-rpc

/**
 * 获取注册配置
 *
 * @param config consumer config
 * @return
 */
private AbstractInterfaceConfig getRegisterConfig(ConsumerConfig config) {
  String url = ZookeeperRegistryHelper.convertConsumerToUrl(config);
  String addr = url.substring(0, url.indexOf("?"));
  for (Map.Entry<ConsumerConfig, String> consumerUrl : consumerUrls.entrySet()) {
    if (consumerUrl.getValue().contains(addr)) {
      return consumerUrl.getKey();
    }
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

List<Map<String, String>> attributes = ZookeeperRegistryHelper.convertConfigToAttributes(configPath,
  currentData);
for (ConfigListener listener : configListeners) {

代码示例来源:origin: alipay/sofa-rpc

List<Map<String, String>> attributes = ZookeeperRegistryHelper.convertOverrideToAttributes(
  config, overridePath, currentData);
for (ConfigListener listener : configListeners) {

代码示例来源:origin: alipay/sofa-rpc

final String overridePath = buildOverridePath(rootPath, config);
final AbstractInterfaceConfig registerConfig = getRegisterConfig(config);

代码示例来源:origin: alipay/sofa-rpc

List<String> urls = providerUrls.remove(config);
if (CommonUtils.isNotEmpty(urls)) {
  String providerPath = buildProviderPath(rootPath, config);
  for (String url : urls) {
    url = URLEncoder.encode(url, "UTF-8");

相关文章