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:org.jasypt.encryption.pbe.PooledPBEWithMD5AndDESStringEncryptorThreadedTest.java

public static void main(String[] args) {
    try {/*from   w  w w .j  a va2  s . com*/

        final int numThreads = Integer.valueOf(args[0]).intValue();
        final int numIters = Integer.valueOf(args[1]).intValue();
        final int poolSize = Integer.valueOf(args[2]).intValue();

        PooledPBEWithMD5AndDESStringEncryptorThreadedTest test = new PooledPBEWithMD5AndDESStringEncryptorThreadedTest(
                numThreads, numIters, poolSize);

        System.out.println("Starting test. NumThreads: " + numThreads + " NumIters: " + numIters + " PoolSize: "
                + poolSize);
        StopWatch sw = new StopWatch();
        sw.start();
        test.testThreadedDigest();
        sw.stop();
        System.out.println("Test finished in: " + sw.toString());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.kuali.ole.docstore.indexer.solr.WorkLicenseDocumentIndexer.java

@Override
public String indexDocuments(List<RequestDocument> requestDocuments, boolean commit) {
    BatchIngestStatistics batchStatistics = BulkIngestStatistics.getInstance().getCurrentBatch();

    String result = null;/* ww w .j  a  v  a 2 s  .  co m*/
    StopWatch timer = new StopWatch();
    StopWatch xmlToObjTime = new StopWatch();
    xmlToObjTime.start();
    xmlToObjTime.suspend();
    timer.start();
    List<SolrInputDocument> solrInputDocuments = new ArrayList<SolrInputDocument>();
    if (requestDocuments != null && requestDocuments.size() > 0) {
        StopWatch buildSolrInputDocTime = new StopWatch();
        StopWatch xmlToPojoTimer = new StopWatch();
        buildSolrInputDocTime.start();
        buildSolrInputDocTime.suspend();
        xmlToPojoTimer.start();
        xmlToPojoTimer.suspend();
        try {
            for (RequestDocument requestDocument : requestDocuments) {
                if (DocFormat.ONIXPL.isEqualTo((requestDocument.getFormat()))) { //onixpl
                    new WorkLicenseOnixplDocBuilder().buildSolrInputDocument(requestDocument,
                            solrInputDocuments);
                } else if ((DocFormat.PDF.isEqualTo((requestDocument.getFormat())))
                        || DocFormat.DOC.isEqualTo(requestDocument.getFormat())
                        || DocFormat.XSLT.isEqualTo(requestDocument.getFormat())) { //pdf
                    new WorkLicenseBinaryDocBuilder().buildSolrInputDocument(requestDocument,
                            solrInputDocuments);
                } else {
                    throw new Exception(
                            "Unsupported Document Format : " + requestDocument.getFormat() + " Called.");
                }
                assignUUIDs(solrInputDocuments, null);
            }
        } catch (Exception e1) {
            result = buildFailureMsg(null, "Indexing failed. " + e1.getMessage());
            logger.error(result, e1);
        }
        timer.stop();
        if ((null == solrInputDocuments) || (solrInputDocuments.isEmpty())) {
            result = buildFailureMsg(null, "No valid documents found in input.");
            return result;
        }
        int numDocs = solrInputDocuments.size();
        batchStatistics.setTimeToConvertXmlToPojo(xmlToPojoTimer.getTime());
        batchStatistics.setTimeToConvertToSolrInputDocs(buildSolrInputDocTime.getTime());
        logger.info("Conversion to Solr docs- Num:" + numDocs + ": Time taken:" + timer.toString());
        result = indexSolrDocuments(solrInputDocuments, commit);
    }
    return result;
}

From source file:org.kuali.ole.docstore.process.RebuildIndexesHandler.java

private void indexBibDocs(List<BibTree> bibTreeList, long records, long recCount,
        List<ReIndexingBatchStatus> batchStatusList, ReIndexingBatchStatus reIndexingBatchStatus) {
    StopWatch indexTimer = new StopWatch();
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
    try {//from   w  w w  . jav a2 s  .  c  om
        Date startDate = new Date();
        reIndexingBatchStatus.setBatchStartTime(dateFormat.format(startDate));
        indexTimer.start();
        reIndexingBatchStatus.setStatus("Indexing");
        reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
        reIndexingBatchStatus.setRecordsProcessed(records);
        reIndexingBatchStatus.setBatchEndTime(" ");
        batchStatusList.add(reIndexingBatchStatus);
        ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
        DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
        BibTrees bibTrees = new BibTrees();
        bibTrees.getBibTrees().addAll(bibTreeList);
        documentIndexer.createTrees(bibTrees);
        //logger.debug(result);
        indexTimer.stop();
        Date endDate = new Date();
        reIndexingBatchStatus.setBatchEndTime(dateFormat.format(endDate));
        reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
        reIndexingBatchStatus.setRecordsProcessed(records);
        reIndexingBatchStatus.setStatus("Done");
        reIndexingBatchStatus.setRecordsRemaining(recCount - records);
        ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
        bibTreeList.clear();
    } catch (Exception e) {
        String firstBibId = bibTreeList.get(0).getBib().getId();
        String lastBibId = bibTreeList.get(bibTreeList.size() - 1).getBib().getId();
        logger.error("Rebuild Indexes Process(" + docCategory + " : " + docType + " : " + docFormat
                + ") Processed(" + (records - bibTreeList.size()) + "), Failed @ bibId( First BibId: "
                + firstBibId + "   :  Last BibId : " + lastBibId + "): Cause: " + e, e);
        indexTimer.stop();
        Date endDate = new Date();
        reIndexingBatchStatus.setBatchEndTime(dateFormat.format(endDate));
        reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
        reIndexingBatchStatus.setRecordsProcessed(0L);
        reIndexingBatchStatus.setStatus("Done");
        reIndexingBatchStatus.setRecordsRemaining(recCount - records);
        ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
        bibTreeList.clear();
    }
}

From source file:org.kuali.ole.docstore.process.RebuildIndexesHandler.java

private void indexDocs(List<RequestDocument> docs, long records, long recCount,
        List<ReIndexingBatchStatus> batchStatusList, ReIndexingBatchStatus reIndexingBatchStatus) {
    try {//from   w w w  .  j av  a 2  s.  c om
        StopWatch indexTimer = new StopWatch();
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
        Date startDate = new Date();
        reIndexingBatchStatus.setBatchStartTime(dateFormat.format(startDate));
        indexTimer.start();
        reIndexingBatchStatus.setStatus("Indexing");
        reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
        reIndexingBatchStatus.setRecordsProcessed(records);
        reIndexingBatchStatus.setBatchEndTime(" ");
        batchStatusList.add(reIndexingBatchStatus);
        ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
        IndexerService indexerService = BeanLocator.getDocstoreFactory().getDocumentIndexManager(
                docs.get(0).getCategory(), docs.get(0).getType(), docs.get(0).getFormat());
        String result = indexerService.indexDocuments(docs, false);
        logger.debug(result);
        indexTimer.stop();
        Date endDate = new Date();
        reIndexingBatchStatus.setBatchEndTime(dateFormat.format(endDate));
        reIndexingBatchStatus.setBatchIndexingTime(indexTimer.toString());
        reIndexingBatchStatus.setRecordsProcessed(records);
        reIndexingBatchStatus.setStatus("Done");
        reIndexingBatchStatus.setRecordsRemaining(recCount - records);
        ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
        docs.clear();
    } catch (Exception e) {
        logger.error("Rebuild Indexes Processed(" + (records - docs.size()) + "), Failed @ batch(" + docs.size()
                + "): Cause: " + e + "\n\tContinuous", e);
    }
}

From source file:org.kuali.ole.docstore.process.RebuildIndexesHandler.java

private void indexAfterParams(StopWatch batchTimer, ReIndexingBatchStatus reIndexingBatchStatus,
        List<ReIndexingBatchStatus> batchStatusList) {
    batchTimer.stop();/*from  ww  w. jav a2s.  c o  m*/
    reIndexingBatchStatus.setBatchTotalTime(batchTimer.toString());
    ReIndexingStatus.getInstance().getDocTypeList().setReIndBatStatusList(batchStatusList);
}

From source file:org.kuali.ole.docstore.process.RebuildIndexesHandler.java

private ReIndexingBatchStatus indexBeforeParams(StopWatch loadTimer) {
    loadTimer.stop();/* www .  j ava2s .com*/
    ReIndexingBatchStatus reIndexingBatchStatus = new ReIndexingBatchStatus();
    reIndexingBatchStatus.setBatchTotalTime(" ");
    reIndexingBatchStatus.setBatchLoadTime(loadTimer.toString());
    return reIndexingBatchStatus;
}

From source file:org.kuali.ole.docstore.service.DocumentIngester.java

/**
 * Method to ingest a Bib RequestDocument using Btree manager.
 *
 * @param reqDocs/* w  w w.  j  ava2s.  c o m*/
 * @param session
 * @param formatNode
 * @return
 * @throws Exception
 */
protected synchronized List<Node> ingestBibDocumentUsingBTreeMgr(List<RequestDocument> reqDocs, Session session,
        Node formatNode) throws Exception {
    List<Node> fileNodes = null;
    fileNodes = new ArrayList<Node>();
    try {
        /*String file = "file";
        if (DocFormat.MARC.isEqualTo(reqDoc.getFormat()))
        file = FILE_MARC;
        else
        file = reqDoc.getFormat() + FILE;
        Node bibFormatNode = null;
        if (formatNode == null)
        bibFormatNode = getStaticFormatNode(reqDoc, session);
        else
        bibFormatNode = formatNode;
        Node l3 = null;
        synchronized (nodeHandler) {
        Node l1 = nodeHandler.initLevelNode(NODE_LEVEL1, bibFormatNode, false, session);
        Node l2 = nodeHandler.initLevelNode(NODE_LEVEL2, l1, false, session);
        l3 = nodeHandler.initLevelNode(NODE_LEVEL3, l2, false, session);
        } */
        StopWatch btreeTimer = new StopWatch();
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
        Date date = new Date();
        btreeTimer.start();
        treeManager = new BTreeManager(formatNode, 500, 1000, Rank.<String>comparableComparator(), true);
        // Create a new NodeSequence with that tree manager
        nodeSequence = ItemSequence.createNodeSequence(treeManager);
        btreeTimer.stop();
        logger.info("Time taken for initializing btree manager sequence=" + btreeTimer.toString());
        StopWatch btreeAddNodeTimer = new StopWatch();
        Node node = null;
        btreeAddNodeTimer.start();
        Random generator = new Random(19580427);
        Format formatter = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
        Date date1 = null;
        for (RequestDocument reqDoc : reqDocs) {
            node = null;
            date1 = new Date();
            String dateStr = formatter.format(date1);
            node = nodeSequence.addNode(dateStr + "-" + generator.nextInt(), NodeType.NT_UNSTRUCTURED);
            nodeHandler.initFileNode(node, reqDoc, FILE_MARC, null, session);
            fileNodes.add(node);
            //i++;
        }
        btreeAddNodeTimer.stop();
        logger.info(
                "Time taken for adding " + reqDocs.size() + " nodes to btree: " + btreeAddNodeTimer.toString());

    } catch (Exception e) {
        logger.error("Ingest failed for RequestDocument: ", e);
        throw new Exception(e);
    }
    return fileNodes;
}

From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoFormBase.java

/**
 * Populates the form with values from the current request. Uses instances of Formatter to convert strings to the Java types of
 * the properties to which they are bound. Values that can't be converted are cached in a map of unconverted values. Returns an
 * ActionErrors containing ActionMessage instances for each conversion error that occured, if any.
 *///  ww w .j  a  v a  2  s  .c o  m
@Override
public void populate(HttpServletRequest request) {

    StopWatch watch = null;
    if (LOG.isDebugEnabled()) {
        watch = new StopWatch();
        watch.start();
        LOG.debug(WATCH_NAME + ": started");
    }
    unconvertedValues.clear();
    unknownKeys = new ArrayList();
    addRequiredNonEditableProperties();
    Map params = request.getParameterMap();

    String contentType = request.getContentType();
    String method = request.getMethod();

    if ("POST".equalsIgnoreCase(method) && contentType != null
            && contentType.startsWith("multipart/form-data")) {
        Map fileElements = (HashMap) request.getAttribute(KRADConstants.UPLOADED_FILE_REQUEST_ATTRIBUTE_KEY);
        Enumeration names = Collections.enumeration(fileElements.keySet());
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            params.put(name, fileElements.get(name));
        }
    }

    postprocessRequestParameters(params);

    /**
     * Iterate through request parameters, if parameter matches a form variable, get the property type, formatter and convert,
     * if not add to the unknowKeys map.
     */
    Comparator<String> nestedPathComparator = new Comparator<String>() {
        public int compare(String prop1, String prop2) {
            Integer i1 = new Integer(prop1.split("\\.").length);
            Integer i2 = new Integer(prop2.split("\\.").length);
            return (i1.compareTo(i2));
        }
    };

    List<String> pathKeyList = new ArrayList<String>(params.keySet());
    Collections.sort(pathKeyList, nestedPathComparator);

    for (String keypath : pathKeyList) {
        if (shouldPropertyBePopulatedInForm(keypath, request)) {
            Object param = params.get(keypath);
            //LOG.debug("(keypath,paramType)=(" + keypath + "," + param.getClass().getName() + ")");

            populateForProperty(keypath, param, params);
        }
    }
    this.registerIsNewForm(false);
    if (LOG.isDebugEnabled()) {
        watch.stop();
        LOG.debug(WATCH_NAME + ": " + watch.toString());
    }
}

From source file:org.kuali.rice.krad.service.impl.DocumentServiceImpl.java

/**
 * Creates a new document by document type name. The principal name
 * passed in will be used as the document initiator.  If the  initiatorPrincipalNm
 * is null or blank, the current user will be used.
 *
 * @see org.kuali.rice.krad.service.DocumentService#getNewDocument(String, String)
 *///from  w ww .  j a  v a 2s .  c o m
@Override
public Document getNewDocument(String documentTypeName, String initiatorPrincipalNm) throws WorkflowException {

    // argument validation
    String watchName = "DocumentServiceImpl.getNewDocument";
    StopWatch watch = new StopWatch();
    watch.start();
    if (LOG.isDebugEnabled()) {
        LOG.debug(watchName + ": started");
    }
    if (StringUtils.isBlank(documentTypeName)) {
        throw new IllegalArgumentException("invalid (blank) documentTypeName");
    }
    if (GlobalVariables.getUserSession() == null) {
        throw new IllegalStateException(
                "GlobalVariables must be populated with a valid UserSession before a new document can be created");
    }

    // get the class for this docTypeName
    Class<? extends Document> documentClass = getDocumentClassByTypeName(documentTypeName);

    // get the initiator
    Person initiator = null;
    if (StringUtils.isBlank(initiatorPrincipalNm)) {
        initiator = GlobalVariables.getUserSession().getPerson();
    } else {
        initiator = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(initiatorPrincipalNm);
        if (initiator == null) {
            initiator = GlobalVariables.getUserSession().getPerson();
        }
    }

    // get the authorization
    DocumentAuthorizer documentAuthorizer = getDocumentDictionaryService()
            .getDocumentAuthorizer(documentTypeName);
    DocumentPresentationController documentPresentationController = getDocumentDictionaryService()
            .getDocumentPresentationController(documentTypeName);
    // make sure this person is authorized to initiate
    if (LOG.isDebugEnabled()) {
        LOG.debug("calling canInitiate from getNewDocument(" + documentTypeName + "," + initiatorPrincipalNm
                + ")");
    }
    if (!documentPresentationController.canInitiate(documentTypeName)
            || !documentAuthorizer.canInitiate(documentTypeName, initiator)) {
        throw new DocumentAuthorizationException(initiator.getPrincipalName(), "initiate", documentTypeName);
    }

    // initiate new workflow entry, get the workflow doc
    WorkflowDocument workflowDocument = getWorkflowDocumentService().createWorkflowDocument(documentTypeName,
            initiator);
    UserSessionUtils.addWorkflowDocument(GlobalVariables.getUserSession(), workflowDocument);

    // create a new document header object
    DocumentHeader documentHeader = new DocumentHeader();
    documentHeader.setWorkflowDocument(workflowDocument);
    documentHeader.setDocumentNumber(workflowDocument.getDocumentId());

    // build Document of specified type
    Document document = null;
    try {
        // all maintenance documents have same class
        if (MaintenanceDocumentBase.class.isAssignableFrom(documentClass)) {
            Class<?>[] defaultConstructor = new Class[] { String.class };
            Constructor<? extends Document> cons = documentClass.getConstructor(defaultConstructor);
            if (cons == null) {
                throw new ConfigurationException(
                        "Could not find constructor with document type name parameter needed for Maintenance Document Base class");
            }
            document = cons.newInstance(documentTypeName);
        } else {
            // non-maintenance document
            document = documentClass.newInstance();
        }
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Error instantiating Document", e);
    } catch (InstantiationException e) {
        throw new RuntimeException("Error instantiating Document", e);
    } catch (SecurityException e) {
        throw new RuntimeException("Error instantiating Maintenance Document", e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(
                "Error instantiating Maintenance Document: No constructor with String parameter found", e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Error instantiating Maintenance Document", e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Error instantiating Maintenance Document", e);
    }

    document.setDocumentHeader(documentHeader);
    document.setDocumentNumber(documentHeader.getDocumentNumber());

    watch.stop();
    if (LOG.isDebugEnabled()) {
        LOG.debug(watchName + ": " + watch.toString());
    }

    return document;
}

From source file:org.kuali.rice.krad.workflow.service.impl.WorkflowDocumentServiceImpl.java

@Override
public WorkflowDocument createWorkflowDocument(String documentTypeName, Person person) {
    String watchName = "createWorkflowDocument";
    StopWatch watch = null;
    if (LOG.isDebugEnabled()) {
        watch = new StopWatch();
        watch.start();// w ww. j a v a 2 s  .  c om
        LOG.debug(watchName + ": started");
    }
    if (StringUtils.isBlank(documentTypeName)) {
        throw new IllegalArgumentException("invalid (blank) documentTypeName");
    }
    if (person == null) {
        throw new IllegalArgumentException("invalid (null) person");
    }

    if (StringUtils.isBlank(person.getPrincipalName())) {
        throw new IllegalArgumentException("invalid (empty) PrincipalName");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("creating workflowDoc(" + documentTypeName + "," + person.getPrincipalName() + ")");
    }

    WorkflowDocument document = WorkflowDocumentFactory.createDocument(person.getPrincipalId(),
            documentTypeName);
    if (watch != null) {
        watch.stop();
        LOG.debug(watchName + ": " + watch.toString());
    }

    return document;
}