com.weibo.api.motan.rpc.URL.getHost()方法的使用及代码示例

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

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

URL.getHost介绍

暂无

代码示例

代码示例来源:origin: weibocom/motan

public NettyClient(URL url) {
  super(url);
  timeMonitorFuture = scheduledExecutor.scheduleWithFixedDelay(
      new TimeoutMonitor("timeout_monitor_" + url.getHost() + "_" + url.getPort()),
      MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD, MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD,
      TimeUnit.MILLISECONDS);
}

代码示例来源:origin: weibocom/motan

@Override
protected Registry createRegistry(URL url) {
  String host = ConsulConstants.DEFAULT_HOST;
  int port = ConsulConstants.DEFAULT_PORT;
  if (StringUtils.isNotBlank(url.getHost())) {
    host = url.getHost();
  }
  if (url.getPort() > 0) {
    port = url.getPort();
  }
  //可以使用不同的client实现
  MotanConsulClient client = new ConsulEcwidClient(host, port);
  return new ConsulRegistry(url, client);
}

代码示例来源:origin: weibocom/motan

protected String getLocalHostAddress(List<URL> registryURLs) {
  String localAddress = null;
  Map<String, Integer> regHostPorts = new HashMap<String, Integer>();
  for (URL ru : registryURLs) {
    if (StringUtils.isNotBlank(ru.getHost()) && ru.getPort() > 0) {
      regHostPorts.put(ru.getHost(), ru.getPort());
    }
  }
  InetAddress address = NetUtils.getLocalAddress(regHostPorts);
  if (address != null) {
    localAddress = address.getHostAddress();
  }
  if (NetUtils.isValidLocalHost(localAddress)) {
    return localAddress;
  }
  throw new MotanServiceException("Please config local server hostname with intranet IP first!",
      MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
}

代码示例来源:origin: weibocom/motan

private List<URL> createSubscribeUrl(URL subscribeUrl) {
  URL url = this.getUrl();
  List result = new ArrayList(directUrls.size());
  for (URL directUrl : directUrls) {
    URL tmp = subscribeUrl.createCopy();
    tmp.setHost(directUrl.getHost());
    tmp.setPort(directUrl.getPort());
    result.add(tmp);
  }
  return result;
}

代码示例来源:origin: weibocom/motan

public NettyChannel(NettyClient nettyClient) {
  this.nettyClient = nettyClient;
  this.remoteAddress = new InetSocketAddress(nettyClient.getUrl().getHost(), nettyClient.getUrl().getPort());
}

代码示例来源:origin: weibocom/motan

private List<Referer<T>> searchLocalReferer(List<Referer<T>> referers, String localhost) {
  List<Referer<T>> localReferers = new ArrayList<Referer<T>>();
  long local = ipToLong(localhost);
  for (Referer<T> referer : referers) {
    long tmp = ipToLong(referer.getUrl().getHost());
    if (local != 0 && local == tmp) {
      if (referer.isAvailable()) {
        localReferers.add(referer);
      }
    }
  }
  return localReferers;
}

代码示例来源:origin: weibocom/motan

/**
 * 根据motan的url生成consul的serivce id。 serviceid 包括ip+port+rpc服务的接口类名
 *
 * @param url
 * @return
 */
public static String convertConsulSerivceId(URL url) {
  if (url == null) {
    return null;
  }
  return convertServiceId(url.getHost(), url.getPort(), url.getPath());
}

代码示例来源:origin: weibocom/motan

private List<URL> mergeResult(URL url, Map<String, Integer> weights) {
  List<URL> finalResult = new ArrayList<URL>();
  if (weights.size() > 1) {
    // 将所有group及权重拼接成一个rule的URL,并作为第一个元素添加到最终结果中
    URL ruleUrl = new URL("rule", url.getHost(), url.getPort(), url.getPath());
    StringBuilder weightsBuilder = new StringBuilder(64);
    for (Map.Entry<String, Integer> entry : weights.entrySet()) {
      weightsBuilder.append(entry.getKey()).append(':').append(entry.getValue()).append(',');
    }
    ruleUrl.addParameter(URLParamType.weights.getName(), weightsBuilder.deleteCharAt(weightsBuilder.length() - 1).toString());
    finalResult.add(ruleUrl);
  }
  for (String key : weights.keySet()) {
    if (groupServiceCache.containsKey(key)) {
      finalResult.addAll(groupServiceCache.get(key));
    } else {
      URL urlTemp = url.createCopy();
      urlTemp.addParameter(URLParamType.group.getName(), key);
      finalResult.addAll(discoverOneGroup(urlTemp));
      registry.subscribeService(urlTemp, this);
    }
  }
  return finalResult;
}

代码示例来源:origin: weibocom/motan

public NettyChannelFactory(NettyClient nettyClient) {
  super();
  this.nettyClient = nettyClient;
  this.factoryName = "NettyChannelFactory_" + nettyClient.getUrl().getHost() + "_"
      + nettyClient.getUrl().getPort();
}

代码示例来源:origin: weibocom/motan

public NettyChannelFactory(NettyClient nettyClient) {
  this.nettyClient = nettyClient;
  this.factoryName = "NettyChannelFactory_" + nettyClient.getUrl().getHost() + "_" + nettyClient.getUrl().getPort();
}

代码示例来源:origin: weibocom/motan

public DirectRegistry(URL url) {
  super(url);
  String address = url.getParameter("address");
  if (address.contains(",")) {
    try {
      String[] directUrlArray = address.split(",");
      for (String directUrl : directUrlArray) {
        parseDirectUrl(directUrl);
      }
    } catch (Exception e) {
      throw new MotanFrameworkException(
          String.format("parse direct url error, invalid direct registry address %s, address should be ip1:port1,ip2:port2 ..."));
    }
  } else {
    registerDirectUrl(url.getHost(), url.getPort());
  }
}

代码示例来源:origin: weibocom/motan

protected ResteasyWebTarget innerCreateClient(URL url) {
  ResteasyClient client = new ResteasyClientBuilder().build();
  String contextpath = url.getParameter("contextpath", "/");
  if (!contextpath.startsWith("/"))
    contextpath = "/" + contextpath;
  return client.target("http://" + url.getHost() + ":" + url.getPort() + contextpath);
}

代码示例来源:origin: weibocom/motan

public NettyClient(URL url) {
  super(url);
  maxClientConnection = url.getIntParameter(URLParamType.maxClientConnection.getName(),
      URLParamType.maxClientConnection.getIntValue());
  timeMonitorFuture = scheduledExecutor.scheduleWithFixedDelay(
      new TimeoutMonitor("timeout_monitor_" + url.getHost() + "_" + url.getPort()),
      MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD, MotanConstants.NETTY_TIMEOUT_TIMER_PERIOD,
      TimeUnit.MILLISECONDS);
}

代码示例来源:origin: weibocom/motan

boolean changed = false;
String protocol = u.getProtocol();
String host = u.getHost();
int port = u.getPort();
String path = u.getPath();

代码示例来源:origin: weibocom/motan

public AbstractClient(URL url) {
  this.url = url;
  this.codec =
      ExtensionLoader.getExtensionLoader(Codec.class).getExtension(
          url.getParameter(URLParamType.codec.getName(), URLParamType.codec.getValue()));
  LoggerUtil.info("init nettyclient. url:" + url.getHost() + "-" + url.getPath() + ", use codec:" + codec.getClass().getSimpleName());
}

代码示例来源:origin: weibocom/motan

public NettyChannel(NettyClient nettyClient) {
  this.nettyClient = nettyClient;
  this.remoteAddress = new InetSocketAddress(nettyClient.getUrl().getHost(), nettyClient.getUrl().getPort());
  codec = ExtensionLoader.getExtensionLoader(Codec.class).getExtension(nettyClient.getUrl().getParameter(URLParamType.codec.getName(), URLParamType.codec.getValue()));
}

代码示例来源:origin: weibocom/motan

public boolean init() throws Exception {
  methodDescMap = GrpcUtil.getMethodDescriptorByAnnotation(interfaceClazz, url.getParameter(URLParamType.serialize.getName()));
  channel = ManagedChannelBuilder.forAddress(url.getHost(), url.getPort()).usePlaintext(true).build();
  return true;
}

代码示例来源:origin: weibocom/motan

/**
 * 根据服务的url生成consul对应的service
 *
 * @param url
 * @return
 */
public static ConsulService buildService(URL url) {
  ConsulService service = new ConsulService();
  service.setAddress(url.getHost());
  service.setId(ConsulUtils.convertConsulSerivceId(url));
  service.setName(ConsulUtils.convertGroupToServiceName(url.getGroup()));
  service.setPort(url.getPort());
  service.setTtl(ConsulConstants.TTL);
  List<String> tags = new ArrayList<String>();
  tags.add(ConsulConstants.CONSUL_TAG_MOTAN_PROTOCOL + url.getProtocol());
  tags.add(ConsulConstants.CONSUL_TAG_MOTAN_URL + StringTools.urlEncode(url.toFullStr()));
  service.setTags(tags);
  return service;
}

代码示例来源:origin: weibocom/motan

private void logAccess(Caller<?> caller, Request request, long consumeTime, boolean success) {
  if (getSide() == null) {
    String side = caller instanceof Provider ? MotanConstants.NODE_TYPE_SERVICE : MotanConstants.NODE_TYPE_REFERER;
    setSide(side);
  }
  StringBuilder builder = new StringBuilder(128);
  append(builder, side);
  append(builder, caller.getUrl().getParameter(URLParamType.application.getName()));
  append(builder, caller.getUrl().getParameter(URLParamType.module.getName()));
  append(builder, NetUtils.getLocalAddress().getHostAddress());
  append(builder, request.getInterfaceName());
  append(builder, request.getMethodName());
  append(builder, request.getParamtersDesc());
  // 对于client,url中的remote ip, application, module,referer 和 service获取的地方不同
  if (MotanConstants.NODE_TYPE_REFERER.equals(side)) {
    append(builder, caller.getUrl().getHost());
    append(builder, caller.getUrl().getParameter(URLParamType.application.getName()));
    append(builder, caller.getUrl().getParameter(URLParamType.module.getName()));
  } else {
    append(builder, request.getAttachments().get(URLParamType.host.getName()));
    append(builder, request.getAttachments().get(URLParamType.application.getName()));
    append(builder, request.getAttachments().get(URLParamType.module.getName()));
  }
  append(builder, success);
  append(builder, request.getAttachments().get(URLParamType.requestIdFromClient.getName()));
  append(builder, consumeTime);
  LoggerUtil.accessLog(builder.substring(0, builder.length() - 1));
}

代码示例来源:origin: weibocom/motan

try {
  channelFuture = nettyClient.getBootstrap().connect(
      new InetSocketAddress(nettyClient.getUrl().getHost(), nettyClient.getUrl().getPort()));

相关文章