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

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

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

URL.getPort介绍

暂无

代码示例

代码示例来源: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

/**
 * 根据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) {
  this.nettyClient = nettyClient;
  this.factoryName = "NettyChannelFactory_" + nettyClient.getUrl().getHost() + "_" + nettyClient.getUrl().getPort();
}

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

public NettyChannelFactory(NettyClient nettyClient) {
  super();
  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

/**
 * 默认策略当接口线程池占用达到3/4或者空闲小于150时,限制单个方法请求不能超过总线程数的1/2 需要自定义方法并发限制可以通过actives参数配置
 */
@Override
public void init(Caller<?> caller) {
  if (caller instanceof Provider) {
    String port = String.valueOf(caller.getUrl().getPort());
    totalCount = portTotalMap.get(port);
    if (totalCount == null) {
      portTotalMap.putIfAbsent(port, new AtomicInteger());
      totalCount = portTotalMap.get(port);
    }
    maxThread = caller.getUrl().getIntParameter(URLParamType.maxWorkerThread.getName(), URLParamType.maxWorkerThread.getIntValue());
    totalLimit = maxThread > 600 ? maxThread - 150 : maxThread * 3 / 4;
    int active = caller.getUrl().getIntParameter(URLParamType.actives.getName(), URLParamType.actives.getIntValue());
    if (active > 0) {
      methodLimit = active;
    } else {
      methodLimit = maxThread / 2;
    }
    isProvider = true;
  }
}

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

@Override
public synchronized boolean open() {
  if (isAvailable()) {
    LoggerUtil.warn("NettyServer ServerChannel already Open: url=" + url);
    return true;
  }
  LoggerUtil.info("NettyServer ServerChannel start Open: url=" + url);
  initServerBootstrap();
  serverChannel = bootstrap.bind(new InetSocketAddress(url.getPort()));
  state = ChannelState.ALIVE;
  StatsUtil.registryStatisticCallback(this);
  LoggerUtil.info("NettyServer ServerChannel finish Open: url=" + url);
  return state.isAliveState();
}

代码示例来源: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

@Override
protected RestServer innerCreateServer(URL url) {
  NettyJaxrsServer server = new NettyJaxrsServer();
  server.setMaxRequestSize(url.getIntParameter(URLParamType.maxContentLength.getName(),
      URLParamType.maxContentLength.getIntValue()));
  ResteasyDeployment deployment = new ResteasyDeployment();
  server.setDeployment(deployment);
  server.setExecutorThreadCount(url.getIntParameter(URLParamType.maxWorkerThread.getName(),
      URLParamType.maxWorkerThread.getIntValue()));
  server.setPort(url.getPort());
  server.setRootResourcePath("");
  server.setSecurityDomain(null);
  deployment.setInjectorFactoryClass(RestfulInjectorFactory.class.getName());
  deployment.getProviderClasses().add(RpcExceptionMapper.class.getName());
  return new EmbedRestServer(server);
}

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

serverBootstrap.childOption(ChannelOption.TCP_NODELAY, true);
serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture channelFuture = serverBootstrap.bind(new InetSocketAddress(url.getPort()));
channelFuture.syncUninterruptibly();
serverChannel = channelFuture.channel();

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

@Override
protected <T> Exporter<T> createExporter(Provider<T> provider, URL url) {
  String ipPort = url.getServerPortStr();
  GrpcServer server = serverMap.get(ipPort);
  if (server == null) {
    boolean shareChannel =
        url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
    int workerQueueSize = url.getIntParameter(URLParamType.workerQueueSize.getName(), URLParamType.workerQueueSize.getIntValue());
    int minWorkerThread = 0, maxWorkerThread = 0;
    if (shareChannel) {
      minWorkerThread =
          url.getIntParameter(URLParamType.minWorkerThread.getName(), MotanConstants.NETTY_SHARECHANNEL_MIN_WORKDER);
      maxWorkerThread =
          url.getIntParameter(URLParamType.maxWorkerThread.getName(), MotanConstants.NETTY_SHARECHANNEL_MAX_WORKDER);
    } else {
      minWorkerThread =
          url.getIntParameter(URLParamType.minWorkerThread.getName(), MotanConstants.NETTY_NOT_SHARECHANNEL_MIN_WORKDER);
      maxWorkerThread =
          url.getIntParameter(URLParamType.maxWorkerThread.getName(), MotanConstants.NETTY_NOT_SHARECHANNEL_MAX_WORKDER);
    }
    ExecutorService executor =
        new StandardThreadExecutor(minWorkerThread, maxWorkerThread, workerQueueSize, new DefaultThreadFactory("GrpcServer-"
            + url.getServerPortStr(), true));
    server = new GrpcServer(url.getPort(), shareChannel, executor);
    serverMap.putIfAbsent(ipPort, server);
    server = serverMap.get(ipPort);
  }
  return new GrpcExporter<T>(provider, url, server);
}

相关文章