當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。