当前位置: 首页>>代码示例>>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;未经允许,请勿转载。