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:org.robotninjas.barge.NettyReplica.java

@Nonnull
public static NettyReplica fromString(@Nonnull String info) {
    try {//from w ww .j  a va2 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.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));
    }/*ww w . java 2 s  .c  o m*/
    return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
}

From source file:io.mandrel.transport.thrift.MandrelCoercions.java

@FromThrift
public static HostAndPort fromThrift(String value) {
    return HostAndPort.fromString(value);
}

From source file:io.v.impl.google.naming.EndpointImpl.java

public static Endpoint fromString(String s) {
    Matcher matcher = hostPortPattern.matcher(s);
    if (matcher.matches()) {
        List<String> blessings = new ArrayList<>(1);
        // If the endpoint does not end in a @, it must be in [blessing@]host:port format.
        HostAndPort hostPort = HostAndPort.fromString(matcher.group(matcher.groupCount()));
        if (matcher.group(1) != null) {
            blessings.add(matcher.group(1));
        }/*from  ww  w.  ja  v a2  s.com*/

        return new EndpointImpl("", hostPort.toString(), ImmutableList.<String>of(), RoutingId.NULL_ROUTING_ID,
                blessings, true, false);
    }

    if (s.endsWith("@@")) {
        s = s.substring(0, s.length() - 2);
    }
    if (s.startsWith("@")) {
        s = s.substring(1, s.length());
    }

    List<String> parts = Splitter.on('@').splitToList(s);
    int version = Integer.parseInt(parts.get(0));
    switch (version) {
    case 6:
        return fromV6String(parts);
    default:
        return null;
    }
}

From source file:org.apache.accumulo.server.master.state.SuspendingTServer.java

public static SuspendingTServer fromValue(Value value) {
    String valStr = value.toString();
    String[] parts = valStr.split("[|]", 2);
    return new SuspendingTServer(HostAndPort.fromString(parts[0]), Long.parseLong(parts[1]));
}

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

public static TiConfiguration createDefault(List<String> pdAddrs) {
    TiConfiguration conf = new TiConfiguration();
    conf.pdAddrs = ImmutableList.copyOf(Iterables.transform(ImmutableSet.copyOf(pdAddrs).asList(),
            addStr -> HostAndPort.fromString(addStr)));
    return conf;//from  www  .jav a  2  s. com
}

From source file:org.seedstack.seed.core.internal.configuration.HostAndPortMapper.java

@Override
public Object map(TreeNode treeNode, Type type) {
    return HostAndPort.fromString(treeNode.value());
}

From source file:google.registry.tools.params.HostAndPortParameter.java

@Override
public HostAndPort convert(String value) {
    return HostAndPort.fromString(value);
}

From source file:brooklyn.util.net.UserAndHostAndPort.java

/**
 * Split a string of the form myuser@myhost:1234 into a user, host and port.
 *  /*from ww w  . j a va 2  s  . co  m*/
 * @param str The input string to parse.
 * @return    If parsing was successful, a populated UserAndHostAndPort object.
 * @throws IllegalArgumentException
 *             if nothing meaningful could be parsed.
 */
public static UserAndHostAndPort fromString(String str) {
    int userEnd = str.indexOf("@");
    if (userEnd < 0)
        throw new IllegalArgumentException("User missing (no '@' in " + str);
    return new UserAndHostAndPort(str.substring(0, userEnd).trim(),
            HostAndPort.fromString(str.substring(userEnd + 1).trim()));
}

From source file:org.apache.hadoop.hbase.net.Address.java

public static Address fromString(String hostnameAndPort) {
    return new Address(HostAndPort.fromString(hostnameAndPort));
}