Example usage for org.apache.commons.lang.time StopWatch toString

List of usage examples for org.apache.commons.lang.time StopWatch toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Gets a summary of the time that the stopwatch recorded as a string.

The format used is ISO8601-like, hours:minutes:seconds.milliseconds.

Usage

From source file:hadoop.Main.java

public static void main(String[] args) throws Exception {

    StopWatch timer = new StopWatch();
    timer.start();//  w  w w.j a va  2 s .c o  m

    System.out.println("Main program is starting");

    String dir = "hdfs://127.0.1.1:9000/user/fiqie/twitter/";

    Configuration conf = new Configuration();
    conf.set("fs.default.name", "hdfs://127.0.1.1:9000");
    FileSystem fs = FileSystem.get(conf);

    String[] prepareOpts = { dir + "input/small.txt", dir + "output/pr-0.out" };
    ToolRunner.run(new Configuration(), new InitPageRank(), prepareOpts);

    //String[] initOpts = { dir + "output/prepared.out", dir + "output/pr-0.out" };
    //ToolRunner.run(new Configuration(), new InitPageRankDriver(), initOpts);

    for (int i = 1; i <= NUMBER_OF_ITERATION; i++) {
        String previous = dir + "output/pr-" + (i - 1) + ".out";
        String current = dir + "output/pr-" + i + ".out";
        String[] opts = { previous, current };
        ToolRunner.run(new Configuration(), new CalculatePageRank(), opts);

        if (i == NUMBER_OF_ITERATION) {
            String[] finalOpts = { dir + "output/pr-" + i + ".out", dir + "output/pr-final.out" };
            ToolRunner.run(new Configuration(), new FinishPageRank(), finalOpts);
        }
    }

    timer.stop();
    System.out.println("Elapsed " + timer.toString());

}

From source file:gov.nih.nci.cagrid.caarray.client.CaArraySvcClient.java

private static void cqlQueryTest(CaArraySvcClient client)
        throws RemoteException, QueryProcessingExceptionType, MalformedQueryExceptionType {
    StopWatch sw = new StopWatch();
    sw.start();/*from ww w  . ja  v a  2  s. c  o  m*/

    CQLQuery cqlQuery = new CQLQuery();

    Object target = new Object();
    cqlQuery.setTarget(target);

    target.setName(UserDefinedCharacteristic.class.getName());
    Attribute a = new Attribute();
    a.setName("id");
    a.setValue(CHARACTERISTIC_ID);
    a.setPredicate(Predicate.EQUAL_TO);
    target.setAttribute(a);

    CQLQueryResults results = client.query(cqlQuery);
    CQLQueryResultsIterator iter = new CQLQueryResultsIterator(results,
            CaArraySvcClient.class.getResourceAsStream("client-config.wsdd"));
    while (iter.hasNext()) {
        java.lang.Object o = iter.next();
        System.out.println("Characteristic: " + ToStringBuilder.reflectionToString(o));
    }
    sw.stop();
    System.out.println("Time for simple data service retrieval: " + sw.toString());
}

From source file:com.streamsets.pipeline.stage.destination.jobtype.avroparquet.LargeInputFileIT.java

@Test
public void testLargeFile() throws Exception {
    File inputFile = new File(getInputDir(), "input.avro");
    File outputFile = new File(getOutputDir(), "input.parquet");
    long recordCount = Long.valueOf(System.getProperty(TARGET_RECORD_COUNT, TARGET_RECORD_COUNT_DEFAULT));
    StopWatch stopWatch = new StopWatch();

    stopWatch.start();//from   w w  w .j a  v  a  2  s  .c o m
    generateAvroFile(AVRO_SCHEMA, inputFile, recordCount);
    stopWatch.stop();

    LOG.info("Created input avro file in {}, contains {} records and have {}.", stopWatch.toString(),
            recordCount, humanReadableSize(inputFile.length()));

    AvroConversionCommonConfig commonConfig = new AvroConversionCommonConfig();
    AvroParquetConfig conf = new AvroParquetConfig();
    commonConfig.inputFile = inputFile.getAbsolutePath();
    commonConfig.outputDirectory = getOutputDir();

    MapReduceExecutor executor = generateExecutor(commonConfig, conf, Collections.emptyMap());

    ExecutorRunner runner = new ExecutorRunner.Builder(MapReduceDExecutor.class, executor)
            .setOnRecordError(OnRecordError.TO_ERROR).build();
    runner.runInit();

    Record record = RecordCreator.create();
    record.set(Field.create(Collections.<String, Field>emptyMap()));

    stopWatch.reset();
    stopWatch.start();
    runner.runWrite(ImmutableList.of(record));
    stopWatch.stop();
    LOG.info("Generated output parquet file in {} and have {}.", stopWatch.toString(),
            humanReadableSize(outputFile.length()));

    Assert.assertEquals(0, runner.getErrorRecords().size());
    runner.runDestroy();

    validateParquetFile(new Path(outputFile.getAbsolutePath()), recordCount);
}

From source file:gov.nasa.ensemble.core.jscience.xml.XMLProfilesResource.java

@Override
@SuppressWarnings("unchecked")
protected void doLoad(InputStream inputStream, Map<?, ?> options) {
    String extension = getURI().fileExtension();
    if (!SUPPORTED_EXTENSIONS.contains(extension.toLowerCase())) {
        LOGGER.warn("\"" + extension + "\" is not a standard extension for a ProfileResource.");
    }//from w w w  .j a v  a2  s .  c  om
    ProfilesParser parser = XMLProfileParser.getInstance();
    inputStream = ProgressMonitorInputStream.wrapInputStream(this, inputStream, options);
    StopWatch sw = new StopWatch();
    sw.start();
    try {
        parser.parse(getURI(), inputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
    sw.stop();
    LOGGER.debug("Loaded profiles from " + getURI() + " in " + sw.toString());
    List<Profile> profiles = parser.getProfiles();
    if (profiles != null) {
        getContents().addAll(profiles);
    }
    setModified(false);
}

From source file:io.cloudslang.lang.cli.SlangCli.java

@CliCommand(value = "run", help = RUN_HELP)
public String run(@CliOption(key = { "", "f", "file" }, mandatory = true, help = FILE_HELP) final File file,
        @CliOption(key = { "cp",
                "classpath" }, mandatory = false, help = CLASSPATH_HELP) final List<String> classPath,
        @CliOption(key = { "i",
                "inputs" }, mandatory = false, help = INPUTS_HELP) final Map<String, ? extends Serializable> inputs,
        @CliOption(key = { "if",
                "input-file" }, mandatory = false, help = INPUT_FILE_HELP) final List<String> inputFiles,
        @CliOption(key = { "v",
                "verbose" }, mandatory = false, help = "default, quiet, debug(print each step outputs). e.g. run --f c:/.../your_flow.sl --v quiet", specifiedDefaultValue = "debug", unspecifiedDefaultValue = "default") final String verbose,
        @CliOption(key = { "spf",
                "system-property-file" }, mandatory = false, help = SYSTEM_PROPERTY_FILE_HELP) final List<String> systemPropertyFiles) {

    if (invalidVerboseInput(verbose)) {
        throw new IllegalArgumentException("Verbose argument is invalid.");
    }/* w w  w. j  a  va2s.c o m*/

    CompilationArtifact compilationArtifact = compilerHelper.compile(file.getAbsolutePath(), classPath);
    Set<SystemProperty> systemProperties = compilerHelper.loadSystemProperties(systemPropertyFiles);
    Map<String, Value> inputsFromFile = compilerHelper.loadInputsFromFile(inputFiles);
    Map<String, Value> mergedInputs = new HashMap<>();

    if (MapUtils.isNotEmpty(inputsFromFile)) {
        mergedInputs.putAll(inputsFromFile);
    }
    if (MapUtils.isNotEmpty(inputs)) {
        mergedInputs.putAll(io.cloudslang.lang.entities.utils.MapUtils.convertMapNonSensitiveValues(inputs));
    }
    boolean quiet = QUIET.equalsIgnoreCase(verbose);
    boolean debug = DEBUG.equalsIgnoreCase(verbose);

    Long id;
    if (!triggerAsync) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        id = scoreServices.triggerSync(compilationArtifact, mergedInputs, systemProperties, quiet, debug);
        stopWatch.stop();
        return quiet ? StringUtils.EMPTY : triggerSyncMsg(id, stopWatch.toString());
    }
    id = scoreServices.trigger(compilationArtifact, mergedInputs, systemProperties);
    return quiet ? StringUtils.EMPTY : triggerAsyncMsg(id, compilationArtifact.getExecutionPlan().getName());
}

From source file:com.mothsoft.alexis.engine.predictive.OpenNLPMaxentModelTrainerTask.java

@Transactional
@Override//w w  w. jav a 2  s .c o  m
public void execute() {
    final Long modelId = findAndMark();

    if (modelId != null) {
        logger.info(String.format("Training model %d", modelId));

        final StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final Model model = this.modelDao.get(modelId);
        train(model);
        stopWatch.stop();

        logger.info(String.format("Training model %d took: %s", modelId, stopWatch.toString()));
    }
}

From source file:com.mothsoft.alexis.engine.textual.TopicDocumentMatcherImpl.java

public void execute() {

    logger.info("Starting Topic<=>Document Matching");

    final StopWatch stopWatch = new StopWatch();

    // a unique state for documents pending matching so we can transition
    // items that had no topics (prevent a big future spike when a topic is
    // added that now matches really old documents)
    stopWatch.start();/*from w  w  w  . j  a v  a2s .  c  om*/
    bulkUpdateDocumentState(DocumentState.PARSED, DocumentState.PENDING_TOPIC_MATCHING);
    stopWatch.stop();
    logger.info("Marking PARSED documents as PENDING_TOPIC_MATCHING took: " + stopWatch.toString());
    stopWatch.reset();

    stopWatch.start();
    match();
    stopWatch.stop();
    logger.info("Matching documents and topics took: " + stopWatch.toString());
    stopWatch.reset();

    // update any documents that had no assignments
    stopWatch.start();
    bulkUpdateDocumentState(DocumentState.PENDING_TOPIC_MATCHING, DocumentState.MATCHED_TO_TOPICS);
    stopWatch.stop();
    logger.info("Marking PENDING_TOPIC_MATCHING documents as MATCHED_TO_TOPICS took: " + stopWatch.toString());
}

From source file:com.mothsoft.alexis.engine.predictive.OpenNLPMaxentModelExecutorTask.java

@Override
public void execute() {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from w  w w  .  j av  a 2 s. c  om

    final List<Long> modelIds = findModelsToExecute();
    final int size = modelIds.size();
    logger.info(String.format("Found %d models in state READY", size));

    int executed = 0;

    for (final Long modelId : modelIds) {
        boolean success = execute(modelId);
        if (success) {
            executed++;
        }
    }

    stopWatch.stop();
    logger.info(String.format("Executed %d of %d models, took: %s", executed, size, stopWatch.toString()));
}

From source file:com.mothsoft.alexis.engine.textual.ParseResponseMessageListener.java

private void updateDocument(final Long documentId, final ParsedContent parsedContent) {
    logger.info("Beginning to update document: " + documentId);

    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from   w  w w.  j a va2s .  c o m*/

    this.transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(final TransactionStatus txStatus) {
            try {
                CurrentUserUtil.setSystemUserAuthentication();
                final Document attachedDocument = ParseResponseMessageListener.this.documentDao.get(documentId);
                attachedDocument.setParsedContent(parsedContent);
            } finally {
                CurrentUserUtil.clearAuthentication();
            }
        }

    });

    stopWatch.stop();
    logger.info("Document update for ID: " + documentId + " took: " + stopWatch.toString());
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public List<TopicDocument> getTopicDocuments(final Long documentId) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from ww w. j  a va 2 s  . co m*/

    final Long userId = CurrentUserUtil.getCurrentUserId();

    final Query query = this.em.createQuery("select td " + "from TopicDocument td join td.topic topic "
            + "where td.document.id = :documentId and topic.userId = :userId " + "order by td.score desc");
    query.setParameter("userId", userId);
    query.setParameter("documentId", documentId);
    @SuppressWarnings("unchecked")
    final List<TopicDocument> filteredTopicDocuments = (List<TopicDocument>) query.getResultList();

    stopWatch.stop();
    logger.debug(stopWatch.toString());
    return filteredTopicDocuments;
}