当前位置: 首页>>代码示例>>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;未经允许,请勿转载。