当前位置: 首页>>代码示例>>Java>>正文


Java HostAndPort.hasPort方法代码示例

本文整理汇总了Java中com.google.common.net.HostAndPort.hasPort方法的典型用法代码示例。如果您正苦于以下问题:Java HostAndPort.hasPort方法的具体用法?Java HostAndPort.hasPort怎么用?Java HostAndPort.hasPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.net.HostAndPort的用法示例。


在下文中一共展示了HostAndPort.hasPort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
void validate(final String setting, final String input) {
  HostAndPort hostAndPort = HostAndPort.fromString(input);
  if (this.requireBracketsForIPv6) {
    hostAndPort = hostAndPort.requireBracketsForIPv6();
  }
  if (null != this.defaultPort) {
    hostAndPort.withDefaultPort(this.defaultPort);
  }

  if (Strings.isNullOrEmpty(hostAndPort.getHostText())) {
    throw new ConfigException(String.format("'%s'(%s) host cannot be blank or null.", setting, input));
  }

  if (this.portRequired && !hostAndPort.hasPort()) {
    throw new ConfigException(String.format("'%s'(%s) must specify a port.", setting, input));
  }

}
 
开发者ID:jcustenborder,项目名称:connect-utils,代码行数:19,代码来源:ValidHostAndPort.java

示例2: withHostAndPort

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
public PayloadBuilder withHostAndPort(HostAndPort host) {
    withHost(host.getHostText());
    if (host.hasPort()) {
        withPort(host.getPort());
        withAdminPort(host.getPort() + 1);
    }
    return this;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:9,代码来源:PayloadBuilder.java

示例3: newCqlDriverBuilder

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig,
                                                                     MetricRegistry metricRegistry) {
    performHostDiscovery(metricRegistry);

    String[] seeds = _seeds.split(",");
    List<String> contactPoints = Lists.newArrayListWithCapacity(seeds.length);

    // Each seed may be a host name or a host name and port (e.g.; "1.2.3.4" or "1.2.3.4:9160").  These need
    // to be converted into host names only.
    for (String seed : seeds) {
        HostAndPort hostAndPort = HostAndPort.fromString(seed);
        seed = hostAndPort.getHostText();
        if (hostAndPort.hasPort()) {
            if (hostAndPort.getPort() == _thriftPort) {
                _log.debug("Seed {} found using RPC port; swapping for native port {}", seed, _cqlPort);
            } else if (hostAndPort.getPort() != _cqlPort) {
                throw new IllegalArgumentException(String.format(
                        "Seed %s found with invalid port %s.  The port must match either the RPC (thrift) port %s " +
                        "or the native (CQL) port %s", seed, hostAndPort.getPort(), _thriftPort, _cqlPort));
            }
        }

        contactPoints.add(seed);
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) {
        poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get());
    }
    if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) {
        poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get());
    }

    SocketOptions socketOptions = new SocketOptions();
    if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) {
        socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get());
    }
    if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) {
        socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
    }

    AuthProvider authProvider = _authenticationCredentials != null
            ? new PlainTextAuthProvider(_authenticationCredentials.getUsername(), _authenticationCredentials.getPassword())
            : AuthProvider.NONE;

    return com.datastax.driver.core.Cluster.builder()
            .addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
            .withPort(_cqlPort)
            .withPoolingOptions(poolingOptions)
            .withSocketOptions(socketOptions)
            .withRetryPolicy(Policies.defaultRetryPolicy())
            .withAuthProvider(authProvider);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:54,代码来源:CassandraConfiguration.java

示例4: removeMatchingPort

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
/**
 * Removes a port from a host+port if the string contains the specified port. If the host+port does not contain
 * a port, or contains another port, the string is returned unaltered. For example, if hostWithPort is the
 * string {@code www.website.com:443}, this method will return {@code www.website.com}.
 *
 * <b>Note:</b> The hostWithPort string is not a URI and should not contain a scheme or resource. This method does
 * not attempt to validate the specified host; it <i>might</i> throw IllegalArgumentException if there was a problem
 * parsing the hostname, but makes no guarantees. In general, it should be validated externally, if necessary.
 *
 * @param hostWithPort string containing a hostname and optional port
 * @param portNumber port to remove from the string
 * @return string with the specified port removed, or the original string if it did not contain the portNumber
 */
public static String removeMatchingPort(String hostWithPort, int portNumber) {
    HostAndPort parsedHostAndPort = HostAndPort.fromString(hostWithPort);
    if (parsedHostAndPort.hasPort() && parsedHostAndPort.getPort() == portNumber) {
        // HostAndPort.getHostText() strips brackets from ipv6 addresses, so reparse using fromHost
        return HostAndPort.fromHost(parsedHostAndPort.getHostText()).toString();
    } else {
        return hostWithPort;
    }
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:23,代码来源:BrowserMobHttpUtil.java


注:本文中的com.google.common.net.HostAndPort.hasPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。