Example usage for com.google.common.net HostSpecifier fromValid

List of usage examples for com.google.common.net HostSpecifier fromValid

Introduction

In this page you can find the example usage for com.google.common.net HostSpecifier fromValid.

Prototype

public static HostSpecifier fromValid(String specifier) 

Source Link

Document

Returns a HostSpecifier built from the provided specifier , which is already known to be valid.

Usage

From source file:com.bennavetta.aeneas.zookeeper.node.ZooKeeper.java

public void configure() throws IOException, ZkException {
    LOG.info("Configuring ZooKeeper installation in {}", installDir);

    configuration = new Configuration();
    configuration.addDefaults();/*www.  j  a v  a  2 s. c  o  m*/
    configuration.addFromEnvironment();

    configuration.addServers(registry);
    configuration.setMyId(Util.obtainId(idGenerator, configuration));

    String serverAddress = Networking.getLocalAddress().getHostAddress();

    int peerPort = Integer.parseInt(System.getenv().getOrDefault("PEER_PORT", "2888"));
    int electionPort = Integer.parseInt(System.getenv().getOrDefault("ELECTION_PORT", "3888"));
    int clientPort = Integer.parseInt(System.getenv().getOrDefault("CLIENT_PORT", "2181"));

    server = new ZkServer(configuration.getMyId(), HostSpecifier.fromValid(serverAddress), Role.defaultRole(),
            peerPort, electionPort, clientPort);

    configuration.setDynamic("server." + server.getId(), server.toConnectionSpec());

    Path configRoot = installDir.resolve("conf");
    Files.createDirectories(configRoot);

    configuration.writeId();
    configuration.writeConfiguration(configRoot.resolve("zoo.cfg"), configRoot.resolve("zoo.cfg.dynamic"));

}

From source file:com.eucalyptus.blockstorage.san.common.entities.SANInfo.java

public static List<SANInfo.Path> parsePaths(String paths) {
    if (Strings.isNullOrEmpty(paths)) {
        throw new IllegalArgumentException("Empty paths");
    }/*from ww w .j  a v  a2s. c  o  m*/
    String[] splitPaths = paths.split(PATH_SEPARATOR);
    if (splitPaths == null || splitPaths.length < 1) {
        throw new IllegalArgumentException("Invalid paths " + paths);
    }
    List<SANInfo.Path> parsed = Lists.newArrayList();
    for (String path : splitPaths) {
        String[] splitOnePath = path.split(PATH_FIELD_SEPARATOR);
        if (splitOnePath == null || splitOnePath.length < 1 || splitOnePath.length > 2) {
            throw new IllegalArgumentException("Invalid path " + path);
        }
        String iface;
        String ip;
        if (splitOnePath.length == 1) {
            iface = "";
            ip = splitOnePath[0];
        } else {
            iface = splitOnePath[0];
            ip = splitOnePath[1];
        }
        HostSpecifier.fromValid(ip);
        parsed.add(new SANInfo.Path(iface, ip));
    }
    return parsed;
}