当前位置: 首页>>代码示例>>Java>>正文


Java HostAndPort类代码示例

本文整理汇总了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());
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:7,代码来源:PushGatewayProvider.java

示例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");
}
 
开发者ID:airlift,项目名称:drift,代码行数:20,代码来源:ApacheThriftMethodInvoker.java

示例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;
}
 
开发者ID:airlift,项目名称:drift,代码行数:19,代码来源:TestApacheThriftMethodInvoker.java

示例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;
}
 
开发者ID:airlift,项目名称:drift,代码行数:25,代码来源:ConnectionPool.java

示例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));
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:25,代码来源:ConnectionFactory.java

示例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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:17,代码来源:TestDriftNettyConnectionFactoryConfig.java

示例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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:21,代码来源:SimpleAddressSelector.java

示例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;
}
 
开发者ID:airlift,项目名称:drift,代码行数:24,代码来源:TestClientsWithApacheServer.java

示例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);
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:18,代码来源:LegacyApacheThriftTesterUtil.java

示例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;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:18,代码来源:SafariBrowserLauncher.java

示例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);
}
 
开发者ID:tochkak,项目名称:play-graylog2,代码行数:23,代码来源:Graylog2Component.java

示例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;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:25,代码来源:PDClient.java

示例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);
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:19,代码来源:PDClient.java

示例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;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:22,代码来源:TiSession.java

示例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);
    }
  }
}
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:22,代码来源:OperatorUtil.java


注:本文中的com.google.common.net.HostAndPort类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。