Example usage for com.google.common.net HostAndPort getHostText

List of usage examples for com.google.common.net HostAndPort getHostText

Introduction

In this page you can find the example usage for com.google.common.net HostAndPort getHostText.

Prototype

public String getHostText() 

Source Link

Document

Returns the portion of this HostAndPort instance that should represent the hostname or IPv4/IPv6 literal.

Usage

From source file:zipkin.dependencies.cassandra.CassandraDependenciesJob.java

static String parseHosts(String contactPoints) {
    List<String> result = new LinkedList<>();
    for (String contactPoint : contactPoints.split(",")) {
        HostAndPort parsed = HostAndPort.fromString(contactPoint);
        result.add(parsed.getHostText());
    }/*from   ww  w  . ja v a2s  . c o m*/
    return Joiner.on(',').join(result);
}

From source file:com.dasasian.chok.util.ZkChokUtil.java

public static ZkServer startZkServer(ZkConfiguration conf) {
    String server = Iterables.getOnlyElement(COMMA_SPLITTER.split(conf.getServers()));
    HostAndPort hostAndPort = HostAndPort.fromString(server);
    if (!hostAndPort.hasPort()) {
        throw new IllegalArgumentException("No Port Specified for ZkServer");
    } else {/*from  w  ww  .  j a v  a2  s .  co  m*/
        String host = hostAndPort.getHostText();
        //            if (!host.equals("127.0.0.1") && !host.equals("localhost")) {
        //                throw new IllegalArgumentException("Attempting to start ZkServer remotely on " + host + " valid values are 127.0.0.1 or localhost");
        //            }
    }
    ZkServer zkServer = new ZkServer(conf.getDataDir(), conf.getLogDataDir(), new DefaultNameSpaceImpl(conf),
            hostAndPort.getPort(), conf.getTickTime());
    zkServer.start();
    return zkServer;
}

From source file:org.sonar.server.es.EsClientProvider.java

private static void addHostToClient(HostAndPort host, TransportClient client) {
    try {/* www. ja  v  a2s.  co m*/
        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHostText()),
                host.getPortOrDefault(9001)));
    } catch (UnknownHostException e) {
        throw new IllegalStateException("Can not resolve host [" + host + "]", e);
    }
}

From source file:org.sonar.application.config.ClusterSettings.java

private static InetAddress convertToInetAddress(String text, String key) {
    InetAddress inetAddress;/*w  w w  .  j  av a2s.  co m*/
    HostAndPort hostAndPort = HostAndPort.fromString(text);
    if (!InetAddresses.isInetAddress(hostAndPort.getHostText())) {
        try {
            inetAddress = InetAddress.getByName(hostAndPort.getHostText());
        } catch (UnknownHostException e) {
            throw new MessageException(format("The interface address [%s] of [%s] cannot be resolved : %s",
                    text, key, e.getMessage()));
        }
    } else {
        inetAddress = forString(hostAndPort.getHostText());
    }

    return inetAddress;
}

From source file:com.facebook.presto.hive.HiveMetastoreClientFactory.java

private static Socket createSocksSocket(HostAndPort proxy) {
    SocketAddress address = InetSocketAddress.createUnresolved(proxy.getHostText(), proxy.getPort());
    return new Socket(new Proxy(Proxy.Type.SOCKS, address));
}

From source file:org.apache.brooklyn.entity.nosql.mongodb.MongoDBTestHelper.java

private static MongoClient clientForServer(AbstractMongoDBServer server) {
    try {/*  w  w w.ja va  2s.  c  o  m*/
        HostAndPort hap = BrooklynAccessUtils.getBrooklynAccessibleAddress(server,
                server.getAttribute(MongoDBServer.PORT));
        return new MongoClient(hap.getHostText(), hap.getPort());
    } catch (Exception e) {
        // Fail whatever test called this method.
        throw Throwables.propagate(e);
    }
}

From source file:brooklyn.entity.nosql.mongodb.MongoDBTestHelper.java

private static MongoClient clientForServer(AbstractMongoDBServer server) {
    try {//from  ww  w  .j a va 2 s .  c  om
        HostAndPort hap = BrooklynAccessUtils.getBrooklynAccessibleAddress(server,
                server.getAttribute(MongoDBServer.PORT));
        return new MongoClient(hap.getHostText(), hap.getPort());
    } catch (UnknownHostException e) {
        // Fail whatever test called this method.
        throw Throwables.propagate(e);
    }
}

From source file:com.facebook.presto.benchmark.driver.BenchmarkDriverOptions.java

private static URI parseServer(String server) {
    server = server.toLowerCase(ENGLISH);
    if (server.startsWith("http://") || server.startsWith("https://")) {
        return URI.create(server);
    }//w  ww  . jav a  2 s. co  m

    HostAndPort host = HostAndPort.fromString(server);
    try {
        return new URI("http", null, host.getHostText(), host.getPortOrDefault(80), null, null, null);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.kududb.client.ProtobufHelper.java

/**
 * Convert a {@link com.google.common.net.HostAndPort} to {@link org.kududb.Common.HostPortPB}
 * protobuf message for serialization.//  w w  w.j a va 2  s. c  o m
 * @param hostAndPort The host and port object. Both host and port must be specified.
 * @return An initialized HostPortPB object.
 */
public static Common.HostPortPB hostAndPortToPB(HostAndPort hostAndPort) {
    return Common.HostPortPB.newBuilder().setHost(hostAndPort.getHostText()).setPort(hostAndPort.getPort())
            .build();
}

From source file:com.netflix.metacat.connector.hive.client.thrift.HiveMetastoreClientFactory.java

private static Socket createSocksSocket(final HostAndPort proxy) {
    final SocketAddress address = InetSocketAddress.createUnresolved(proxy.getHostText(), proxy.getPort());
    return new Socket(new Proxy(Proxy.Type.SOCKS, address));
}