org.apache.dubbo.common.URL.setPath()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(13.1k)|赞(0)|评价(0)|浏览(139)

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

URL.setPath介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-dubbo

@Override
public MetadataReport getMetadataReport(URL url) {
  url = url.setPath(MetadataReport.class.getName())
      .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
  String key = url.toServiceString();
  // Lock the registry access process to ensure a single instance of the registry
  LOCK.lock();
  try {
    MetadataReport metadataReport = SERVICE_STORE_MAP.get(key);
    if (metadataReport != null) {
      return metadataReport;
    }
    metadataReport = createMetadataReport(url);
    if (metadataReport == null) {
      throw new IllegalStateException("Can not create metadata Report " + url);
    }
    SERVICE_STORE_MAP.put(key, metadataReport);
    return metadataReport;
  } finally {
    // Release the lock
    LOCK.unlock();
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public MetadataReport getMetadataReport(URL url) {
  url = url.setPath(MetadataReport.class.getName())
      .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
  String key = url.toServiceString();
  // Lock the registry access process to ensure a single instance of the registry
  LOCK.lock();
  try {
    MetadataReport metadataReport = SERVICE_STORE_MAP.get(key);
    if (metadataReport != null) {
      return metadataReport;
    }
    metadataReport = createMetadataReport(url);
    if (metadataReport == null) {
      throw new IllegalStateException("Can not create metadata Report " + url);
    }
    SERVICE_STORE_MAP.put(key, metadataReport);
    return metadataReport;
  } finally {
    // Release the lock
    LOCK.unlock();
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Monitor getMonitor(URL url) {
  url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
  String key = url.toServiceStringWithoutResolving();
  Monitor monitor = MONITORS.get(key);
  Future<Monitor> future = FUTURES.get(key);
  if (monitor != null || future != null) {
    return monitor;
  }
  LOCK.lock();
  try {
    monitor = MONITORS.get(key);
    future = FUTURES.get(key);
    if (monitor != null || future != null) {
      return monitor;
    }
    final URL monitorUrl = url;
    final CompletableFuture<Monitor> completableFuture = CompletableFuture.supplyAsync(() -> AbstractMonitorFactory.this.createMonitor(monitorUrl));
    completableFuture.thenRunAsync(new MonitorListener(key), executor);
    FUTURES.put(key, completableFuture);
    return null;
  } finally {
    // unlock
    LOCK.unlock();
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Monitor getMonitor(URL url) {
  url = url.setPath(MonitorService.class.getName()).addParameter(Constants.INTERFACE_KEY, MonitorService.class.getName());
  String key = url.toServiceStringWithoutResolving();
  Monitor monitor = MONITORS.get(key);
  Future<Monitor> future = FUTURES.get(key);
  if (monitor != null || future != null) {
    return monitor;
  }
  LOCK.lock();
  try {
    monitor = MONITORS.get(key);
    future = FUTURES.get(key);
    if (monitor != null || future != null) {
      return monitor;
    }
    final URL monitorUrl = url;
    final CompletableFuture<Monitor> completableFuture = CompletableFuture.supplyAsync(() -> AbstractMonitorFactory.this.createMonitor(monitorUrl));
    completableFuture.thenRunAsync(new MonitorListener(key), executor);
    FUTURES.put(key, completableFuture);
    return null;
  } finally {
    // unlock
    LOCK.unlock();
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Registry getRegistry(URL url) {
  url = url.setPath(RegistryService.class.getName())
      .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
      .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
  String key = url.toServiceStringWithoutResolving();
  // Lock the registry access process to ensure a single instance of the registry
  LOCK.lock();
  try {
    Registry registry = REGISTRIES.get(key);
    if (registry != null) {
      return registry;
    }
    //create registry by spi/ioc
    registry = createRegistry(url);
    if (registry == null) {
      throw new IllegalStateException("Can not create registry " + url);
    }
    REGISTRIES.put(key, registry);
    return registry;
  } finally {
    // Release the lock
    LOCK.unlock();
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Registry getRegistry(URL url) {
  url = url.setPath(RegistryService.class.getName())
      .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
      .removeParameters(Constants.EXPORT_KEY, Constants.REFER_KEY);
  String key = url.toServiceStringWithoutResolving();
  // Lock the registry access process to ensure a single instance of the registry
  LOCK.lock();
  try {
    Registry registry = REGISTRIES.get(key);
    if (registry != null) {
      return registry;
    }
    //create registry by spi/ioc
    registry = createRegistry(url);
    if (registry == null) {
      throw new IllegalStateException("Can not create registry " + url);
    }
    REGISTRIES.put(key, registry);
    return registry;
  } finally {
    // Release the lock
    LOCK.unlock();
  }
}

代码示例来源:origin: apache/incubator-dubbo

private URL turnRegistryUrlToConsumerUrl(URL url) {
  // save any parameter in registry that will be useful to the new url.
  String isDefault = url.getParameter(Constants.DEFAULT_KEY);
  if (StringUtils.isNotEmpty(isDefault)) {
    queryMap.put(Constants.REGISTRY_KEY + "." + Constants.DEFAULT_KEY, isDefault);
  }
  return url.setPath(url.getServiceInterface())
      .clearParameters()
      .addParameters(queryMap)
      .removeParameter(Constants.MONITOR_KEY);
}

代码示例来源:origin: apache/incubator-dubbo

private URL turnRegistryUrlToConsumerUrl(URL url) {
  // save any parameter in registry that will be useful to the new url.
  String isDefault = url.getParameter(Constants.DEFAULT_KEY);
  if (StringUtils.isNotEmpty(isDefault)) {
    queryMap.put(Constants.REGISTRY_KEY + "." + Constants.DEFAULT_KEY, isDefault);
  }
  return url.setPath(url.getServiceInterface())
      .clearParameters()
      .addParameters(queryMap)
      .removeParameter(Constants.MONITOR_KEY);
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * Merge url parameters. the order is: override > -D >Consumer > Provider
 *
 * @param providerUrl
 * @return
 */
private URL mergeUrl(URL providerUrl) {
  providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // Merge the consumer side parameters
  providerUrl = overrideWithConfigurator(providerUrl);
  providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // Do not check whether the connection is successful or not, always create Invoker!
  // The combination of directoryUrl and override is at the end of notify, which can't be handled here
  this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // Merge the provider side parameters
  if ((providerUrl.getPath() == null || providerUrl.getPath()
      .length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // Compatible version 1.0
    //fix by tony.chenl DUBBO-44
    String path = directoryUrl.getParameter(Constants.INTERFACE_KEY);
    if (path != null) {
      int i = path.indexOf('/');
      if (i >= 0) {
        path = path.substring(i + 1);
      }
      i = path.lastIndexOf(':');
      if (i >= 0) {
        path = path.substring(0, i);
      }
      providerUrl = providerUrl.setPath(path);
    }
  }
  return providerUrl;
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * Merge url parameters. the order is: override > -D >Consumer > Provider
 *
 * @param providerUrl
 * @return
 */
private URL mergeUrl(URL providerUrl) {
  providerUrl = ClusterUtils.mergeUrl(providerUrl, queryMap); // Merge the consumer side parameters
  providerUrl = overrideWithConfigurator(providerUrl);
  providerUrl = providerUrl.addParameter(Constants.CHECK_KEY, String.valueOf(false)); // Do not check whether the connection is successful or not, always create Invoker!
  // The combination of directoryUrl and override is at the end of notify, which can't be handled here
  this.overrideDirectoryUrl = this.overrideDirectoryUrl.addParametersIfAbsent(providerUrl.getParameters()); // Merge the provider side parameters
  if ((providerUrl.getPath() == null || providerUrl.getPath()
      .length() == 0) && "dubbo".equals(providerUrl.getProtocol())) { // Compatible version 1.0
    //fix by tony.chenl DUBBO-44
    String path = directoryUrl.getParameter(Constants.INTERFACE_KEY);
    if (path != null) {
      int i = path.indexOf('/');
      if (i >= 0) {
        path = path.substring(i + 1);
      }
      i = path.lastIndexOf(':');
      if (i >= 0) {
        path = path.substring(0, i);
      }
      providerUrl = providerUrl.setPath(path);
    }
  }
  return providerUrl;
}

代码示例来源:origin: apache/incubator-dubbo

if (!anyServices.contains(child)) {
    anyServices.add(child);
    subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child,
        Constants.CHECK_KEY, String.valueOf(false)), listener);
service = URL.decode(service);
anyServices.add(service);
subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service,
    Constants.CHECK_KEY, String.valueOf(false)), listener);

代码示例来源:origin: apache/incubator-dubbo

if (!anyServices.contains(child)) {
    anyServices.add(child);
    subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child,
        Constants.CHECK_KEY, String.valueOf(false)), listener);
service = URL.decode(service);
anyServices.add(service);
subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service,
    Constants.CHECK_KEY, String.valueOf(false)), listener);

代码示例来源:origin: apache/incubator-dubbo

urls.add(url.setProtocol(Constants.EMPTY_PROTOCOL)
    .setAddress(Constants.ANYHOST_VALUE)
    .setPath(toServiceName(key))
    .addParameter(Constants.CATEGORY_KEY, category));

代码示例来源:origin: apache/incubator-dubbo

urls.add(url.setProtocol(Constants.EMPTY_PROTOCOL)
    .setAddress(Constants.ANYHOST_VALUE)
    .setPath(toServiceName(key))
    .addParameter(Constants.CATEGORY_KEY, category));

代码示例来源:origin: apache/incubator-dubbo

@Override
protected Monitor createMonitor(URL url) {
  url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
  if (StringUtils.isEmpty(url.getPath())) {
    url = url.setPath(MonitorService.class.getName());
  }
  String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
  if (StringUtils.isEmpty(filter)) {
    filter = "";
  } else {
    filter = filter + ",";
  }
  url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false),
      Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
  Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
  MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
  return new DubboMonitor(monitorInvoker, monitorService);
}

代码示例来源:origin: apache/incubator-dubbo

private static URL getRegistryURL(URL url) {
  return url.setPath(RegistryService.class.getName())
      .removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY)
      .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
      .addParameter(Constants.CLUSTER_STICKY_KEY, "true")
      .addParameter(Constants.LAZY_CONNECT_KEY, "true")
      .addParameter(Constants.RECONNECT_KEY, "false")
      .addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000")
      .addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000")
      .addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000")
      .addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ","))
      //.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName())
      //.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch
      //.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect")
      .addParameter("subscribe.1.callback", "true")
      .addParameter("unsubscribe.1.callback", "false");
}

代码示例来源:origin: apache/incubator-dubbo

private static URL getRegistryURL(URL url) {
  return url.setPath(RegistryService.class.getName())
      .removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY)
      .addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
      .addParameter(Constants.CLUSTER_STICKY_KEY, "true")
      .addParameter(Constants.LAZY_CONNECT_KEY, "true")
      .addParameter(Constants.RECONNECT_KEY, "false")
      .addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000")
      .addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000")
      .addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000")
      .addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ","))
      //.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName())
      //.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch
      //.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect")
      .addParameter("subscribe.1.callback", "true")
      .addParameter("unsubscribe.1.callback", "false");
}

代码示例来源:origin: apache/incubator-dubbo

@Override
protected Monitor createMonitor(URL url) {
  url = url.setProtocol(url.getParameter(Constants.PROTOCOL_KEY, "dubbo"));
  if (StringUtils.isEmpty(url.getPath())) {
    url = url.setPath(MonitorService.class.getName());
  }
  String filter = url.getParameter(Constants.REFERENCE_FILTER_KEY);
  if (StringUtils.isEmpty(filter)) {
    filter = "";
  } else {
    filter = filter + ",";
  }
  url = url.addParameters(Constants.CLUSTER_KEY, "failsafe", Constants.CHECK_KEY, String.valueOf(false),
      Constants.REFERENCE_FILTER_KEY, filter + "-monitor");
  Invoker<MonitorService> monitorInvoker = protocol.refer(MonitorService.class, url);
  MonitorService monitorService = proxyFactory.getProxy(monitorInvoker);
  return new DubboMonitor(monitorInvoker, monitorService);
}

代码示例来源:origin: apache/incubator-dubbo

if (isGeneric) {
  RpcContext.getContext().setAttachment(Constants.GENERIC_KEY, generic);
  url = url.setPath(url.getPath() + "/" + Constants.GENERIC_KEY);

代码示例来源:origin: apache/incubator-dubbo

if (isGeneric) {
  RpcContext.getContext().setAttachment(Constants.GENERIC_KEY, generic);
  url = url.setPath(url.getPath() + "/" + Constants.GENERIC_KEY);

相关文章

微信公众号

最新文章

更多