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

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

Introduction

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

Prototype

public static HostAndPort fromString(String hostPortString) 

Source Link

Document

Split a freeform string into a host and port, without strict validation.

Usage

From source file:io.imply.druid.hadoop.DruidInputFormat.java

public static HostAndPort getCoordinatorHost(final Configuration conf) {
    final String s = Preconditions.checkNotNull(conf.get(CONF_COORDINATOR_HOST), CONF_COORDINATOR_HOST);
    return HostAndPort.fromString(s);
}

From source file:org.mayocat.shop.application.MayocatShopService.java

@Override
public void run(MayocatShopSettings configuration, Environment environment) throws Exception {
    super.run(configuration, environment);

    if (configuration.getDevelopmentEnvironment().isEnabled()) {
        HostAndPort hp = HostAndPort.fromString(configuration.getSiteSettings().getDomainName());
        swaggerDropwizard.onRun(configuration, environment, hp.getHostText(), hp.getPort());
    }//from w  w w .jav  a 2 s . c o m
}

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   www.  j  a v a 2 s  .  co m
 * @return socketAddress
 */
public static InetSocketAddress inetAddressOf(String address) {

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

From source file:com.yahoo.omid.tso.ZKModule.java

@Provides
@Singleton/*from w w  w .  j a v  a 2 s .com*/
@Named(TSO_HOST_AND_PORT_KEY)
String provideTSOHostAndPort() throws SocketException, UnknownHostException {
    // Build TSO host:port string and validate it
    final String tsoNetIfaceName = config.getNetworkIface();
    InetAddress addr = getIPAddressFromNetworkInterface(tsoNetIfaceName);
    final int tsoPort = config.getPort();

    String tsoHostAndPortAsString = addr.getHostAddress() + ":" + tsoPort;
    try {
        HostAndPort.fromString(tsoHostAndPortAsString);
    } catch (IllegalArgumentException e) {
        LOG.error("Cannot parse TSO host:port string {}", tsoHostAndPortAsString);
        throw e;
    }
    return tsoHostAndPortAsString;
}

From source file:brooklyn.networking.vclouddirector.natservice.resources.NatServiceResource.java

@Override
public String openPortForwarding(String endpoint, String vDC, String identity, String credential,
        String protocol, String original, String originalPortRange, String translated) {
    LOG.info("creating nat rule {} {} -> {}, on {} @ {} (vDC {})",
            new Object[] { protocol, original, translated, identity, endpoint, vDC });
    HostAndPort originalHostAndPort = HostAndPort.fromString(original);
    HostAndPort translatedHostAndPort = HostAndPort.fromString(translated);
    Preconditions.checkArgument(translatedHostAndPort.hasPort(), "translated %s must include port", translated);
    try {//ww w .  j  a  v a2 s .c o m
        HostAndPort result = dispatcher().openPortForwarding(endpoint, vDC, identity, credential,
                new PortForwardingConfig().protocol(Protocol.valueOf(protocol.toUpperCase()))
                        .publicEndpoint(originalHostAndPort)
                        .publicPortRange(Strings.isBlank(originalPortRange) ? null
                                : PortRanges.fromString(originalPortRange))
                        .targetEndpoint(translatedHostAndPort));

        return result.toString();
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
}

From source file:com.basho.riak.presto.RiakClient.java

@Inject
public RiakClient(RiakConfig config, ObjectMapper objectMapper) //}, JsonCodec<Map<String, List<PRTable>>> catalogCodec)
        throws IOException, InterruptedException {
    this.config = checkNotNull(config, "config is null");
    this.objectMapper = checkNotNull(objectMapper, "om is null");

    this.hosts = checkNotNull(config.getHost());
    log.info("Riak Config: %s", hosts);

    HostAndPort hp = HostAndPort.fromString(hosts);

    RiakNode node = new RiakNode.Builder().withRemoteAddress(hp.getHostText())
            .withRemotePort(hp.getPortOrDefault(config.getPort())).withMaxConnections(10)
            .withConnectionTimeout(CONNECTION_TIMEOUT_MIL).build();
    cluster = RiakCluster.builder(Arrays.asList(node)).build();

    //final String hosts = config.getHosts();
    this.schemas = Arrays.asList("md", "t");
    //String json = Resources.toString(metadataUri.toURL(), Charsets.UTF_8);
    //Map<String, List<PRTable>> catalog = catalogCodec.fromJson(json);
    //this.schemas = ImmutableMap.copyOf(transformValues(catalog, resolveAndIndexTables(metadataUri)));
    cluster.start();/*from  w w w. j  a  v  a 2s  .  c  o  m*/
    // insert your names;
    // TODO: how do we unregister when presto node shuts down?
    // register();
}

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. j  a  v a 2s.com

    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.graylog.plugins.metrics.mongodb.providers.MongoDBReporterProvider.java

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);
    }//from ww w.j a  va2 s  . c  o  m
    return serverAddresses.toArray(new ServerAddress[serverAddresses.size()]);
}

From source file:com.pingcap.tikv.TiSession.java

public synchronized ManagedChannel getChannel(String addressStr) {
    ManagedChannel channel = connPool.get(addressStr);
    if (channel == null) {
        HostAndPort address;//from  www .  java 2 s .c  o m
        try {
            address = HostAndPort.fromString(addressStr);
        } catch (Exception e) {
            throw new IllegalArgumentException("failed to form address");
        }
        // Channel should be lazy without actual connection until first call
        // So a coarse grain lock is ok here
        channel = ManagedChannelBuilder.forAddress(address.getHostText(), address.getPort())
                .maxInboundMessageSize(conf.getMaxFrameSize()).usePlaintext(true)
                .idleTimeout(60, TimeUnit.SECONDS).build();
        connPool.put(addressStr, channel);
    }
    return channel;
}

From source file:hm.binkley.util.XPropsConverter.java

public XPropsConverter() {
    register("address", value -> {
        final HostAndPort parsed = HostAndPort.fromString(value).requireBracketsForIPv6();
        return createUnresolved(parsed.getHostText(), parsed.getPort());
    });/*ww w.j  a  v  a 2 s .co  m*/
    register("bundle", ResourceBundle::getBundle);
    register("byte", Byte::valueOf);
    register("class", Class::forName);
    register("date", LocalDate::parse);
    register("decimal", BigDecimal::new);
    register("double", Double::valueOf);
    register("duration", Duration::parse);
    register("file", File::new);
    register("float", Float::valueOf);
    register("inet", InetAddress::getByName);
    register("int", Integer::valueOf);
    register("integer", BigInteger::new);
    register("long", Long::valueOf);
    register("path", Paths::get);
    register("period", Period::parse);
    register("regex", Pattern::compile);
    register("resource",
            value -> new DefaultResourceLoader(currentThread().getContextClassLoader()).getResource(value));
    register("resource*",
            value -> asList(new PathMatchingResourcePatternResolver(currentThread().getContextClassLoader())
                    .getResources(value)));
    register("short", Short::valueOf);
    register("time", LocalDateTime::parse);
    register("timestamp", Instant::parse);
    register("tz", TimeZone::getTimeZone);
    register("uri", URI::create);
    register("url", URL::new);
}