當前位置: 首頁>>代碼示例>>Java>>正文


Java HostAndPort.getPortOrDefault方法代碼示例

本文整理匯總了Java中com.google.common.net.HostAndPort.getPortOrDefault方法的典型用法代碼示例。如果您正苦於以下問題:Java HostAndPort.getPortOrDefault方法的具體用法?Java HostAndPort.getPortOrDefault怎麽用?Java HostAndPort.getPortOrDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.net.HostAndPort的用法示例。


在下文中一共展示了HostAndPort.getPortOrDefault方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addressFor

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/**
 * Build an {@link InetSocketAddress} for the given hostAndPort.
 * 
 * @param hostAndPort String representation of the host and port
 * @param proxyServer the current {@link DefaultHttpProxyServer}
 * @return a resolved InetSocketAddress for the specified hostAndPort
 * @throws UnknownHostException if hostAndPort could not be resolved, or if the input string could not be parsed into
 *          a host and port.
 */
public static InetSocketAddress addressFor(String hostAndPort, DefaultHttpProxyServer proxyServer)
        throws UnknownHostException {
    HostAndPort parsedHostAndPort;
    try {
        parsedHostAndPort = HostAndPort.fromString(hostAndPort);
    } catch (IllegalArgumentException e) {
        // we couldn't understand the hostAndPort string, so there is no way we can resolve it.
        throw new UnknownHostException(hostAndPort);
    }

    String host = parsedHostAndPort.getHostText();
    int port = parsedHostAndPort.getPortOrDefault(80);

    return proxyServer.getServerResolver().resolve(host, port);
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:25,代碼來源:ProxyToServerConnection.java

示例2: get

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@Override
public OpenTsdb get() {
    final OpenTsdbProtocol protocol = configuration.getProtocol();
    switch (protocol) {
        case HTTP:
            return OpenTsdb.forService(configuration.getHttpBaseUrl().toASCIIString())
                    .withConnectTimeout(configuration.getHttpConnectTimeout())
                    .withReadTimeout(configuration.getHttpReadTimeout())
                    .withGzipEnabled(configuration.isHttpEnableGzip())
                    .create();
        case TELNET:
            final HostAndPort address = configuration.getTelnetAddress();
            final String host = address.getHostText();
            final int port = address.getPortOrDefault(MetricsOpenTsdbReporterConfiguration.DEFAULT_PORT);

            return OpenTsdbTelnet.forService(host, port).create();
        default:
            throw new IllegalStateException("Invalid OpenTSDB protocol: " + protocol);
    }
}
 
開發者ID:graylog-labs,項目名稱:graylog-plugin-metrics-reporter,代碼行數:21,代碼來源:OpenTsdbProvider.java

示例3: createUrlAddress

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/** Turns {@code address} into a more human readable form. */
static HostAndPort createUrlAddress(HostAndPort address) {
  if (address.getHost().equals("::") || address.getHost().equals("0.0.0.0")) {
    return address.getPortOrDefault(80) == 80
        ? HostAndPort.fromHost(getCanonicalHostName())
        : HostAndPort.fromParts(getCanonicalHostName(), address.getPort());
  } else {
    return address.getPortOrDefault(80) == 80 ? HostAndPort.fromHost(address.getHost()) : address;
  }
}
 
開發者ID:bazelbuild,項目名稱:rules_closure,代碼行數:11,代碼來源:NetworkUtils.java

示例4: createUrlAddress

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/** Converts a bind address into an address that other machines can use to connect here. */
private static HostAndPort createUrlAddress(HostAndPort address) {
  if (address.getHost().equals("::") || address.getHost().equals("0.0.0.0")) {
    return address.getPortOrDefault(DEFAULT_PORT) == DEFAULT_PORT
        ? HostAndPort.fromHost(getCanonicalHostName())
        : HostAndPort.fromParts(getCanonicalHostName(), address.getPort());
  } else {
    return address.getPortOrDefault(DEFAULT_PORT) == DEFAULT_PORT
        ? HostAndPort.fromHost(address.getHost())
        : address;
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:13,代碼來源:TestServer.java

示例5: get

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@Override
public Statsd get() {
    final HostAndPort address = configuration.getAddress();
    return new Statsd(address.getHostText(), address.getPortOrDefault(8125));
}
 
開發者ID:graylog-labs,項目名稱:graylog-plugin-metrics-reporter,代碼行數:6,代碼來源:StatsdProvider.java


注:本文中的com.google.common.net.HostAndPort.getPortOrDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。