Example usage for org.apache.commons.lang3.time StopWatch start

List of usage examples for org.apache.commons.lang3.time StopWatch start

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time StopWatch start.

Prototype

public void start() 

Source Link

Document

Start the stopwatch.

Usage

From source file:net.sf.gazpachoquest.dbpopulator.DBPopulatorRunner.java

public static void main(final String... args) {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "dbpopulator-datasource-context.xml", "dbpopulator-jpa-context.xml", "services-context.xml",
            "facades-context.xml", "components-context.xml");
    DBPopulator populator = ctx.getBean(DBPopulator.class);
    StopWatch stopWatch = new StopWatch();
    logger.info("Populating database");
    stopWatch.start();
    ShiroLogin.login();/*from  w  w w  .  jav  a  2  s.  c om*/
    populator.populate();
    stopWatch.stop();
    ShiroLogin.logout();
    logger.info("Database populated in {} {}", stopWatch.getTime(), "ms");

    ctx.close();
}

From source file:net.sf.gazpachoquest.exporter.ExporterRunner.java

public static void main(final String... args) throws IOException {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("exporter-datasource-context.xml",
            "exporter-jpa-context.xml", "services-context.xml", "facades-context.xml",
            "components-context.xml");
    Exporter exporter = ctx.getBean(Exporter.class);
    StopWatch stopWatch = new StopWatch();
    logger.info("Exporting questionnaire definition");
    stopWatch.start();
    exporter.doExport();/*ww  w.  j  a  v a 2  s .  com*/
    stopWatch.stop();
    logger.info("Export process ended in {} {}", stopWatch.getTime(), "ms");
    ctx.close();
}

From source file:net.sf.gazpachoquest.importer.ImporterRunner.java

public static void main(final String... args) throws IOException {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("importer-datasource-context.xml",
            "importer-jpa-context.xml", "services-context.xml", "facades-context.xml",
            "components-context.xml");
    Importer populator = ctx.getBean(Importer.class);
    StopWatch stopWatch = new StopWatch();
    logger.info("Importing questionnaire definitions");
    stopWatch.start();
    populator.doImport();//from w  w  w  .  ja  v a 2  s  . c  o  m
    stopWatch.stop();
    logger.info("Import process ended in {} {}", stopWatch.getTime(), "ms");
    ctx.close();
}

From source file:chibi.gemmaanalysis.cli.deprecated.AddExperimentalDesignCLI.java

/**
 * @param args// w  ww . ja  v a2  s  .  c  o  m
 */
public static void main(String[] args) {
    AddExperimentalDesignCLI p = new AddExperimentalDesignCLI();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = p.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info("Total run time: " + watch.getTime());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:chibi.gemmaanalysis.CorrelationAnalysisCLI.java

public static void main(String[] args) {
    CorrelationAnalysisCLI analysis = new CorrelationAnalysisCLI();
    StopWatch watch = new StopWatch();
    watch.start();
    log.info("Starting Correlation Analysis");
    Exception exc = analysis.doWork(args);
    if (exc != null) {
        log.error(exc.getMessage());/*from w  w  w . ja  v  a  2s .  c o  m*/
    }
    log.info("Finished analysis in " + watch);
}

From source file:chibi.gemmaanalysis.MetaLinkFinderCli.java

/**
 * @param args/*  w w  w  .  j  a v  a 2s .co  m*/
 */
public static void main(String[] args) {
    MetaLinkFinderCli linkFinderCli = new MetaLinkFinderCli();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = linkFinderCli.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info(watch.getTime());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:edu.jhu.hlt.concrete.gigaword.expt.ConvertGigawordDocuments.java

/**
 * @param args/*www  .  j  a  v  a  2 s .  co  m*/
 */
public static void main(String... args) {
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            logger.error("Thread {} caught unhandled exception.", t.getName());
            logger.error("Unhandled exception.", e);
        }
    });

    if (args.length != 2) {
        logger.info("Usage: {} {} {}", GigawordConcreteConverter.class.getName(), "path/to/expt/file",
                "path/to/out/folder");
        System.exit(1);
    }

    String exptPathStr = args[0];
    String outPathStr = args[1];

    // Verify path points to something.
    Path exptPath = Paths.get(exptPathStr);
    if (!Files.exists(exptPath)) {
        logger.error("File: {} does not exist. Re-run with the correct path to "
                + " the experiment 2 column file. See README.md.");
        System.exit(1);
    }

    logger.info("Experiment map located at: {}", exptPathStr);

    // Create output dir if not yet created.
    Path outPath = Paths.get(outPathStr);
    if (!Files.exists(outPath)) {
        logger.info("Creating directory: {}", outPath.toString());
        try {
            Files.createDirectories(outPath);
        } catch (IOException e) {
            logger.error("Caught an IOException when creating output dir.", e);
            System.exit(1);
        }
    }

    logger.info("Output directory located at: {}", outPathStr);

    // Read in expt map. See README.md.
    Map<String, Set<String>> exptMap = null;
    try (Reader r = ExperimentUtils.createReader(exptPath); BufferedReader br = new BufferedReader(r)) {
        exptMap = ExperimentUtils.createFilenameToIdMap(br);
    } catch (IOException e) {
        logger.error("Caught an IOException when creating expt map.", e);
        System.exit(1);
    }

    // Start a timer.
    logger.info("Gigaword -> Concrete beginning.");
    StopWatch sw = new StopWatch();
    sw.start();
    // Iterate over expt map.
    exptMap.entrySet()
            // .parallelStream()
            .forEach(p -> {
                final String pathStr = p.getKey();
                final Set<String> ids = p.getValue();
                final Path lp = Paths.get(pathStr);
                logger.info("Converting path: {}", pathStr);

                // Get the file name and immediate folder it is under.
                int nElements = lp.getNameCount();
                Path fileName = lp.getName(nElements - 1);
                Path subFolder = lp.getName(nElements - 2);
                String newFnStr = fileName.toString().split("\\.")[0] + ".tar";

                // Mirror folders in output dir.
                Path localOutFolder = outPath.resolve(subFolder);
                Path localOutPath = localOutFolder.resolve(newFnStr);

                // Create output subfolders.
                if (!Files.exists(localOutFolder) && !Files.isDirectory(localOutFolder)) {
                    logger.info("Creating out file: {}", localOutFolder.toString());
                    try {
                        Files.createDirectories(localOutFolder);
                    } catch (IOException e) {
                        throw new RuntimeException("Caught an IOException when creating output dir.", e);
                    }
                }

                // Iterate over communications.
                Iterator<Communication> citer;
                try (OutputStream os = Files.newOutputStream(localOutPath);
                        BufferedOutputStream bos = new BufferedOutputStream(os);
                        Archiver archiver = new TarArchiver(bos);) {
                    citer = new ConcreteGigawordDocumentFactory().iterator(lp);
                    while (citer.hasNext()) {
                        Communication c = citer.next();
                        String cId = c.getId();

                        // Document ID must be in the set. Remove.
                        boolean wasInSet = ids.remove(cId);
                        if (!wasInSet) {
                            // Some IDs are duplicated in Gigaword.
                            // See ERRATA.
                            logger.debug(
                                    "ID: {} was parsed from path: {}, but was not in the experiment map. Attempting to remove dupe.",
                                    cId, pathStr);

                            // Attempt to create a duplicate id (append .duplicate to the id).
                            // Then, try to remove again.
                            String newId = RepairDuplicateIDs.repairDuplicate(cId);
                            boolean dupeRemoved = ids.remove(newId);
                            // There are not nested duplicates, so this should never fire.
                            if (!dupeRemoved) {
                                logger.info("Failed to remove dupe.");
                                return;
                            } else
                                // Modify the communication ID to the unique version.
                                c.setId(newId);
                        }

                        archiver.addEntry(new ArchivableCommunication(c));
                    }

                    logger.info("Finished path: {}", pathStr);
                } catch (ConcreteException ex) {
                    logger.error("Caught ConcreteException during Concrete mapping.", ex);
                    logger.error("Path: {}", pathStr);
                } catch (IOException e) {
                    logger.error("Error archiving communications.", e);
                    logger.error("Path: {}", localOutPath.toString());
                }
            });

    sw.stop();
    logger.info("Finished.");
    Minutes m = new Duration(sw.getTime()).toStandardMinutes();
    logger.info("Runtime: Approximately {} minutes.", m.getMinutes());
}

From source file:chibi.gemmaanalysis.OutlierDetectionTestCli.java

/**
 * @param args//  w  w  w  .  j a v  a 2  s.  c o  m
 */
public static void main(String[] args) {
    OutlierDetectionTestCli testCli = new OutlierDetectionTestCli();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = testCli.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info("Elapsed time: " + watch.getTime() / 1000 + " seconds");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    System.exit(0);
}

From source file:chibi.gemmaanalysis.AffyPlatFormAnalysisCli.java

/**
 * @param args//from ww w .ja  v  a2 s .c  om
 */
public static void main(String[] args) {
    AffyPlatFormAnalysisCli analysis = new AffyPlatFormAnalysisCli();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = analysis.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info("Elapsed time: " + watch.getTime() / 1000 + " seconds");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.mgmtp.jfunk.core.JFunk.java

/**
 * Starts jFunk.//from www .  j  av a  2 s  .co m
 * 
 * <pre>
 * -threadcount=&lt;count&gt;    Optional    Number of threads to be used. Allows for parallel
 *                                     execution of test scripts.
 * -parallel               Optional    Allows a single script to be executed in parallel
 *                                     depending on the number of threads specified. The
 *                                     argument is ignored if multiple scripts are specified.
 * &lt;script parameters&gt     Optional    Similar to Java system properties they can be provided
 *                                     as key-value-pairs preceded by -S, e.g. -Skey=value.
 *                                     These parameters are then available in the script as
 *                                     Groovy variables.
 * &lt;script(s)&gt;             Required    At least one test script must be specified.
 *
 * Example:
 * java -cp &lt;jFunkClasspath&gt; com.mgmtp.jfunk.core.JFunk -Skey=value -threadcount=4 -parallel mytest.script
 * </pre>
 * 
 * @param args
 *            The program arguments.
 */
public static void main(final String[] args) {
    SLF4JBridgeHandler.install();

    boolean exitWithError = true;
    StopWatch stopWatch = new StopWatch();

    try {
        RESULT_LOG.info("jFunk started");
        stopWatch.start();

        int threadCount = 1;
        boolean parallel = false;
        Properties scriptProperties = new Properties();
        List<File> scripts = Lists.newArrayList();

        for (String arg : args) {
            if (arg.startsWith("-threadcount")) {
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "The number of threads must be specified as follows: -threadcount=<value>");
                threadCount = Integer.parseInt(split[1]);
                RESULT_LOG.info("Using " + threadCount + (threadCount == 1 ? " thread" : " threads"));
            } else if (arg.startsWith("-S")) {
                arg = arg.substring(2);
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "Script parameters must be given in the form -S<name>=<value>");
                scriptProperties.setProperty(split[0], normalizeScriptParameterValue(split[1]));
                RESULT_LOG.info("Using script parameter " + split[0] + " with value " + split[1]);
            } else if (arg.equals("-parallel")) {
                parallel = true;
                RESULT_LOG.info("Using parallel mode");
            } else {
                scripts.add(new File(arg));
            }
        }

        if (scripts.isEmpty()) {
            scripts.addAll(requestScriptsViaGui());

            if (scripts.isEmpty()) {
                RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
                System.exit(0);
            }
        }

        String propsFileName = System.getProperty("jfunk.props.file", "jfunk.properties");
        Module module = ModulesLoader.loadModulesFromProperties(new JFunkDefaultModule(), propsFileName);
        Injector injector = Guice.createInjector(module);

        JFunkFactory factory = injector.getInstance(JFunkFactory.class);
        JFunkBase jFunk = factory.create(threadCount, parallel, scripts, scriptProperties);
        jFunk.execute();

        exitWithError = false;
    } catch (JFunkExecutionException ex) {
        // no logging necessary
    } catch (Exception ex) {
        Logger.getLogger(JFunk.class).error("jFunk terminated unexpectedly.", ex);
    } finally {
        stopWatch.stop();
        RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
    }

    System.exit(exitWithError ? -1 : 0);
}