當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。