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:org.apache.accumulo.core.rpc.TTimeoutTransport.java

public static TTransport create(HostAndPort addr, long timeoutMillis) throws IOException {
    return create(new InetSocketAddress(addr.getHostText(), addr.getPort()), timeoutMillis);
}

From source file:org.robotninjas.barge.Replica.java

@Nonnull
public static Replica fromString(@Nonnull String info) {
    try {//from   ww  w . j  a  v a  2 s . c  o  m
        checkNotNull(info);
        HostAndPort hostAndPort = HostAndPort.fromString(info);
        InetAddress addr = InetAddress.getByName(hostAndPort.getHostText());
        InetSocketAddress saddr = new InetSocketAddress(addr, hostAndPort.getPort());
        return new Replica(saddr);
    } catch (UnknownHostException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.robotninjas.barge.NettyReplica.java

@Nonnull
public static NettyReplica fromString(@Nonnull String info) {
    try {/*w ww . ja  v a2 s .c  o  m*/
        checkNotNull(info);
        HostAndPort hostAndPort = HostAndPort.fromString(info);
        InetAddress addr = InetAddress.getByName(hostAndPort.getHostText());
        InetSocketAddress saddr = new InetSocketAddress(addr, hostAndPort.getPort());
        return new NettyReplica(saddr);
    } catch (UnknownHostException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.apache.slider.core.zk.ZookeeperUtils.java

/**
 * Build up to a hosts only list// www  .ja  v  a2 s.c  o  m
 * @param hostAndPorts
 * @return a list of the hosts only
 */
public static String buildHostsOnlyList(List<HostAndPort> hostAndPorts) {
    StringBuilder sb = new StringBuilder();
    for (HostAndPort hostAndPort : hostAndPorts) {
        sb.append(hostAndPort.getHostText()).append(",");
    }
    if (sb.length() > 0) {
        sb.delete(sb.length() - 1, sb.length());
    }
    return sb.toString();
}

From source file:org.opendaylight.protocol.util.InetSocketAddressUtil.java

public static InetSocketAddress getInetSocketAddress(final String hostPortString, final Integer defaultPort) {
    final HostAndPort hostAndPort = HostAndPort.fromString(hostPortString);
    if (defaultPort != null) {
        return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPortOrDefault(defaultPort));
    }/*from w  w w  .  j  av  a2  s .  c  o m*/
    return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
}

From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java

private static Iterable<InetSocketAddress> getZkAddresses(URI uri) {
    String zkServers = getZKServersFromDLUri(uri);
    String[] zkServerList = StringUtils.split(zkServers, ',');
    ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder();
    for (String zkServer : zkServerList) {
        HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181);
        builder.add(InetSocketAddress.createUnresolved(hostAndPort.getHostText(), hostAndPort.getPort()));
    }//from w ww .  ja v  a  2s .c o  m
    return builder.build();
}

From source file:brooklyn.entity.webapp.WebAppServiceMethods.java

public static String inferBrooklynAccessibleRootUrl(Entity entity) {
    if (isProtocolEnabled(entity, "https")) {
        Integer rawPort = entity.getAttribute(HTTPS_PORT);
        checkNotNull(rawPort, "HTTPS_PORT sensors not set for %s; is an acceptable port available?", entity);
        HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, rawPort);
        return String.format("https://%s:%s/", hp.getHostText(), hp.getPort());
    } else if (isProtocolEnabled(entity, "http")) {
        Integer rawPort = entity.getAttribute(HTTP_PORT);
        checkNotNull(rawPort, "HTTP_PORT sensors not set for %s; is an acceptable port available?", entity);
        HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, rawPort);
        return String.format("http://%s:%s/", hp.getHostText(), hp.getPort());
    } else {/*from   w ww .j  a  va 2s . c o  m*/
        throw new IllegalStateException("HTTP and HTTPS protocols not enabled for " + entity
                + "; enabled protocols are " + getEnabledProtocols(entity));
    }
}

From source file:zipkin.storage.cassandra3.DefaultSessionFactory.java

static List<InetSocketAddress> parseContactPoints(Cassandra3Storage cassandra) {
    List<InetSocketAddress> result = new LinkedList<>();
    for (String contactPoint : cassandra.contactPoints.split(",")) {
        HostAndPort parsed = HostAndPort.fromString(contactPoint);
        result.add(new InetSocketAddress(parsed.getHostText(), parsed.getPortOrDefault(9042)));
    }/*from  w  ww.j  ava2s  .c  o m*/
    return result;
}

From source file:org.dcache.utils.net.InetSocketAddresses.java

/**
 * Convert a {@link String} in a form <code>host:port</code>
 * into corresponding {@link InetSocketAddress}.
 * @param address/*from   w  w  w  .ja v a2  s. c o  m*/
 * @return socketAddress
 */
public static InetSocketAddress inetAddressOf(String address) {

    HostAndPort hostAndPort = HostAndPort.fromString(address);
    return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
}

From source file:org.apache.phoenix.end2end.LoadBalancerEnd2EndIT.java

private static void createNodeForTesting(List<HostAndPort> pqsNodes) throws Exception {
    for (HostAndPort pqs : pqsNodes) {
        registry.registerServer(LOAD_BALANCER_CONFIGURATION, pqs.getPort(), zkConnectString, pqs.getHostText());
    }//  w  ww  .  j  ava 2  s.c om
    curatorFramework.getChildren().forPath(LOAD_BALANCER_CONFIGURATION.getParentPath()).size();
}