本文整理汇总了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);
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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));
}