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: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);/*from  w w  w  . j av  a2s.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.NedisBench.java

public static void main(String[] args) throws InterruptedException {
    Args parsedArgs = new Args();
    CmdLineParser parser = new CmdLineParser(parsedArgs);
    try {/*ww  w . ja v a2  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);
    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: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  ww w.jav a2s.  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);
    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: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 ww  w .j  a  v a 2s .  c om

    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:com.torodb.stampede.Main.java

public static void main(String[] args) throws Exception {
    try {/*w w w.j  ava 2  s  .  com*/
        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: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 ww  w .  j a va2s . c om*/
        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:alluxio.examples.Performance.java

/**
 * Runs the performance test.//from w  w  w.j a v  a  2 s.co  m
 *
 * Usage:
 * {@code java -cp <ALLUXIO-VERSION> alluxio.examples.Performance <MasterIp> <FileNamePrefix>
 * <WriteBlockSizeInBytes> <BlocksPerFile> <DebugMode:true/false> <Threads> <FilesPerThread>
 * <TestCaseNumber> <BaseFileNumber>}
 *
 * @param args the arguments for this example
 * @throws Exception if the example fails
 */
public static void main(String[] args) throws Exception {
    if (args.length != 9) {
        System.out.println("java -cp " + RuntimeConstants.ALLUXIO_JAR + " alluxio.examples.Performance "
                + "<MasterIp> <FileNamePrefix> <WriteBlockSizeInBytes> <BlocksPerFile> "
                + "<DebugMode:true/false> <Threads> <FilesPerThread> <TestCaseNumber> " + "<BaseFileNumber>\n"
                + "1: Files Write Test\n" + "2: Files Read Test\n" + "3: RamFile Write Test \n"
                + "4: RamFile Read Test \n" + "5: ByteBuffer Write Test \n" + "6: ByteBuffer Read Test \n");
        System.exit(-1);
    }

    HostAndPort masterAddress = HostAndPort.fromString(args[0]);
    sFileName = args[1];
    sBlockSizeBytes = Integer.parseInt(args[2]);
    sBlocksPerFile = Long.parseLong(args[3]);
    sDebugMode = ("true".equals(args[4]));
    sThreads = Integer.parseInt(args[5]);
    sFiles = Integer.parseInt(args[6]) * sThreads;
    final int testCase = Integer.parseInt(args[7]);
    sBaseFileNumber = Integer.parseInt(args[8]);

    sFileBytes = sBlocksPerFile * sBlockSizeBytes;
    sFilesBytes = sFileBytes * sFiles;

    long fileBufferBytes = Configuration.getBytes(PropertyKey.USER_FILE_BUFFER_BYTES);
    sResultPrefix = String.format(
            "Threads %d FilesPerThread %d TotalFiles %d "
                    + "BLOCK_SIZE_KB %d BLOCKS_PER_FILE %d FILE_SIZE_MB %d "
                    + "Alluxio_WRITE_BUFFER_SIZE_KB %d BaseFileNumber %d : ",
            sThreads, sFiles / sThreads, sFiles, sBlockSizeBytes / 1024, sBlocksPerFile,
            sFileBytes / Constants.MB, fileBufferBytes / 1024, sBaseFileNumber);

    CommonUtils.warmUpLoop();

    Configuration.set(PropertyKey.MASTER_HOSTNAME, masterAddress.getHostText());
    Configuration.set(PropertyKey.MASTER_RPC_PORT, Integer.toString(masterAddress.getPort()));

    if (testCase == 1) {
        sResultPrefix = "AlluxioFilesWriteTest " + sResultPrefix;
        LOG.info(sResultPrefix);
        sFileSystem = FileSystem.Factory.get();
        AlluxioTest(true /* write */);
    } else if (testCase == 2 || testCase == 9) {
        sResultPrefix = "AlluxioFilesReadTest " + sResultPrefix;
        LOG.info(sResultPrefix);
        sFileSystem = FileSystem.Factory.get();
        sAlluxioStreamingRead = (9 == testCase);
        AlluxioTest(false /* read */);
    } else if (testCase == 3) {
        sResultPrefix = "RamFile Write " + sResultPrefix;
        LOG.info(sResultPrefix);
        memoryCopyTest(true, false);
    } else if (testCase == 4) {
        sResultPrefix = "RamFile Read " + sResultPrefix;
        LOG.info(sResultPrefix);
        memoryCopyTest(false, false);
    } else if (testCase == 5) {
        sResultPrefix = "ByteBuffer Write Test " + sResultPrefix;
        LOG.info(sResultPrefix);
        memoryCopyTest(true, true);
    } else if (testCase == 6) {
        sResultPrefix = "ByteBuffer Read Test " + sResultPrefix;
        LOG.info(sResultPrefix);
        memoryCopyTest(false, true);
    } else if (testCase == 7) {
        sResultPrefix = "HdfsFilesWriteTest " + sResultPrefix;
        LOG.info(sResultPrefix);
        HdfsTest(true);
    } else if (testCase == 8) {
        sResultPrefix = "HdfsFilesReadTest " + sResultPrefix;
        LOG.info(sResultPrefix);
        HdfsTest(false);
    } else {
        throw new RuntimeException("No Test Case " + testCase);
    }

    for (int k = 0; k < RESULT_ARRAY_SIZE; k++) {
        System.out.print(sResults[k] + " ");
    }
    System.out.println();
    System.exit(0);
}

From source file:ratpack.server.internal.HostUtil.java

public static String determineHost(HostAndPort hostAndPort) {
    try {/*from w w  w  .  ja  v a 2s  .c  o m*/
        InetAddress address = InetAddress.getByName(hostAndPort.getHostText());
        return determineHost(address);
    } catch (UnknownHostException e) {
        return hostAndPort.getHostText();
    }
}

From source file:org.apache.hadoop.hbase.favored.StartcodeAgnosticServerName.java

public static StartcodeAgnosticServerName valueOf(final HostAndPort hostnameAndPort, long startcode) {
    return new StartcodeAgnosticServerName(hostnameAndPort.getHostText(), hostnameAndPort.getPort(), startcode);
}

From source file:com.mgmtp.perfload.core.console.model.Daemon.java

public static Daemon fromHostAndPort(final int id, final HostAndPort hostAndPort) {
    String host = hostAndPort.getHostText();
    int port = hostAndPort.getPort();
    return new Daemon(id, host, port);
}