本文整理匯總了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));
}