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:com.facebook.nifty.client.AbstractClientConnector.java

public AbstractClientConnector(HostAndPort address) {
    this(new InetSocketAddress(address.getHostText(), address.getPort()));
}

From source file:org.graylog.plugins.metrics.statsd.providers.StatsdProvider.java

@Override
public Statsd get() {
    final HostAndPort address = configuration.getAddress();
    return new Statsd(address.getHostText(), address.getPortOrDefault(8125));
}

From source file:dk.dma.ais.reader.AisReaderMXBean.java

public String getHosts() {
    List<String> l = new ArrayList<>();
    for (HostAndPort hap : reader.hosts) {
        l.add(hap.getHostText());
    }//from ww  w  .  j  a  v  a2  s .c  o m
    return Joiner.on(',').join(l);
}

From source file:org.apache.accumulo.server.util.LocalityCheck.java

private void addBlocks(VolumeManager fs, String host, ArrayList<String> files, Map<String, Long> totalBlocks,
        Map<String, Long> localBlocks) throws Exception {
    long allBlocks = 0;
    long matchingBlocks = 0;
    if (!totalBlocks.containsKey(host)) {
        totalBlocks.put(host, 0L);//from w  w w.  j  av a  2 s  .  c  o m
        localBlocks.put(host, 0L);
    }
    for (String file : files) {
        Path filePath = new Path(file);
        FileSystem ns = fs.getVolumeByPath(filePath).getFileSystem();
        FileStatus fileStatus = ns.getFileStatus(filePath);
        BlockLocation[] fileBlockLocations = ns.getFileBlockLocations(fileStatus, 0, fileStatus.getLen());
        for (BlockLocation blockLocation : fileBlockLocations) {
            allBlocks++;
            for (String location : blockLocation.getHosts()) {
                HostAndPort hap = HostAndPort.fromParts(location, 0);
                if (hap.getHostText().equals(host)) {
                    matchingBlocks++;
                    break;
                }
            }
        }
    }
    totalBlocks.put(host, allBlocks + totalBlocks.get(host));
    localBlocks.put(host, matchingBlocks + localBlocks.get(host));
}

From source file:com.bazaarvoice.dropwizard.caching.memcached.MemcachedResponseStoreFactory.java

/**
 * InetSocketAddress deserialization is broken in jackson 2.3.3, so using HostAndPort instead.
 * See: https://github.com/FasterXML/jackson-databind/issues/444
 * Fix will be in 2.3.4, but not released yet (as of 2014-Jul-10).
 *///w w w  .ja  v  a2  s.  c om
@JsonProperty
void setServers(HostAndPort[] servers) {
    checkNotNull(servers);

    _servers = FluentIterable.from(Arrays.asList(servers))
            .transform(new Function<HostAndPort, InetSocketAddress>() {
                public InetSocketAddress apply(HostAndPort input) {
                    return new InetSocketAddress(input.getHostText(), input.getPort());
                }
            }).toList();
}

From source file:org.jclouds.predicates.InetSocketAddressConnect.java

@Override
public boolean apply(HostAndPort socketA) {
    InetSocketAddress socketAddress = new InetSocketAddress(socketA.getHostText(), socketA.getPort());
    Socket socket = null;// w w w .  j  a  v  a2 s.c  o  m
    try {
        logger.trace("testing socket %s", socketAddress);
        socket = new Socket(
                proxyForURI.apply(URI.create("socket://" + socketA.getHostText() + ":" + socketA.getPort())));
        socket.setReuseAddress(false);
        socket.setSoLinger(false, 1);
        socket.setSoTimeout(timeout);
        socket.connect(socketAddress, timeout);
    } catch (IOException e) {
        return false;
    } finally {
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException ioe) {
                // no work to do
            }
        }
    }
    return true;
}

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

/**
 * Create a metastore client connected to the Hive metastore.
 * <p>//www. j  av  a  2  s .com
 * As per Hive HA metastore behavior, return the first metastore in the list
 * list of available metastores (i.e. the default metastore) if a connection
 * can be made, else try another of the metastores at random, until either a
 * connection succeeds or there are no more fallback metastores.
 */
@Override
public HiveMetastoreClient createMetastoreClient() {
    List<HostAndPort> metastores = new ArrayList<>(addresses);
    Collections.shuffle(metastores.subList(1, metastores.size()));

    TTransportException lastException = null;
    for (HostAndPort metastore : metastores) {
        try {
            return clientFactory.create(metastore.getHostText(), metastore.getPort());
        } catch (TTransportException e) {
            lastException = e;
        }
    }

    throw new PrestoException(HIVE_METASTORE_ERROR, "Failed connecting to Hive metastore: " + addresses,
            lastException);
}

From source file:com.google.devtools.kythe.platform.shared.RemoteFileData.java

public RemoteFileData(String addr) {
    HostAndPort hp = HostAndPort.fromString(addr);
    ChannelImpl channel = NettyChannelBuilder.forAddress(new InetSocketAddress(hp.getHostText(), hp.getPort()))
            .build();/*from  w ww .  j  av a  2  s.c o  m*/
    stub = FileDataServiceGrpc.newStub(channel);
}

From source file:com.spotify.helios.servicescommon.DockerHost.java

private DockerHost(final String endpoint) {
    final String stripped = endpoint.replaceAll(".*://", "");
    final HostAndPort hostAndPort = HostAndPort.fromString(stripped);
    final String hostText = hostAndPort.getHostText();
    this.port = hostAndPort.getPortOrDefault(defaultPort());
    this.address = Strings.isNullOrEmpty(hostText) ? DEFAULT_HOST : hostText;
    this.host = address + ":" + port;
    this.uri = URI.create("http://" + address + ":" + port);
}

From source file:brooklyn.entity.nosql.solr.SolrServerImpl.java

@Override
protected void connectSensors() {
    super.connectSensors();

    HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getSolrPort());

    String solrUri = String.format("http://%s:%d/solr", hp.getHostText(), hp.getPort());
    setAttribute(Attributes.MAIN_URI, URI.create(solrUri));

    httpFeed = HttpFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS).baseUri(solrUri)
            .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200))
                    .onFailureOrException(Functions.constant(false)))
            .build();//from ww  w .j a  v a  2s.c o  m
}