當前位置: 首頁>>代碼示例>>Java>>正文


Java HostAndPort.getHostText方法代碼示例

本文整理匯總了Java中com.google.common.net.HostAndPort.getHostText方法的典型用法代碼示例。如果您正苦於以下問題:Java HostAndPort.getHostText方法的具體用法?Java HostAndPort.getHostText怎麽用?Java HostAndPort.getHostText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.net.HostAndPort的用法示例。


在下文中一共展示了HostAndPort.getHostText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: bootstrap

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public boolean bootstrap(HostAndPort seed, 
                         Node localNode) throws SyncException {
    this.localNode = localNode;
    succeeded = false;
    SocketAddress sa =
            new InetSocketAddress(seed.getHostText(), seed.getPort());
    ChannelFuture future = bootstrap.connect(sa);
    future.awaitUninterruptibly();
    if (!future.isSuccess()) {
        logger.debug("Could not connect to " + seed, future.cause());
        return false;
    }
    Channel channel = future.channel();
    logger.debug("[{}] Connected to {}", 
                 localNode != null ? localNode.getNodeId() : null,
                 seed);
    
    try {
        channel.closeFuture().await();
    } catch (InterruptedException e) {
        logger.debug("Interrupted while waiting for bootstrap");
        return succeeded;
    }
    return succeeded;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:26,代碼來源:BootstrapClient.java

示例3: bootstrap

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public boolean bootstrap(HostAndPort seed, 
                         Node localNode) throws SyncException {
    this.localNode = localNode;
    succeeded = false;
    SocketAddress sa =
            new InetSocketAddress(seed.getHostText(), seed.getPort());
    ChannelFuture future = bootstrap.connect(sa);
    future.awaitUninterruptibly();
    if (!future.isSuccess()) {
        logger.debug("Could not connect to " + seed, future.getCause());
        return false;
    }
    Channel channel = future.getChannel();
    logger.debug("[{}] Connected to {}", 
                 localNode != null ? localNode.getNodeId() : null,
                 seed);
    
    try {
        channel.getCloseFuture().await();
    } catch (InterruptedException e) {
        logger.debug("Interrupted while waiting for bootstrap");
        return succeeded;
    }
    return succeeded;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:26,代碼來源:Bootstrap.java

示例4: bootstrap

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public boolean bootstrap(HostAndPort seed,
                         Node localNode) throws SyncException {
    this.localNode = localNode;
    succeeded = false;
    SocketAddress sa =
            new InetSocketAddress(seed.getHostText(), seed.getPort());
    ChannelFuture future = bootstrap.connect(sa);
    future.awaitUninterruptibly();
    if (!future.isSuccess()) {
        logger.debug("Could not connect to " + seed, future.cause());
        return false;
    }
    Channel channel = future.channel();
    logger.debug("[{}] Connected to {}",
                 localNode != null ? localNode.getNodeId() : null,
                 seed);

    try {
        channel.closeFuture().await();
    } catch (InterruptedException e) {
        logger.debug("Interrupted while waiting for bootstrap");
        return succeeded;
    }
    return succeeded;
}
 
開發者ID:zhenshengcai,項目名稱:floodlight-hardware,代碼行數:26,代碼來源:BootstrapClient.java

示例5: parseHostHeader

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/**
 * Retrieves the host and, optionally, the port from the specified request's Host header.
 *
 * @param httpRequest HTTP request
 * @param includePort when true, include the port
 * @return the host and, optionally, the port specified in the request's Host header
 */
private static String parseHostHeader(HttpRequest httpRequest, boolean includePort) {
    // this header parsing logic is adapted from ClientToProxyConnection#identifyHostAndPort.
    List<String> hosts = httpRequest.headers().getAll(HttpHeaders.Names.HOST);
    if (!hosts.isEmpty()) {
        String hostAndPort = hosts.get(0);

        if (includePort) {
            return hostAndPort;
        } else {
            HostAndPort parsedHostAndPort = HostAndPort.fromString(hostAndPort);
            return parsedHostAndPort.getHostText();
        }
    } else {
        return null;
    }
}
 
開發者ID:misakuo,項目名稱:Dream-Catcher,代碼行數:24,代碼來源:HttpUtil.java

示例6: 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);
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:25,代碼來源:ProxyToServerConnection.java

示例7: 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);
    }
}
 
開發者ID:graylog-labs,項目名稱:graylog-plugin-metrics-reporter,代碼行數:21,代碼來源:OpenTsdbProvider.java

示例8: createAndGetConfiguredGraphiteReporter

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
private ScheduledReporter createAndGetConfiguredGraphiteReporter(String prefix, String graphiteHost) {
    LOG.info("Configuring Graphite reporter. Sendig data to host:port {}", graphiteHost);
    HostAndPort addr = HostAndPort.fromString(graphiteHost);

    final Graphite graphite = new Graphite(
            new InetSocketAddress(addr.getHostText(), addr.getPort()));

    return GraphiteReporter.forRegistry(metrics)
            .prefixedWith(prefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);
}
 
開發者ID:apache,項目名稱:incubator-omid,代碼行數:15,代碼來源:CodahaleMetricsProvider.java

示例9: getHost

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/**
 * Returns the hostname (but not the port) the specified request for both HTTP and HTTPS requests.  The request may reflect
 * modifications from this or other filters. This filter instance must be currently handling the specified request;
 * otherwise the results are undefined.
 *
 * @param modifiedRequest a possibly-modified version of the request currently being processed
 * @return hostname of the specified request, without the port
 */
public String getHost(HttpRequest modifiedRequest) {
    String serverHost;
    if (isHttps()) {
        HostAndPort hostAndPort = HostAndPort.fromString(getHttpsRequestHostAndPort());
        serverHost = hostAndPort.getHostText();
    } else {
        serverHost = HttpUtil.getHostFromRequest(modifiedRequest);
    }
    return serverHost;
}
 
開發者ID:misakuo,項目名稱:Dream-Catcher,代碼行數:19,代碼來源:HttpsAwareFiltersAdapter.java

示例10: proxyToServerResolutionSucceeded

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@Override
public void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress) {
    // the address *should* always be resolved at this point
    InetAddress resolvedAddress = resolvedRemoteAddress.getAddress();

    if (resolvedAddress != null) {
        // place the resolved host into the hostname cache, so subsequent requests will be able to identify the IP address
        HostAndPort parsedHostAndPort = HostAndPort.fromString(serverHostAndPort);
        String host = parsedHostAndPort.getHostText();

        if (host != null && !host.isEmpty()) {
            resolvedAddresses.put(host, resolvedAddress.getHostAddress());
        }
    }
}
 
開發者ID:misakuo,項目名稱:Dream-Catcher,代碼行數:16,代碼來源:ResolvedHostnameCacheFilter.java

示例11: createFrom

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/**
 * Parse a {@link SocketAddress} from the given string.
 */
public static SocketAddress createFrom(String value) {
  if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
    // Unix Domain Socket address.
    // Create the underlying file for the Unix Domain Socket.
    String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
    File file = new File(filePath);
    if (!file.isAbsolute()) {
      throw new IllegalArgumentException("File path must be absolute: " + filePath);
    }
    try {
      if (file.createNewFile()) {
        // If this application created the file, delete it when the application exits.
        file.deleteOnExit();
      }
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
    // Create the SocketAddress referencing the file.
    return new DomainSocketAddress(file);
  } else {
    // Standard TCP/IP address.
    HostAndPort hostAndPort = HostAndPort.fromString(value);
    checkArgument(hostAndPort.hasPort(),
        "Address must be a unix:// path or be in the form host:port. Got: %s", value);
    return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:31,代碼來源:SocketAddressFactory.java

示例12: extractServerAddresses

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
private ServerAddress[] extractServerAddresses(MongoClientURI mongoClientURI) {
    final List<String> hosts = mongoClientURI.getHosts();
    final List<ServerAddress> serverAddresses = new ArrayList<>(hosts.size());
    for (String host : hosts) {
        final HostAndPort hostAndPort = HostAndPort.fromString(host).withDefaultPort(ServerAddress.defaultPort());
        final ServerAddress serverAddress = new ServerAddress(hostAndPort.getHostText(), hostAndPort.getPort());
        serverAddresses.add(serverAddress);
    }
    return serverAddresses.toArray(new ServerAddress[serverAddresses.size()]);
}
 
開發者ID:graylog-labs,項目名稱:graylog-plugin-metrics-reporter,代碼行數:11,代碼來源:MongoDBReporterProvider.java

示例13: forSeedsAndPort

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/** Note: <code>seeds</code> may be a single host or comma-delimited list. */
public static CassandraThriftFacade forSeedsAndPort(String seeds, int defaultPort) {
    final String seed = seeds.contains(",") ? seeds.substring(0, seeds.indexOf(',')) : seeds;
    HostAndPort host = HostAndPort.fromString(seed).withDefaultPort(defaultPort);
    return new CassandraThriftFacade(new TFramedTransport(new TSocket(host.getHostText(), host.getPort())));
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:7,代碼來源:CassandraThriftFacade.java

示例14: newCqlDriverBuilder

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
private com.datastax.driver.core.Cluster.Builder newCqlDriverBuilder(ConnectionPoolConfiguration poolConfig,
                                                                     MetricRegistry metricRegistry) {
    performHostDiscovery(metricRegistry);

    String[] seeds = _seeds.split(",");
    List<String> contactPoints = Lists.newArrayListWithCapacity(seeds.length);

    // Each seed may be a host name or a host name and port (e.g.; "1.2.3.4" or "1.2.3.4:9160").  These need
    // to be converted into host names only.
    for (String seed : seeds) {
        HostAndPort hostAndPort = HostAndPort.fromString(seed);
        seed = hostAndPort.getHostText();
        if (hostAndPort.hasPort()) {
            if (hostAndPort.getPort() == _thriftPort) {
                _log.debug("Seed {} found using RPC port; swapping for native port {}", seed, _cqlPort);
            } else if (hostAndPort.getPort() != _cqlPort) {
                throw new IllegalArgumentException(String.format(
                        "Seed %s found with invalid port %s.  The port must match either the RPC (thrift) port %s " +
                        "or the native (CQL) port %s", seed, hostAndPort.getPort(), _thriftPort, _cqlPort));
            }
        }

        contactPoints.add(seed);
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    if (poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).isPresent()) {
        poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, poolConfig.getMaxConnectionsPerHost().or(getMaxConnectionsPerHost()).get());
    }
    if (poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).isPresent()) {
        poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, poolConfig.getCoreConnectionsPerHost().or(getCoreConnectionsPerHost()).get());
    }

    SocketOptions socketOptions = new SocketOptions();
    if (poolConfig.getConnectTimeout().or(getConnectTimeout()).isPresent()) {
        socketOptions.setConnectTimeoutMillis(poolConfig.getConnectTimeout().or(getConnectTimeout()).get());
    }
    if (poolConfig.getSocketTimeout().or(getSocketTimeout()).isPresent()) {
        socketOptions.setReadTimeoutMillis(poolConfig.getSocketTimeout().or(getSocketTimeout()).get());
    }

    AuthProvider authProvider = _authenticationCredentials != null
            ? new PlainTextAuthProvider(_authenticationCredentials.getUsername(), _authenticationCredentials.getPassword())
            : AuthProvider.NONE;

    return com.datastax.driver.core.Cluster.builder()
            .addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
            .withPort(_cqlPort)
            .withPoolingOptions(poolingOptions)
            .withSocketOptions(socketOptions)
            .withRetryPolicy(Policies.defaultRetryPolicy())
            .withAuthProvider(authProvider);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:54,代碼來源:CassandraConfiguration.java

示例15: 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));
}
 
開發者ID:graylog-labs,項目名稱:graylog-plugin-metrics-reporter,代碼行數:6,代碼來源:StatsdProvider.java


注:本文中的com.google.common.net.HostAndPort.getHostText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。