本文整理汇总了Java中com.google.common.net.HostAndPort类的典型用法代码示例。如果您正苦于以下问题:Java HostAndPort类的具体用法?Java HostAndPort怎么用?Java HostAndPort使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HostAndPort类属于com.google.common.net包,在下文中一共展示了HostAndPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.google.common.net.HostAndPort; //导入依赖的package包/类
@Override
public PushGateway get() {
final HostAndPort address = configuration.getAddress().withDefaultPort(9091);
return new PushGateway(address.toString());
}
示例2: ApacheThriftMethodInvoker
import com.google.common.net.HostAndPort; //导入依赖的package包/类
public ApacheThriftMethodInvoker(
ListeningExecutorService executorService,
ListeningScheduledExecutorService delayService,
TTransportFactory transportFactory,
TProtocolFactory protocolFactory,
Duration connectTimeout,
Duration requestTimeout,
Optional<HostAndPort> socksProxy,
Optional<SSLContext> sslContext)
{
this.executorService = requireNonNull(executorService, "executorService is null");
this.delayService = requireNonNull(delayService, "delayService is null");
this.transportFactory = requireNonNull(transportFactory, "transportFactory is null");
this.protocolFactory = requireNonNull(protocolFactory, "protocolFactory is null");
this.connectTimeoutMillis = Ints.saturatedCast(requireNonNull(connectTimeout, "connectTimeout is null").toMillis());
this.requestTimeoutMillis = Ints.saturatedCast(requireNonNull(requestTimeout, "requestTimeout is null").toMillis());
this.socksProxy = requireNonNull(socksProxy, "socksProxy is null");
this.sslContext = requireNonNull(sslContext, "sslContext is null");
}
示例3: logThrift
import com.google.common.net.HostAndPort; //导入依赖的package包/类
private static int logThrift(HostAndPort address, List<LogEntry> messages)
{
try {
TSocket socket = new TSocket(address.getHost(), address.getPort());
socket.open();
try {
TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket));
assertEquals(new scribe.Client(tp).Log(messages), ResultCode.OK);
}
finally {
socket.close();
}
}
catch (TException e) {
throw new RuntimeException(e);
}
return 1;
}
示例4: getConnection
import com.google.common.net.HostAndPort; //导入依赖的package包/类
@Override
public Future<Channel> getConnection(HostAndPort address)
{
Future<Channel> future;
synchronized (this) {
if (closed) {
return group.next().newFailedFuture(new TTransportException("Connection pool is closed"));
}
try {
future = cachedConnections.get(address);
}
catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
// check if connection is failed
if (isFailed(future)) {
// remove failed connection
cachedConnections.asMap().remove(address, future);
}
return future;
}
示例5: getConnection
import com.google.common.net.HostAndPort; //导入依赖的package包/类
@Override
public Future<Channel> getConnection(HostAndPort address)
{
try {
Bootstrap bootstrap = new Bootstrap()
.group(group)
.channel(NioSocketChannel.class)
.option(CONNECT_TIMEOUT_MILLIS, saturatedCast(connectTimeout.toMillis()))
.handler(new ThriftClientInitializer(
messageFraming,
messageEncoding,
requestTimeout,
socksProxy,
sslContextSupplier));
Promise<Channel> promise = group.next().newPromise();
bootstrap.connect(new InetSocketAddress(address.getHost(), address.getPort()))
.addListener((ChannelFutureListener) future -> notifyConnect(future, promise));
return promise;
}
catch (Throwable e) {
return group.next().newFailedFuture(new TTransportException(e));
}
}
示例6: testExplicitPropertyMappings
import com.google.common.net.HostAndPort; //导入依赖的package包/类
@Test
public void testExplicitPropertyMappings()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("thrift.client.thread-count", "99")
.put("thrift.client.ssl-context.refresh-time", "33m")
.put("thrift.client.socks-proxy", "example.com:9876")
.build();
DriftNettyConnectionFactoryConfig expected = new DriftNettyConnectionFactoryConfig()
.setThreadCount(99)
.setSslContextRefreshTime(new Duration(33, MINUTES))
.setSocksProxy(HostAndPort.fromParts("example.com", 9876));
assertFullMapping(properties, expected);
}
示例7: selectAddress
import com.google.common.net.HostAndPort; //导入依赖的package包/类
@Override
public Optional<Address> selectAddress(Optional<String> addressSelectionContext)
{
checkArgument(!addressSelectionContext.isPresent(), "addressSelectionContext should not be set");
List<HostAndPort> result = new ArrayList<>();
for (HostAndPort address : addresses) {
try {
for (InetAddress ip : InetAddress.getAllByName(address.getHost())) {
result.add(HostAndPort.fromParts(ip.getHostAddress(), address.getPort()));
}
}
catch (UnknownHostException ignored) {
}
}
if (result.isEmpty()) {
return Optional.empty();
}
HostAndPort hostAndPort = result.get(ThreadLocalRandom.current().nextInt(result.size()));
return Optional.of(() -> hostAndPort);
}
示例8: testApacheServer
import com.google.common.net.HostAndPort; //导入依赖的package包/类
private static int testApacheServer(List<MethodInvocationFilter> filters)
throws Exception
{
ScribeService scribeService = new ScribeService();
TProcessor processor = new scribe.Processor<>(scribeService);
int invocationCount = 0;
for (boolean secure : ImmutableList.of(true, false)) {
for (Transport transport : Transport.values()) {
for (Protocol protocol : Protocol.values()) {
invocationCount += testApacheServer(secure, transport, protocol, processor, ImmutableList.<ToIntFunction<HostAndPort>>builder()
.addAll(legacyApacheThriftTestClients(filters, transport, protocol, secure))
.addAll(driftNettyTestClients(filters, transport, protocol, secure))
.addAll(apacheThriftTestClients(filters, transport, protocol, secure))
.build());
}
}
}
assertEquals(scribeService.getMessages(), newArrayList(concat(nCopies(invocationCount, MESSAGES))));
return invocationCount;
}
示例9: createClientSocket
import com.google.common.net.HostAndPort; //导入依赖的package包/类
private static TSocket createClientSocket(boolean secure, HostAndPort address)
throws TTransportException
{
if (!secure) {
return new TSocket(address.getHost(), address.getPort());
}
try {
SSLContext serverSslContext = ClientTestUtils.getClientSslContext();
SSLSocket clientSocket = (SSLSocket) serverSslContext.getSocketFactory().createSocket(address.getHost(), address.getPort());
// clientSocket.setSoTimeout(timeout);
return new TSocket(clientSocket);
}
catch (Exception e) {
throw new TTransportException("Error initializing secure socket", e);
}
}
示例10: launch
import com.google.common.net.HostAndPort; //导入依赖的package包/类
@Override
public final SafariBrowser launch(DesiredCapabilities caps) throws BrowserException {
String udid = (String) caps.getCapability("uuid");
SafariBrowser browser = udid == null ? launch() : launch(udid);
@SuppressWarnings("unchecked")
Map<String, String> proxyDict = (Map<String, String>) caps.getCapability("proxy");
if (proxyDict != null) {
HostAndPort proxy = HostAndPort.fromString(proxyDict.get("httpProxy"));
browser.setHttpProxy(proxy);
}
@SuppressWarnings("unchecked")
Map<String, String> cert = (Map<String, String>) caps.getCapability("httpsCert");
if (cert != null) {
browser.installHttpsCert(cert.get("certName"), cert.get("certContentBase64"));
}
return browser;
}
示例11: getGelfConfiguration
import com.google.common.net.HostAndPort; //导入依赖的package包/类
private GelfConfiguration getGelfConfiguration(Configuration config) {
final Integer queueCapacity = config.getInt("graylog2.appender.queue-size", 512);
final Long reconnectInterval = config.getMilliseconds("graylog2.appender.reconnect-interval", 500L);
final Long connectTimeout = config.getMilliseconds("graylog2.appender.connect-timeout", 1000L);
final Boolean isTcpNoDelay = config.getBoolean("graylog2.appender.tcp-nodelay", false);
final String hostString = config.getString("graylog2.appender.host", "127.0.0.1:12201");
final String protocol = config.getString("graylog2.appender.protocol", "udp");
final HostAndPort hostAndPort = HostAndPort.fromString(hostString);
GelfTransports gelfTransport = GelfTransports.valueOf(protocol.toUpperCase());
final Integer sendBufferSize = config.getInt("graylog2.appender.sendbuffersize", 0); // causes the socket default to be used
return new GelfConfiguration(hostAndPort.getHost(), hostAndPort.getPort())
.transport(gelfTransport)
.reconnectDelay(reconnectInterval.intValue())
.queueSize(queueCapacity)
.connectTimeout(connectTimeout.intValue())
.tcpNoDelay(isTcpNoDelay)
.sendBufferSize(sendBufferSize);
}
示例12: createLeaderWrapper
import com.google.common.net.HostAndPort; //导入依赖的package包/类
private boolean createLeaderWrapper(String leaderUrlStr) {
try {
URL tURL = new URL(leaderUrlStr);
HostAndPort newLeader = HostAndPort.fromParts(tURL.getHost(), tURL.getPort());
leaderUrlStr = newLeader.toString();
if (leaderWrapper != null && leaderUrlStr.equals(leaderWrapper.getLeaderInfo())) {
return true;
}
// create new Leader
ManagedChannel clientChannel = session.getChannel(leaderUrlStr);
leaderWrapper =
new LeaderWrapper(
leaderUrlStr,
PDGrpc.newBlockingStub(clientChannel),
PDGrpc.newStub(clientChannel),
System.nanoTime());
} catch (MalformedURLException e) {
logger.error("Error updating leader.", e);
return false;
}
logger.info(String.format("Switched to new leader: %s", leaderWrapper));
return true;
}
示例13: initCluster
import com.google.common.net.HostAndPort; //导入依赖的package包/类
private void initCluster() {
GetMembersResponse resp = null;
List<HostAndPort> pdAddrs = getSession().getConf().getPdAddrs();
for(HostAndPort u: pdAddrs) {
resp = getMembers(u);
if(resp != null) {
break;
}
}
checkNotNull(resp, "Failed to init client for PD cluster.");
long clusterId = resp.getHeader().getClusterId();
header = RequestHeader.newBuilder().setClusterId(clusterId).build();
tsoReq = TsoRequest.newBuilder().setHeader(header).build();
this.pdAddrs = pdAddrs;
createLeaderWrapper(resp.getLeader().getClientUrls(0));
service = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).build());
service.scheduleAtFixedRate(this::updateLeader, 1, 1, TimeUnit.MINUTES);
}
示例14: getChannel
import com.google.common.net.HostAndPort; //导入依赖的package包/类
public synchronized ManagedChannel getChannel(String addressStr) {
ManagedChannel channel = connPool.get(addressStr);
if (channel == null) {
HostAndPort address;
try {
address = HostAndPort.fromString(addressStr);
} catch (Exception e) {
throw new IllegalArgumentException("failed to form address");
}
// Channel should be lazy without actual connection until first call
// So a coarse grain lock is ok here
channel = ManagedChannelBuilder.forAddress(address.getHostText(), address.getPort())
.maxInboundMessageSize(conf.getMaxFrameSize())
.usePlaintext(true)
.idleTimeout(60, TimeUnit.SECONDS)
.build();
connPool.put(addressStr, channel);
}
return channel;
}
示例15: startOstrichService
import com.google.common.net.HostAndPort; //导入依赖的package包/类
public static void startOstrichService(String tsdbHostPort, int ostrichPort) {
final int TSDB_METRICS_PUSH_INTERVAL_IN_MILLISECONDS = 10 * 1000;
OstrichAdminService ostrichService = new OstrichAdminService(ostrichPort);
ostrichService.startAdminHttpService();
if (tsdbHostPort != null) {
LOG.info("Starting the OpenTsdb metrics pusher");
try {
HostAndPort pushHostPort = HostAndPort.fromString(tsdbHostPort);
MetricsPusher metricsPusher = new MetricsPusher(
pushHostPort.getHostText(),
pushHostPort.getPort(),
new OpenTsdbMetricConverter("KafkaOperator", HostName),
TSDB_METRICS_PUSH_INTERVAL_IN_MILLISECONDS);
metricsPusher.start();
LOG.info("OpenTsdb metrics pusher started!");
} catch (Throwable t) {
// pusher fail is OK, do
LOG.error("Exception when starting stats pusher: ", t);
}
}
}