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.hillview.HillviewServerRunner.java

public static void main(String[] args) {
    if (args.length != 1) {
        usage();//from   w  ww  .j  a  va2 s  .  com
        throw new RuntimeException("Incorrect arguments");
    }

    HillviewLogger.initialize("worker", "hillview.log");
    try {
        final IDataSet<Empty> dataSet = new LocalDataSet<Empty>(Empty.getInstance());
        final String hostnameAndPort = args[0];
        final HillviewServer server = new HillviewServer(HostAndPort.fromString(hostnameAndPort), dataSet);
        HillviewLogger.instance.info("Created HillviewServer");
        Thread.currentThread().join();
    } catch (Exception ex) {
        HillviewLogger.instance.error("Caught exception", ex);
    }
}

From source file:org.opendaylight.protocol.pcep.testtool.PCCMock.java

public static void main(final String[] args) throws InterruptedException, ExecutionException {
    Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided.");
    final List<PCEPCapability> caps = new ArrayList<>();
    final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30,
            caps);/*  w ww .j ava  2s. c  o m*/
    final PCEPSessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(proposal, 0);
    final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]);
    final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHostText(),
            serverHostAndPort.getPortOrDefault(12345));
    final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0);

    try (final PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(
            ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry())) {
        pccDispatcher.createClient(serverAddr, -1, new PCEPSessionListenerFactory() {
            @Override
            public PCEPSessionListener getSessionListener() {
                return new SimpleSessionListener();
            }
        }, snf, null, clientAddr).get();
    }
}

From source file:io.codis.nedis.bench.JedisBench.java

public static void main(String[] args) throws InterruptedException {
    Args parsedArgs = new Args();
    CmdLineParser parser = new CmdLineParser(parsedArgs);
    try {//from w  w  w  . j a  v a 2 s  .com
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        parser.printUsage(System.err);
        return;
    }

    AtomicBoolean stop = new AtomicBoolean(false);
    AtomicLong reqCount = new AtomicLong(0);
    ExecutorService executor = Executors.newFixedThreadPool(parsedArgs.threads,
            new ThreadFactoryBuilder().setDaemon(true).build());
    HostAndPort hap = HostAndPort.fromString(parsedArgs.redisAddr);
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(parsedArgs.conns);
    config.setMaxIdle(parsedArgs.conns);
    JedisPool pool = new JedisPool(config, hap.getHostText(), hap.getPort());
    for (int i = 0; i < parsedArgs.threads; i++) {
        executor.execute(new Worker(stop, reqCount, pool, parsedArgs.pipeline));
    }
    long duration = TimeUnit.MINUTES.toNanos(parsedArgs.minutes);
    long startTime = System.nanoTime();
    long prevTime = -1L;
    long prevReqCount = -1L;
    for (;;) {
        long currentTime = System.nanoTime();
        if (currentTime - startTime >= duration) {
            stop.set(true);
            executor.shutdown();
            if (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
                throw new RuntimeException("Can not terminate workers");
            }
            System.out.println(String.format("Test run %d minutes, qps: %.2f", parsedArgs.minutes,
                    (double) reqCount.get() / (currentTime - startTime) * TimeUnit.SECONDS.toNanos(1)));
            pool.close();
            return;
        }
        long currentReqCount = reqCount.get();
        if (prevTime > 0) {
            System.out.println(String.format("qps: %.2f", (double) (currentReqCount - prevReqCount)
                    / (currentTime - prevTime) * TimeUnit.SECONDS.toNanos(1)));
        }
        prevTime = currentTime;
        prevReqCount = currentReqCount;
        Thread.sleep(5000);
    }
}

From source file:com.torodb.standalone.Main.java

public static void main(String[] args) throws Exception {
    Console console = JCommander.getConsole();

    ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
    final CliConfig cliConfig = new CliConfig();
    JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
    jCommander.setColumnSize(Integer.MAX_VALUE);

    if (cliConfig.isHelp()) {
        jCommander.usage();//from   w  ww  .  j  av  a 2s.c  o m
        System.exit(0);
    }

    if (cliConfig.isHelpParam()) {
        console.println(cliBundle.getString("help-param-header"));
        ResourceBundle configBundle = PropertyResourceBundle.getBundle("ConfigMessages");
        ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, configBundle, console, 0);
        System.exit(0);
    }

    final Config config = CliConfigUtils.readConfig(cliConfig);

    if (cliConfig.isPrintConfig()) {
        ConfigUtils.printYamlConfig(config, console);

        System.exit(0);
    }

    if (cliConfig.isPrintXmlConfig()) {
        ConfigUtils.printXmlConfig(config, console);

        System.exit(0);
    }

    configureLogger(cliConfig, config);

    config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {
        @Override
        public void visit(AbstractDerby value) {
            parseToropassFile(value);
        }

        @Override
        public void visit(AbstractPostgres value) {
            parseToropassFile(value);
        }

        public void parseToropassFile(BackendPasswordConfig value) {
            try {
                ConfigUtils.parseToropassFile(value);
            } catch (Exception ex) {
                throw new SystemException(ex);
            }
        }
    });
    if (config.getProtocol().getMongo().getReplication() != null) {
        for (AbstractReplication replication : config.getProtocol().getMongo().getReplication()) {
            if (replication.getAuth().getUser() != null) {
                HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource())
                        .withDefaultPort(27017);
                ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {

                    @Override
                    public void setPassword(String password) {
                        replication.getAuth().setPassword(password);
                    }

                    @Override
                    public String getUser() {
                        return replication.getAuth().getUser();
                    }

                    @Override
                    public Integer getPort() {
                        return syncSource.getPort();
                    }

                    @Override
                    public String getPassword() {
                        return replication.getAuth().getPassword();
                    }

                    @Override
                    public String getMongopassFile() {
                        return config.getProtocol().getMongo().getMongopassFile();
                    }

                    @Override
                    public String getHost() {
                        return syncSource.getHostText();
                    }

                    @Override
                    public String getDatabase() {
                        return replication.getAuth().getSource();
                    }
                });
            }
        }
    }

    if (config.getBackend().isLike(AbstractPostgres.class)) {
        AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);

        if (cliConfig.isAskForPassword()) {
            console.print("Database user " + postgres.getUser() + " password:");
            postgres.setPassword(readPwd());
        }
    } else if (config.getBackend().isLike(AbstractDerby.class)) {
        AbstractDerby derby = config.getBackend().as(AbstractDerby.class);

        if (cliConfig.isAskForPassword()) {
            console.print("Database user " + derby.getUser() + " password:");
            derby.setPassword(readPwd());
        }
    }

    try {
        Clock clock = Clock.systemDefaultZone();
        Service server;
        if (config.getProtocol().getMongo().getReplication() == null
                || config.getProtocol().getMongo().getReplication().isEmpty()) {
            Service toroDbServer = ToroDbBootstrap.createStandaloneService(config, clock);

            toroDbServer.startAsync();
            toroDbServer.awaitRunning();

            server = toroDbServer;
        } else {
            throw new UnsupportedOperationException("Replication not supported yet!");
        }

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            server.stopAsync();
            server.awaitTerminated();
        }));
    } catch (CreationException ex) {
        ex.getErrorMessages().stream().forEach(m -> {
            if (m.getCause() != null) {
                LOGGER.error(m.getCause().getMessage());
            } else {
                LOGGER.error(m.getMessage());
            }
        });
        System.exit(1);
    } catch (Throwable ex) {
        LOGGER.error("Fatal error on initialization", ex);
        Throwable rootCause = Throwables.getRootCause(ex);
        String causeMessage = rootCause.getMessage();
        JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
        System.exit(1);
    }
}

From source file:io.codis.nedis.bench.NedisBench.java

public static void main(String[] args) throws InterruptedException {
    Args parsedArgs = new Args();
    CmdLineParser parser = new CmdLineParser(parsedArgs);
    try {/*from   w w w.  ja  v  a 2s  .c o m*/
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        parser.printUsage(System.err);
        return;
    }

    AtomicBoolean stop = new AtomicBoolean(false);
    AtomicLong reqCount = new AtomicLong(0);
    ExecutorService executor = Executors.newFixedThreadPool(parsedArgs.threads,
            new ThreadFactoryBuilder().setDaemon(true).build());
    HostAndPort hap = HostAndPort.fromString(parsedArgs.redisAddr);
    NedisClient client = NedisUtils.newPooledClient(NedisClientPoolBuilder.create()
            .maxPooledConns(parsedArgs.conns).remoteAddress(hap.getHostText(), hap.getPort()).build());
    for (int i = 0; i < parsedArgs.threads; i++) {
        executor.execute(new Worker(stop, reqCount, client, parsedArgs.pipeline));
    }
    long duration = TimeUnit.MINUTES.toNanos(parsedArgs.minutes);
    long startTime = System.nanoTime();
    long prevTime = -1L;
    long prevReqCount = -1L;
    for (;;) {
        long currentTime = System.nanoTime();
        if (currentTime - startTime >= duration) {
            stop.set(true);
            executor.shutdown();
            if (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
                throw new RuntimeException("Can not terminate workers");
            }
            System.out.println(String.format("Test run %d minutes, qps: %.2f", parsedArgs.minutes,
                    (double) reqCount.get() / (currentTime - startTime) * TimeUnit.SECONDS.toNanos(1)));
            client.close().sync();
            return;
        }
        long currentReqCount = reqCount.get();
        if (prevTime > 0) {
            System.out.println(String.format("qps: %.2f", (double) (currentReqCount - prevReqCount)
                    / (currentTime - prevTime) * TimeUnit.SECONDS.toNanos(1)));
        }
        prevTime = currentTime;
        prevReqCount = currentReqCount;
        Thread.sleep(5000);
    }
}

From source file:com.torodb.stampede.Main.java

public static void main(String[] args) throws Exception {
    try {//from w w  w .j  av a  2  s  .  c  om
        Console console = JCommander.getConsole();

        ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
        final CliConfig cliConfig = new CliConfig();
        JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
        jCommander.setColumnSize(Integer.MAX_VALUE);

        if (cliConfig.isVersion()) {
            BuildProperties buildProperties = new DefaultBuildProperties();
            console.println(buildProperties.getFullVersion());
            System.exit(0);
        }

        if (cliConfig.isHelp()) {
            jCommander.usage();
            System.exit(0);
        }

        if (cliConfig.isHelpParam()) {
            console.println(cliBundle.getString("cli.help-param-header"));
            ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, cliBundle, console, 0);
            System.exit(0);
        }

        cliConfig.addParams();

        final Config config = CliConfigUtils.readConfig(cliConfig);

        if (cliConfig.isPrintConfig()) {
            ConfigUtils.printYamlConfig(config, console);

            System.exit(0);
        }

        if (cliConfig.isPrintXmlConfig()) {
            ConfigUtils.printXmlConfig(config, console);

            System.exit(0);
        }

        if (cliConfig.isPrintParam()) {
            JsonNode jsonNode = ConfigUtils.getParam(config, cliConfig.getPrintParamPath());

            if (jsonNode != null) {
                console.print(jsonNode.asText());
            }

            System.exit(0);
        }

        configureLogger(cliConfig, config);

        config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {
            @Override
            public void visit(AbstractDerby value) {
                parseToropassFile(value);
            }

            @Override
            public void visit(AbstractPostgres value) {
                parseToropassFile(value);
            }

            public void parseToropassFile(BackendPasswordConfig value) {
                try {
                    ConfigUtils.parseToropassFile(value);
                } catch (Exception ex) {
                    throw new SystemException(ex);
                }
            }
        });
        AbstractReplication replication = config.getReplication();
        if (replication.getAuth().getUser() != null) {
            HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
            ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {

                @Override
                public void setPassword(String password) {
                    replication.getAuth().setPassword(password);
                }

                @Override
                public String getUser() {
                    return replication.getAuth().getUser();
                }

                @Override
                public Integer getPort() {
                    return syncSource.getPort();
                }

                @Override
                public String getPassword() {
                    return replication.getAuth().getPassword();
                }

                @Override
                public String getMongopassFile() {
                    return config.getReplication().getMongopassFile();
                }

                @Override
                public String getHost() {
                    return syncSource.getHostText();
                }

                @Override
                public String getDatabase() {
                    return replication.getAuth().getSource();
                }
            });
        }

        if (config.getBackend().isLike(AbstractPostgres.class)) {
            AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);

            if (cliConfig.isAskForPassword()) {
                console.print("Type database user " + postgres.getUser() + "'s password:");
                postgres.setPassword(readPwd());
            }

            if (postgres.getPassword() == null) {
                throw new SystemException("No password provided for database user " + postgres.getUser()
                        + ".\n\n" + "Please add following line to file " + postgres.getToropassFile() + ":\n"
                        + postgres.getHost() + ":" + postgres.getPort() + ":" + postgres.getDatabase() + ":"
                        + postgres.getUser() + ":<password>\n" + "Replace <password> for database user "
                        + postgres.getUser() + "'s password");
            }
        }

        try {
            Clock clock = Clock.systemDefaultZone();

            Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                @SuppressFBWarnings(value = "DM_EXIT", justification = "Since is really hard to stop cleanly all threads when an OOME is thrown we must "
                        + "exit to avoid no more action is performed that could lead to an unespected "
                        + "state")
                public void uncaughtException(Thread t, Throwable e) {
                    if (e instanceof OutOfMemoryError) {
                        try {
                            LOGGER.error("Fatal out of memory: " + e.getLocalizedMessage(), e);
                        } finally {
                            System.exit(1);
                        }
                    }
                }
            });

            Service stampedeService = StampedeBootstrap.createStampedeService(config, clock);

            stampedeService.startAsync();
            stampedeService.awaitTerminated();

            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                stampedeService.stopAsync();
                stampedeService.awaitTerminated();
            }));
        } catch (CreationException ex) {
            ex.getErrorMessages().stream().forEach(m -> {
                if (m.getCause() != null) {
                    LOGGER.error(m.getCause().getMessage());
                } else {
                    LOGGER.error(m.getMessage());
                }
            });
            LogManager.shutdown();
            System.exit(1);
        }
    } catch (Throwable ex) {
        LOGGER.debug("Fatal error on initialization", ex);
        Throwable rootCause = Throwables.getRootCause(ex);
        String causeMessage = rootCause.getMessage();
        LogManager.shutdown();
        JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
        System.exit(1);
    }
}

From source file:org.dcache.nfs.v4.client.Main.java

public static void main(String[] args) throws IOException, OncRpcException, InterruptedException {

    System.out.println("Started the NFS4 Client ....");
    String line;//from www .j  av a 2 s  .  c o m

    Main nfsClient = null;

    final String[] commands = { "mount", "cd", "ls", "lookup", "lookup-fh", "mkdir", "read", "readatonce",
            "filebomb", "remove", "umount", "write", "fs_locations", "getattr", "openbomb", "read-nostate" };

    ConsoleReader reader = new ConsoleReader();
    reader.setPrompt(PROMPT);
    reader.setHistoryEnabled(true);
    reader.addCompleter(new StringsCompleter(commands));

    if (args.length > 0) {
        HostAndPort hp = HostAndPort.fromString(args[0]).withDefaultPort(2049).requireBracketsForIPv6();

        InetSocketAddress serverAddress = new InetSocketAddress(hp.getHostText(), hp.getPort());
        nfsClient = new Main(serverAddress);
        nfsClient.mount("/");
    }

    PrintWriter out = new PrintWriter(reader.getOutput());

    while ((line = reader.readLine()) != null) {
        line = line.trim();
        if (line.length() == 0) {
            continue;
        }

        String[] commandArgs = line.split("[ \t]+");

        try {

            if (commandArgs[0].equals("mount")) {

                String host = commandArgs.length > 1 ? commandArgs[1] : "localhost";
                String root = commandArgs.length > 2 ? commandArgs[2] : "/";
                nfsClient = new Main(InetAddress.getByName(host));
                nfsClient.mount(root);

            } else if (commandArgs[0].equals("umount")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                nfsClient.umount();
                nfsClient = null;

            } else if (commandArgs[0].equals("ls")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length == 2) {
                    nfsClient.readdir(commandArgs[1]);
                } else {
                    nfsClient.readdir();
                }

            } else if (commandArgs[0].equals("cd")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: cd <path>");
                    continue;
                }
                nfsClient.cwd(commandArgs[1]);

            } else if (commandArgs[0].equals("lookup")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: lookup <path>");
                    continue;
                }
                nfsClient.lookup(commandArgs[1]);

            } else if (commandArgs[0].equals("lookup-fh")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 3) {
                    System.out.println("usage: lookup-fh <fh> <path>");
                    continue;
                }
                nfsClient.lookup(commandArgs[1], commandArgs[2]);

            } else if (commandArgs[0].equals("getattr")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: getattr <path>");
                    continue;
                }
                nfsClient.getattr(commandArgs[1]);

            } else if (commandArgs[0].equals("mkdir")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: mkdir <path>");
                    continue;
                }
                nfsClient.mkdir(commandArgs[1]);
            } else if (commandArgs[0].equals("read")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length < 2 || commandArgs.length > 3) {
                    System.out.println("usage: read <file> [-nopnfs]");
                    continue;
                }
                boolean usePNFS = commandArgs.length == 2 || !commandArgs[2].equals("-nopnfs");
                nfsClient.read(commandArgs[1], usePNFS);

            } else if (commandArgs[0].equals("readatonce")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: readatonce <file>");
                    continue;
                }
                nfsClient.readatonce(commandArgs[1]);

            } else if (commandArgs[0].equals("read-nostate")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: read-nostate <file>");
                    continue;
                }
                nfsClient.readNoState(commandArgs[1]);

            } else if (commandArgs[0].equals("fs_locations")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: fs_locations <file>");
                    continue;
                }

                nfsClient.get_fs_locations(commandArgs[1]);

            } else if (commandArgs[0].equals("remove")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: remove <file>");
                    continue;
                }
                nfsClient.remove(commandArgs[1]);

            } else if (commandArgs[0].equals("write")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length < 3 || commandArgs.length > 4) {
                    System.out.println("usage: write <src> <dest> [-nopnfs]");
                    continue;
                }
                boolean usePNFS = commandArgs.length == 3 || !commandArgs[3].equals("-nopnfs");
                nfsClient.write(commandArgs[1], commandArgs[2], usePNFS);

            } else if (commandArgs[0].equals("filebomb")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 2) {
                    System.out.println("usage: filebomb <num>");
                    continue;
                }
                nfsClient.filebomb(Integer.parseInt(commandArgs[1]));

            } else if (commandArgs[0].equals("openbomb")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                if (commandArgs.length != 3) {
                    System.out.println("usage: openbomb <file> <count>");
                    continue;
                }
                nfsClient.openbomb(commandArgs[1], Integer.parseInt(commandArgs[2]));

            } else if (commandArgs[0].equals("gc")) {

                if (nfsClient == null) {
                    System.out.println("Not mounted");
                    continue;
                }

                nfsClient.gc();

            } else if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit")) {

                if (nfsClient != null) {
                    nfsClient.destroy_session();
                    nfsClient.destroy_clientid();
                }
                System.exit(0);
            } else {
                out.println("Supported commands: ");
                for (String command : commands) {
                    out.println("    " + command);
                }
            }
            out.flush();
        } catch (ChimeraNFSException e) {
            out.printf("%s failed: %s(%d) \n", commandArgs[0], nfsstat.toString(e.getStatus()), e.getStatus());
        }
    }
}

From source file:org.apache.accumulo.core.util.AddressUtil.java

static public HostAndPort parseAddress(String address, boolean ignoreMissingPort) throws NumberFormatException {
    address = address.replace('+', ':');
    HostAndPort hap = HostAndPort.fromString(address);
    if (!ignoreMissingPort && !hap.hasPort())
        throw new IllegalArgumentException("Address was expected to contain port. address=" + address);

    return hap;/*from   www . ja v a 2 s .co  m*/
}

From source file:com.dasasian.chok.util.ZkChokUtil.java

public static ZkServer startZkServer(ZkConfiguration conf) {
    String server = Iterables.getOnlyElement(COMMA_SPLITTER.split(conf.getServers()));
    HostAndPort hostAndPort = HostAndPort.fromString(server);
    if (!hostAndPort.hasPort()) {
        throw new IllegalArgumentException("No Port Specified for ZkServer");
    } else {/*from  ww w  .  j av  a  2  s. c  o  m*/
        String host = hostAndPort.getHostText();
        //            if (!host.equals("127.0.0.1") && !host.equals("localhost")) {
        //                throw new IllegalArgumentException("Attempting to start ZkServer remotely on " + host + " valid values are 127.0.0.1 or localhost");
        //            }
    }
    ZkServer zkServer = new ZkServer(conf.getDataDir(), conf.getLogDataDir(), new DefaultNameSpaceImpl(conf),
            hostAndPort.getPort(), conf.getTickTime());
    zkServer.start();
    return zkServer;
}

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

@Nonnull
public static Replica fromString(@Nonnull String info) {
    try {// w  w w.ja  v  a2  s .co 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);
    }
}