Example usage for org.apache.commons.io IOUtils readLines

List of usage examples for org.apache.commons.io IOUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils readLines.

Prototype

public static List readLines(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a list of Strings, one entry per line.

Usage

From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java

@Test
public void testCreateAndRunScriptWithFakeKeplerThatSucceedsWithEmailSetButAllJobValuesAreEmpty()
        throws Exception {
    assumeTrue(SystemUtils.IS_OS_UNIX);//from  w  w w  .  j  av  a  2s.  c o  m
    File baseDirectory = Folder.newFolder();
    File tempDirectory = new File(baseDirectory + File.separator + "subdir");
    File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME);
    assertTrue(outputsDir.mkdirs());

    JobEmailNotificationData emailNotifyData = createJobEmailNotificationData();

    File stderrFile = new File(outputsDir.getAbsolutePath() + File.separator + "stderr");
    assertTrue(stderrFile.createNewFile());

    JobBinaries jb = new JobBinaries();
    jb.setKeplerScript(getAndCheckForTrueBinaryFile().getAbsolutePath());
    jb.setRegisterUpdateJar("register.jar");
    jb.setJavaCommand("echo");
    jb.setEchoCommand("echo");
    jb.setMailCommand("cat >> email.${finishedMessage};echo ");
    jb.setRetryCount(1);

    JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData);

    Job j = new Job();
    Workflow w = new Workflow();
    w.setId(new Long(5));
    Parameter emailParam = new Parameter();
    emailParam.setName(Constants.CWS_NOTIFYEMAIL);
    emailParam.setValue("bob@bob.com");
    ArrayList<Parameter> params = new ArrayList<>();
    params.add(emailParam);
    j.setParameters(params);
    j.setWorkflow(w);

    String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(2345));
    assertTrue(jobCmd != null);

    RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl();
    rclpi.setWorkingDirectory(outputsDir.getAbsolutePath());

    String result = rclpi.runCommandLineProcess(jobCmd);

    assertTrue(result.contains("Sending start email for Unknown to user bob@bob.com and bcc to bcc"));
    assertTrue(result
            .contains("-s project Workflow Unknown - Unknown has started running -r help -b bcc bob@bob.com"));
    assertTrue(result.contains("Sending done email for Unknown to user bob@bob.com and bcc to bcc"));
    assertTrue(
            result.contains("-s project Workflow Unknown - Unknown has finished -r help -b bcc bob@bob.com"));

    File emailStartFile = new File(outputsDir.getAbsolutePath() + File.separator + "email.");

    assertTrue(emailStartFile.exists());

    List<String> lines = IOUtils.readLines(new FileReader(emailStartFile));
    boolean dearFound = false;
    boolean yourFound = false;
    boolean pleaseFound = false;
    boolean contactFound = false;
    for (String line : lines) {
        if (line.startsWith("Dear")) {
            assertTrue(line.contains("Dear Unknown,"));
            dearFound = true;
        }
        if (line.startsWith("Your Unknown workflow job:")) {
            assertTrue(line.contains(
                    "Your Unknown workflow job: Unknown (Unknown) is now actively running on project resources."));
            yourFound = true;
        }
        if (line.startsWith("Please login to the ")) {
            assertTrue(line.contains("Please login to the portalname (portalurl) to check status."));
            pleaseFound = true;
        }
        if (line.startsWith("Contact project")) {
            assertTrue(line
                    .contains("Contact project support at help if you have any questions regarding your job."));
            contactFound = true;
        }
    }
    assertTrue(dearFound);
    assertTrue(yourFound);
    assertTrue(pleaseFound);
    assertTrue(contactFound);

    dearFound = false;
    yourFound = false;
    pleaseFound = false;
    contactFound = false;

    File emailDoneFile = new File(outputsDir.getAbsolutePath() + File.separator + "email.finished");
    lines = IOUtils.readLines(new FileReader(emailStartFile));
    for (String line : lines) {
        if (line.startsWith("Dear")) {
            assertTrue(line.contains("Dear Unknown,"));
            dearFound = true;
        }

        if (line.startsWith("Your Unknown workflow job:")) {
            assertTrue(line.contains(
                    "Your Unknown workflow job: Unknown (Unknown) is now actively running on project resources."));
            yourFound = true;
        }

        if (line.startsWith("Please login to the ")) {
            assertTrue(line.contains("Please login to the portalname (portalurl) to check status."));
            pleaseFound = true;
        }
        if (line.startsWith("Contact project")) {
            assertTrue(line
                    .contains("Contact project support at help if you have any questions regarding your job."));
            contactFound = true;
        }
    }
    assertTrue(dearFound);
    assertTrue(yourFound);
    assertTrue(pleaseFound);
    assertTrue(contactFound);

}

From source file:com.linkedin.pinot.tools.perf.QueryRunner.java

/**
 * Use multiple threads to run query at a target QPS.
 * <p>Use a concurrent linked queue to buffer the queries to be sent. Use the main thread to insert queries into the
 * queue at the target QPS, and start <code>numThreads</code> worker threads to fetch queries from the queue and send
 * them.//ww  w.  j a  va 2 s.  c  o m
 * <p>The main thread is responsible for collecting and logging the statistic information periodically.
 * <p>Queries are picked sequentially from the query file.
 * <p>Query runner will stop when all queries in the query file has been executed number of times configured.
 *
 * @param conf perf benchmark driver config.
 * @param queryFile query file.
 * @param numTimesToRunQueries number of times to run all queries in the query file, 0 means infinite times.
 * @param numThreads number of threads sending queries.
 * @param startQPS start QPS (target QPS).
 * @param reportIntervalMs report interval in milliseconds.
 * @param numIntervalsToReportAndClearStatistics number of report intervals to report detailed statistics and clear
 *                                               them, 0 means never.
 * @throws Exception
 */
public static void targetQPSQueryRunner(PerfBenchmarkDriverConf conf, String queryFile,
        int numTimesToRunQueries, int numThreads, double startQPS, int reportIntervalMs,
        int numIntervalsToReportAndClearStatistics) throws Exception {
    List<String> queries;
    try (FileInputStream input = new FileInputStream(new File(queryFile))) {
        queries = IOUtils.readLines(input);
    }

    PerfBenchmarkDriver driver = new PerfBenchmarkDriver(conf);
    ConcurrentLinkedQueue<String> queryQueue = new ConcurrentLinkedQueue<>();
    AtomicInteger numQueriesExecuted = new AtomicInteger(0);
    AtomicLong totalBrokerTime = new AtomicLong(0L);
    AtomicLong totalClientTime = new AtomicLong(0L);
    List<Statistics> statisticsList = Collections.singletonList(new Statistics(CLIENT_TIME_STATISTICS));

    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    for (int i = 0; i < numThreads; i++) {
        executorService.submit(new Worker(driver, queryQueue, numQueriesExecuted, totalBrokerTime,
                totalClientTime, statisticsList));
    }
    executorService.shutdown();

    int queryIntervalMs = (int) (MILLIS_PER_SECOND / startQPS);
    long startTime = System.currentTimeMillis();
    long reportStartTime = startTime;
    int numReportIntervals = 0;
    int numTimesExecuted = 0;
    while (numTimesToRunQueries == 0 || numTimesExecuted < numTimesToRunQueries) {
        if (executorService.isTerminated()) {
            LOGGER.error("All threads got exception and already dead.");
            return;
        }

        for (String query : queries) {
            queryQueue.add(query);
            Thread.sleep(queryIntervalMs);

            long currentTime = System.currentTimeMillis();
            if (currentTime - reportStartTime >= reportIntervalMs) {
                long timePassed = currentTime - startTime;
                int numQueriesExecutedInt = numQueriesExecuted.get();
                LOGGER.info(
                        "Target QPS: {}, Time Passed: {}ms, Queries Executed: {}, Average QPS: {}, "
                                + "Average Broker Time: {}ms, Average Client Time: {}ms, Queries Queued: {}.",
                        startQPS, timePassed, numQueriesExecutedInt,
                        numQueriesExecutedInt / ((double) timePassed / MILLIS_PER_SECOND),
                        totalBrokerTime.get() / (double) numQueriesExecutedInt,
                        totalClientTime.get() / (double) numQueriesExecutedInt, queryQueue.size());
                reportStartTime = currentTime;
                numReportIntervals++;

                if ((numIntervalsToReportAndClearStatistics != 0)
                        && (numReportIntervals == numIntervalsToReportAndClearStatistics)) {
                    numReportIntervals = 0;
                    startTime = currentTime;
                    reportAndClearStatistics(numQueriesExecuted, totalBrokerTime, totalClientTime,
                            statisticsList);
                }
            }
        }
        numTimesExecuted++;
    }

    // Wait for all queries getting executed.
    while (queryQueue.size() != 0) {
        Thread.sleep(1);
    }
    executorService.shutdownNow();
    while (!executorService.isTerminated()) {
        Thread.sleep(1);
    }

    long timePassed = System.currentTimeMillis() - startTime;
    int numQueriesExecutedInt = numQueriesExecuted.get();
    LOGGER.info("--------------------------------------------------------------------------------");
    LOGGER.info("FINAL REPORT:");
    LOGGER.info(
            "Target QPS: {}, Time Passed: {}ms, Queries Executed: {}, Average QPS: {}, "
                    + "Average Broker Time: {}ms, Average Client Time: {}ms.",
            startQPS, timePassed, numQueriesExecutedInt,
            numQueriesExecutedInt / ((double) timePassed / MILLIS_PER_SECOND),
            totalBrokerTime.get() / (double) numQueriesExecutedInt,
            totalClientTime.get() / (double) numQueriesExecutedInt);
    for (Statistics statistics : statisticsList) {
        statistics.report();
    }
}

From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java

private static List<String> connectAndReadFromURL(URL url) {
    List<String> data = null;
    DefaultHttpClient httpClient = null;
    TrustStrategy easyStrategy = new TrustStrategy() {
        @Override/*from w ww . ja  va  2  s  .  c  o m*/
        public boolean isTrusted(X509Certificate[] certificate, String authType) throws CertificateException {
            return true;
        }
    };
    try {
        SSLSocketFactory sslsf = new SSLSocketFactory(easyStrategy,
                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        Scheme httpsScheme = new Scheme("https", 443, sslsf);
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(httpsScheme);
        schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(schemeRegistry);

        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 50000);
        HttpConnectionParams.setSoTimeout(httpParams, new Integer(12000));
        httpClient = new DefaultHttpClient(ccm, httpParams);
        httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(schemeRegistry, ProxySelector.getDefault()));
        // // Additions by lrt for tcia -
        // // attempt to reduce errors going through a Coyote Point
        // Equalizer load balance switch
        httpClient.getParams().setParameter("http.socket.timeout", new Integer(12000));
        httpClient.getParams().setParameter("http.socket.receivebuffer", new Integer(16384));
        httpClient.getParams().setParameter("http.tcp.nodelay", true);
        httpClient.getParams().setParameter("http.connection.stalecheck", false);
        // // end lrt additions

        HttpPost httpPostMethod = new HttpPost(url.toString());

        List<BasicNameValuePair> postParams = new ArrayList<BasicNameValuePair>();
        postParams.add(new BasicNameValuePair(osParam, os));
        UrlEncodedFormEntity query = new UrlEncodedFormEntity(postParams);
        httpPostMethod.setEntity(query);
        HttpResponse response = httpClient.execute(httpPostMethod);
        int responseCode = response.getStatusLine().getStatusCode();

        if (responseCode == HttpStatus.SC_OK) {
            InputStream inputStream = response.getEntity().getContent();
            data = IOUtils.readLines(inputStream);
        } else {
            JOptionPane.showMessageDialog(null, "Incorrect response from server: " + responseCode);
        }

    } catch (java.net.ConnectException e) {
        String note = "Connection error 1 while connecting to " + url.toString() + ":\n" + getProxyInfo();
        //+ checkListeningPort("127.0.0.1", 8888);
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 1: " + e.getMessage());
        e.printStackTrace();
    } catch (MalformedURLException e) {
        String note = "Connection error 2 while connecting to " + url.toString() + ":\n";
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 2: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        String note = "Connection error 3 while connecting to " + url.toString() + ":\n";
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 3: " + e.getMessage());
        e.printStackTrace();
    } catch (KeyManagementException e) {
        String note = "Connection error 4 while connecting to " + url.toString() + ":\n";
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 4: " + e.getMessage());
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        String note = "Connection error 5 while connecting to " + url.toString() + ":\n";
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 5: " + e.getMessage());
        e.printStackTrace();
    } catch (KeyStoreException e) {
        String note = "Connection error 6 while connecting to " + url.toString() + ":\n";
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 6: " + e.getMessage());
        e.printStackTrace();
    } catch (UnrecoverableKeyException e) {
        String note = "Connection error 7 while connecting to " + url.toString() + ":\n";
        printStackTraceToDialog(note, e);
        //JOptionPane.showMessageDialog(null, "Connection error 7: " + e.getMessage());
        e.printStackTrace();
    } finally {
        if (httpClient != null) {
            httpClient.getConnectionManager().shutdown();
        }
    }
    return data;
}

From source file:com.edgenius.wiki.installation.DBLoader.java

protected List<String> loadSQLFile(String type, String filename) throws IOException {
    InputStream is = FileUtil.getFileInputStream("classpath:META-INF/meta/" + type + "/" + filename);
    List<String> plines = IOUtils.readLines(is);
    IOUtils.closeQuietly(is);//from   w w w.  j  ava 2  s  .  c o m

    List<String> sqlLines = new ArrayList<String>();
    StringBuffer line = new StringBuffer();
    for (String pline : plines) {
        pline = StringUtils.trimToEmpty(pline);
        if (pline.startsWith("--") || pline.startsWith("#"))
            continue;

        if (pline.endsWith(";")) {
            //trim last ";" as it is invalid in Oracle
            line.append(pline, 0, pline.length() - 1);
            sqlLines.add(line.toString());
            line = new StringBuffer();
        } else {
            line.append(pline).append("\n");
        }
    }

    return sqlLines;
}

From source file:io.apiman.test.common.util.TestPlanRunner.java

/**
 * Assume the payload is Text and do some assertions based on the configuration
 * in the REST Test./*  w ww .  j ava 2 s  .co m*/
 * @param restTest
 * @param response
 */
private void assertTextPayload(RestTest restTest, HttpResponse response) {
    InputStream inputStream = null;
    try {
        inputStream = response.getEntity().getContent();
        List<String> lines = IOUtils.readLines(inputStream);
        StringBuilder builder = new StringBuilder();
        for (String line : lines) {
            builder.append(line).append("\n"); //$NON-NLS-1$
        }

        String actual = builder.toString();
        String expected = restTest.getExpectedResponsePayload();
        Assert.assertEquals("Response payload (text/plain) mismatch.", expected, actual); //$NON-NLS-1$
    } catch (Exception e) {
        throw new Error(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:ml.shifu.shifu.fs.ShifuFileUtils.java

public static List<String> readFilePartsIntoList(String filePath, SourceType sourceType) throws IOException {
    List<String> lines = new ArrayList<String>();

    FileSystem fs = getFileSystemBySourceType(sourceType);
    FileStatus[] fileStatsArr = getFilePartStatus(filePath, sourceType);

    CompressionCodecFactory compressionFactory = new CompressionCodecFactory(new Configuration());
    for (FileStatus fileStatus : fileStatsArr) {
        InputStream is = null;//from w ww. jav a2  s.  com
        CompressionCodec codec = compressionFactory.getCodec(fileStatus.getPath());
        if (codec != null) {
            is = codec.createInputStream(fs.open(fileStatus.getPath()));
        } else {
            is = fs.open(fileStatus.getPath());
        }

        lines.addAll(IOUtils.readLines(is));
        IOUtils.closeQuietly(is);
    }

    return lines;
}

From source file:com.gitblit.tickets.TicketNotifier.java

protected String readResource(String resource) {
    StringBuilder sb = new StringBuilder();
    InputStream is = null;//from  w  ww. j  a  va2s  . c om
    try {
        is = getClass().getResourceAsStream(resource);
        List<String> lines = IOUtils.readLines(is);
        for (String line : lines) {
            sb.append(line).append('\n');
        }
    } catch (IOException e) {

    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
    return sb.toString();
}

From source file:com.linkedin.pinot.tools.perf.QueryRunner.java

/**
 * Use multiple threads to run query at an increasing target QPS.
 * <p>Use a concurrent linked queue to buffer the queries to be sent. Use the main thread to insert queries into the
 * queue at the target QPS, and start <code>numThreads</code> worker threads to fetch queries from the queue and send
 * them./*from w  ww  . jav a 2  s.  com*/
 * <p>We start with the start QPS, and keep adding delta QPS to the start QPS during the test.
 * <p>The main thread is responsible for collecting and logging the statistic information periodically.
 * <p>Queries are picked sequentially from the query file.
 * <p>Query runner will stop when all queries in the query file has been executed number of times configured.
 *
 * @param conf perf benchmark driver config.
 * @param queryFile query file.
 * @param numTimesToRunQueries number of times to run all queries in the query file, 0 means infinite times.
 * @param numThreads number of threads sending queries.
 * @param startQPS start QPS.
 * @param deltaQPS delta QPS.
 * @param reportIntervalMs report interval in milliseconds.
 * @param numIntervalsToReportAndClearStatistics number of report intervals to report detailed statistics and clear
 *                                               them, 0 means never.
 * @param numIntervalsToIncreaseQPS number of intervals to increase QPS.
 * @throws Exception
 */

public static void increasingQPSQueryRunner(PerfBenchmarkDriverConf conf, String queryFile,
        int numTimesToRunQueries, int numThreads, double startQPS, double deltaQPS, int reportIntervalMs,
        int numIntervalsToReportAndClearStatistics, int numIntervalsToIncreaseQPS) throws Exception {
    List<String> queries;
    try (FileInputStream input = new FileInputStream(new File(queryFile))) {
        queries = IOUtils.readLines(input);
    }

    PerfBenchmarkDriver driver = new PerfBenchmarkDriver(conf);
    ConcurrentLinkedQueue<String> queryQueue = new ConcurrentLinkedQueue<>();
    AtomicInteger numQueriesExecuted = new AtomicInteger(0);
    AtomicLong totalBrokerTime = new AtomicLong(0L);
    AtomicLong totalClientTime = new AtomicLong(0L);
    List<Statistics> statisticsList = Collections.singletonList(new Statistics(CLIENT_TIME_STATISTICS));

    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    for (int i = 0; i < numThreads; i++) {
        executorService.submit(new Worker(driver, queryQueue, numQueriesExecuted, totalBrokerTime,
                totalClientTime, statisticsList));
    }
    executorService.shutdown();

    long startTime = System.currentTimeMillis();
    long reportStartTime = startTime;
    int numReportIntervals = 0;
    int numTimesExecuted = 0;
    double currentQPS = startQPS;
    int queryIntervalMs = (int) (MILLIS_PER_SECOND / currentQPS);
    while (numTimesToRunQueries == 0 || numTimesExecuted < numTimesToRunQueries) {
        if (executorService.isTerminated()) {
            LOGGER.error("All threads got exception and already dead.");
            return;
        }

        for (String query : queries) {
            queryQueue.add(query);
            Thread.sleep(queryIntervalMs);

            long currentTime = System.currentTimeMillis();
            if (currentTime - reportStartTime >= reportIntervalMs) {
                long timePassed = currentTime - startTime;
                reportStartTime = currentTime;
                numReportIntervals++;

                if (numReportIntervals == numIntervalsToIncreaseQPS) {
                    // Try to find the next interval.
                    double newQPS = currentQPS + deltaQPS;
                    int newQueryIntervalMs;
                    // Skip the target QPS with the same interval as the previous one.
                    while ((newQueryIntervalMs = (int) (MILLIS_PER_SECOND / newQPS)) == queryIntervalMs) {
                        newQPS += deltaQPS;
                    }
                    if (newQueryIntervalMs == 0) {
                        LOGGER.warn("Due to sleep granularity of millisecond, cannot further increase QPS.");
                    } else {
                        // Find the next interval.
                        LOGGER.info(
                                "--------------------------------------------------------------------------------");
                        LOGGER.info("REPORT FOR TARGET QPS: {}", currentQPS);
                        int numQueriesExecutedInt = numQueriesExecuted.get();
                        LOGGER.info(
                                "Current Target QPS: {}, Time Passed: {}ms, Queries Executed: {}, Average QPS: {}, "
                                        + "Average Broker Time: {}ms, Average Client Time: {}ms, Queries Queued: {}.",
                                currentQPS, timePassed, numQueriesExecutedInt,
                                numQueriesExecutedInt / ((double) timePassed / MILLIS_PER_SECOND),
                                totalBrokerTime.get() / (double) numQueriesExecutedInt,
                                totalClientTime.get() / (double) numQueriesExecutedInt, queryQueue.size());
                        numReportIntervals = 0;
                        startTime = currentTime;
                        reportAndClearStatistics(numQueriesExecuted, totalBrokerTime, totalClientTime,
                                statisticsList);

                        currentQPS = newQPS;
                        queryIntervalMs = newQueryIntervalMs;
                        LOGGER.info(
                                "Increase target QPS to: {}, the following statistics are for the new target QPS.",
                                currentQPS);
                    }
                } else {
                    int numQueriesExecutedInt = numQueriesExecuted.get();
                    LOGGER.info(
                            "Current Target QPS: {}, Time Passed: {}ms, Queries Executed: {}, Average QPS: {}, "
                                    + "Average Broker Time: {}ms, Average Client Time: {}ms, Queries Queued: {}.",
                            currentQPS, timePassed, numQueriesExecutedInt,
                            numQueriesExecutedInt / ((double) timePassed / MILLIS_PER_SECOND),
                            totalBrokerTime.get() / (double) numQueriesExecutedInt,
                            totalClientTime.get() / (double) numQueriesExecutedInt, queryQueue.size());

                    if ((numIntervalsToReportAndClearStatistics != 0)
                            && (numReportIntervals % numIntervalsToReportAndClearStatistics == 0)) {
                        startTime = currentTime;
                        reportAndClearStatistics(numQueriesExecuted, totalBrokerTime, totalClientTime,
                                statisticsList);
                    }
                }
            }
        }
        numTimesExecuted++;
    }

    // Wait for all queries getting executed.
    while (queryQueue.size() != 0) {
        Thread.sleep(1);
    }
    executorService.shutdownNow();
    while (!executorService.isTerminated()) {
        Thread.sleep(1);
    }

    long timePassed = System.currentTimeMillis() - startTime;
    int numQueriesExecutedInt = numQueriesExecuted.get();
    LOGGER.info("--------------------------------------------------------------------------------");
    LOGGER.info("FINAL REPORT:");
    LOGGER.info(
            "Current Target QPS: {}, Time Passed: {}ms, Queries Executed: {}, Average QPS: {}, "
                    + "Average Broker Time: {}ms, Average Client Time: {}ms.",
            currentQPS, timePassed, numQueriesExecutedInt,
            numQueriesExecutedInt / ((double) timePassed / MILLIS_PER_SECOND),
            totalBrokerTime.get() / (double) numQueriesExecutedInt,
            totalClientTime.get() / (double) numQueriesExecutedInt);
    for (Statistics statistics : statisticsList) {
        statistics.report();
    }
}

From source file:com.lenovo.tensorhusky.common.utils.ProcfsBasedProcessTree.java

/**
 * Update memory related information//from  w w  w.  jav  a  2  s .c  o m
 *
 * @param pInfo
 * @param procfsDir
 */
private static void constructProcessSMAPInfo(ProcessTreeSmapMemInfo pInfo, String procfsDir) {
    BufferedReader in = null;
    InputStreamReader fReader = null;
    try {
        File pidDir = new File(procfsDir, pInfo.getPid());
        File file = new File(pidDir, SMAPS);
        if (!file.exists()) {
            return;
        }
        fReader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
        in = new BufferedReader(fReader);
        ProcessSmapMemoryInfo memoryMappingInfo = null;
        List<String> lines = IOUtils.readLines(in);
        for (String line : lines) {
            line = line.trim();
            try {
                Matcher address = ADDRESS_PATTERN.matcher(line);
                if (address.find()) {
                    memoryMappingInfo = new ProcessSmapMemoryInfo(line);
                    memoryMappingInfo.setPermission(address.group(4));
                    pInfo.getMemoryInfoList().add(memoryMappingInfo);
                    continue;
                }
                Matcher memInfo = MEM_INFO_PATTERN.matcher(line);
                if (memInfo.find()) {
                    String key = memInfo.group(1).trim();
                    String value = memInfo.group(2).replace(KB, "").trim();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("MemInfo : " + key + " : Value  : " + value);
                    }
                    memoryMappingInfo.setMemInfo(key, value);
                }
            } catch (Throwable t) {
                LOG.warn("Error parsing smaps line : " + line + "; " + t.getMessage());
            }
        }
    } catch (FileNotFoundException f) {
        LOG.error(f.getMessage());
    } catch (IOException e) {
        LOG.error(e.getMessage());
    } catch (Throwable t) {
        LOG.error(t.getMessage());
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGenerator.java

/**
 * Loads SQL statements from a SQL script file and returns a list containing strings for each statement.
 *
 * <p>This method also runs the {@link QCLiveTestDataGenerator#stripEndingSemicolonFromSQLStmts(List)} method
 * on the returned list.//from   w ww . j  av a 2 s  .co m
 *
 * @param sqlScriptFileURL - the SQL script file to retrieve SQL statements from
 * @param toLowerCase wether to convert the SQL statements to lower case
 * @return a list containing strings that represent each SQL statement in the provided SQL script file
 * @throws IOException
 */
private List<String> getSQLStmtsFromFile(final URL sqlScriptFileURL, final boolean toLowerCase)
        throws IOException {

    logger.debug("Retrieving SQL statements from file '" + sqlScriptFileURL + "'");

    InputStream inputStream = sqlScriptFileURL.openStream();
    try {
        // Read in all the lines from the SQL script file and remove all lines that do begin with "select", "delete", or "truncate" and end with ";", and
        // do not include commit.

        List<String> sqlStatements = new ArrayList<String>();
        List<String> sqlStatementsFromFile = IOUtils.readLines(inputStream);
        String trimmedStatement, trimmedStatementToLowerCase;
        for (String statement : sqlStatementsFromFile) {
            trimmedStatement = statement.trim();
            trimmedStatementToLowerCase = trimmedStatement.toLowerCase();
            if (SQL_STMT_PATTERN.matcher(trimmedStatementToLowerCase).matches()
                    && !SQL_STMT_EXCLUSION_PATTERN.matcher(trimmedStatementToLowerCase).matches()) {
                sqlStatements.add(toLowerCase ? trimmedStatementToLowerCase : trimmedStatement);
            }
        }

        return stripEndingSemicolonFromSQLStmts(sqlStatements);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}