Example usage for org.springframework.util StopWatch start

List of usage examples for org.springframework.util StopWatch start

Introduction

In this page you can find the example usage for org.springframework.util StopWatch start.

Prototype

public void start(String taskName) throws IllegalStateException 

Source Link

Document

Start a named task.

Usage

From source file:org.fracturedatlas.athena.helper.ticketfactory.manager.TicketFactoryManager.java

public List<Ticket> createTickets(PTicket pTicket) {
    String performanceId = (String) pTicket.getId();
    PTicket performance = athenaStage.get("performance", performanceId);

    //If the performace isn't found, throw a bad request
    if (performance == null) {
        throw new AthenaException("Performance with id [" + performanceId + "] was not found");
    }/*  w  ww  . j ava 2 s  .c  o m*/

    StopWatch watch = new StopWatch();
    watch.start("gathering info");

    String chartId = performance.get("chartId");
    String eventId = performance.get("eventId");
    PTicket chart = athenaStage.get("chart", chartId);
    PTicket event = athenaStage.get("event", eventId);

    AthenaSearchConstraint sectionSearch = new AthenaSearchConstraint("chartId", Operator.EQUALS, chartId);
    AthenaSearch athenaSearch = new AthenaSearch.Builder(sectionSearch).build();
    logger.debug("Finding sections for chart [{}]", chartId);
    Collection<PTicket> sections = athenaStage.find("section", athenaSearch);
    logger.debug("Found [{}] sections", sections.size());

    ArrayList<Ticket> ticketsToCreate = new ArrayList<Ticket>();
    watch.stop();

    //for each section
    for (PTicket section : sections) {
        watch.start("section " + section.get("name"));
        Integer capacity = Integer.parseInt(section.get("capacity"));
        logger.debug("capacity of section [{}] is [{}]", section.getId(), capacity);
        for (int seatNum = 0; seatNum < capacity; seatNum++) {
            Ticket ticket = new Ticket(section, performance, event, INITIAL_STATE);
            ticketsToCreate.add(ticket);

        }
        watch.stop();
    }

    watch.start("creating tickets");
    List<Ticket> tickets = saveTickets(ticketsToCreate);
    watch.stop();
    logger.debug("{}", watch.prettyPrint());
    return tickets;
}

From source file:org.sharetask.utility.log.PerformanceInterceptor.java

@SuppressWarnings("PMD.AvoidCatchingThrowable")
@Override//from w w  w .  ja va2  s.com
protected Object invokeUnderTrace(final MethodInvocation invocation, final Log logger) throws Throwable {
    final String name = invocation.getMethod().getDeclaringClass().getName() + "."
            + invocation.getMethod().getName();
    final StopWatch stopWatch = new StopWatch(name);
    Object returnValue = null;
    try {
        stopWatch.start(name);
        returnValue = invocation.proceed();
        return returnValue;
    } catch (final Throwable ex) {
        if (stopWatch.isRunning()) {
            stopWatch.stop();
        }
        throw ex;
    } finally {
        if (stopWatch.isRunning()) {
            stopWatch.stop();
        }
        writeToLog(logger, replacePlaceholders(exitMessage, invocation, returnValue, null,
                stopWatch.getTotalTimeMillis()));
    }
}

From source file:edu.isistan.carcha.lsa.LSARunner.java

/**
 * Discover traceability.//  w w w. ja va2 s  . co m
 *
 * @param sspaceFile the sspace file
 * @return the traceability document
 * @throws IOException Signals that an I/O exception has occurred.
 */
private TraceabilityDocument discoverTraceability(File sspaceFile) throws IOException {

    TraceabilityDocument ret = new TraceabilityDocument(concerns, designDecision);
    List<TraceabilityLink> links = new ArrayList<TraceabilityLink>();

    StaticSemanticSpace sspace = new StaticSemanticSpace(sspaceFile);

    //build the document vector to compare sentences
    DocumentVectorBuilder builder = new DocumentVectorBuilder(sspace);

    StopWatch sw = new StopWatch();
    sw.start("LSA - Traceability discovery");

    int untracedCount = 0;
    for (Entity req : concerns) {
        //create vector1
        DoubleVector vector1 = builder.buildVector(
                new BufferedReader(new StringReader(req.getFormattedLabel())), new CompactSparseVector());

        boolean hasTrace = false;
        for (Entity arch : designDecision) {
            //create vector2
            DoubleVector vector2 = builder.buildVector(
                    new BufferedReader(new StringReader(arch.getFormattedLabel())), new CompactSparseVector());

            //Math round is WAY faster than DoubleFormat
            Double linkWeight = ((double) Math.round(Similarity.cosineSimilarity(vector1, vector2) * 100)
                    / 100);

            //add the edge between the two nodes including the calculated weight
            if (linkWeight > threshold) {
                links.add(new TraceabilityLink(req, arch, linkWeight));
                hasTrace = true;
            }
        }
        if (!hasTrace) {
            untracedCount++;
        }
    }
    sw.stop();
    logger.info(sw.prettyPrint());

    //save the traceability results like: untraced count, links, traced count, etc...
    ret.setLinks(links);
    ret.setUntracedConcernCount(untracedCount);
    ret.setTracedConcernCount(concerns.size() - untracedCount);
    return ret;
}

From source file:com.emc.smartcomm.UregApplication.java

/**
 * @param register A SmartRegister instance 
 */// w  ww  .  j av a2s  . c o m
public void uregApplication(SmartRegister register) {

    logger.info("Processing UREG Tranasctional Flow:");
    GrsiRequest greq = PopulateData.setGrsiRequest();
    GrsiResponse grsiResponse = PopulateData.setGrsiResponse();
    BabProtocolRequest breq = PopulateData.setBabRequest();
    BabProtocolResponse bres = PopulateData.setBabResponse();
    ValidateRegRequest vreg = PopulateData.setValidateRegRequest();
    ValidateRegResponse vres = PopulateData.setValidateRegResponse();
    greq.setSvcFlag(register.getChannel());
    String msg = register.toString();
    String path = "/appl/LogTransaction.txt";

    Timestamp txStartTime = PrepareLog.getCurrentTimeStamp();
    StopWatch sw = new StopWatch("UREG Transaction");
    sw.start("UREG Transaction");
    logger.debug("UREG Transaction Initiated:{}", txStartTime);
    StopWatch sw0 = new StopWatch("UREG REQUEST");
    sw0.start("UREG REQUEST");
    uregTemplate.convertAndSend(msg);
    sw0.stop();
    logger.debug(sw0.prettyPrint());
    logger.debug(sw0.shortSummary());

    StopWatch sw1 = new StopWatch("GRSI Request");
    sw1.start("GRSI Request");
    grsiTemplate.convertAndSend(greq);
    sw1.stop();
    logger.debug(sw1.prettyPrint());
    logger.debug(sw1.shortSummary());

    if ("PVS".equals(grsiResponse.getsx12())) // || "BAB".equals(grsiResponse.getsx13()))
    {
        StopWatch sw2 = new StopWatch("Validate Request:");
        sw2.start("Validate Request:");
        String validateRegText = vreg.toString();
        validateRegTemplate.convertAndSend(validateRegText);
        sw2.stop();
        logger.debug(sw2.prettyPrint());
        logger.debug(sw2.shortSummary());
    }

    if ("PPC".equals(grsiResponse.getsx03())) {

        StopWatch sw3 = new StopWatch("BAB Request");
        sw3.start("BAB Request:");
        babTemplate.convertAndSend("bab.Request", breq.toString());
        sw3.stop();
        logger.debug(sw3.prettyPrint());
        logger.debug(sw3.shortSummary());
    }

    grsiResponse.setsx03("NSN");
    if ("NSN".equals(grsiResponse.getsx03())) {

        InputStream is = getClass().getResourceAsStream("/mock/SOAPProtocolRecharge.txt");
        String message = FileReader.readFile(is);
        StopWatch sw4 = new StopWatch("SOAP Recharge Request: ");
        sw4.start("SOAP Recharge Request:");
        soapRechargeTemplate.convertAndSend(message);
        sw4.stop();
        logger.debug(sw4.prettyPrint());
        logger.debug(sw4.shortSummary());

    }

    Timestamp txEndTime = PrepareLog.getCurrentTimeStamp();
    logger.debug("Persisting Transaction log in gemxd and oracle");
    LogTransaction logTransaction = PrepareLog.prepareLog(greq, grsiResponse, breq, bres, vreg, vres);
    logTransaction.setTxnStartTime(txStartTime);
    logTransaction.setTxnEndTime(txEndTime);
    StopWatch sw5 = new StopWatch("Transaction Persistence: ");
    sw5.start("Transaction Persistence:");
    logTransactionService.logTransaction(logTransaction);
    sw5.stop();
    logger.debug(sw5.prettyPrint());
    logger.debug(sw5.shortSummary());
    ExternalFileWriter.writeToFile(path, PopulateData.populateLog());

    sw.stop();
    logger.debug(sw.prettyPrint());
    logger.debug(sw.shortSummary());
    logger.debug("UREG Transaction is Completed:{}", txEndTime);
    logger.info("UREG Transaction TimeSpan:{}", (txEndTime.getTime() - txStartTime.getTime()));

}

From source file:edu.isistan.carcha.lsa.TraceabilityComparator.java

/**
 * Run./*from w w w .  jav  a2s  .c  o m*/
 *
 * @param builder the Vector builder to construct vector using the sspace
 * @param reqConcerns the requirement concerns
 * @param archConcerns the architectural concerns
 */
@SuppressWarnings("unused")
private void run(DocumentVectorBuilder builder, List<String> reqConcerns, List<String> archConcerns) {
    StopWatch sw = new StopWatch();
    sw.start("Start the traceability comparation");
    init();
    int i = 0;
    int count = reqConcerns.size();
    this.untracedCount = 0;
    for (String lineForVector1 : reqConcerns) {
        Entity req = Entity.buildFromString(lineForVector1, NodeType.CC);
        addNode(req);
        //create vector 1
        DoubleVector vector1 = new CompactSparseVector();
        vector1 = builder.buildVector(new BufferedReader(new StringReader(req.getFormattedLabel())), vector1);
        boolean hasTrace = false;
        for (String lineForVector2 : archConcerns) {
            Entity arch = Entity.buildFromString(lineForVector2, NodeType.DD);
            addNode(arch);
            //create vector 2
            DoubleVector vector2 = new CompactSparseVector();
            vector2 = builder.buildVector(new BufferedReader(new StringReader(arch.getFormattedLabel())),
                    vector2);

            //Math round is WAY faster than DoubleFormat
            Double linkWeight = ((double) Math.round(Similarity.cosineSimilarity(vector1, vector2) * 1000)
                    / 1000);

            //add the edge between the two nodes including the calculated weight
            if (linkWeight > threshold) {
                addEdge(req, arch, linkWeight);
                hasTrace = true;
            }
        }
        if (!hasTrace) {
            this.untracedCount++;
        }
    }
    sw.stop();
    logger.info(sw.shortSummary());
    String filename = saveGraph();
}

From source file:com.ethlo.kfka.KfkaApplicationTests.java

@Test
public void testPerformance1() throws InterruptedException {
    kfkaManager.clearAll();/*from   w ww  .j  a  va 2s .c  o  m*/

    final int count = 10_000;
    final StopWatch sw = new StopWatch();
    sw.start("Insert1");
    for (int i = 1; i <= count; i++) {
        kfkaManager.add(new CustomKfkaMessageBuilder().userId(321).payload("otherMessage" + i)
                .timestamp(System.currentTimeMillis()).topic("bar").type("mytype").build());
    }
    sw.stop();

    sw.start("Insert2");
    for (int i = 1; i <= count; i++) {
        kfkaManager.add(new CustomKfkaMessageBuilder().userId(123).payload("myMessage" + 1)
                .timestamp(System.currentTimeMillis()).topic("bar").type("mytype").build());
    }
    sw.stop();

    sw.start("Query");
    final CollectingListener collListener = new CollectingListener();
    kfkaManager.addListener(collListener,
            new KfkaPredicate().topic("bar").relativeOffset(-(count + 10)).addPropertyMatch("userId", 123));
    sw.stop();
    assertThat(collListener.getReceived()).hasSize(count);
    assertThat(collListener.getReceived().get(0).getId()).isEqualTo(count + 1);
    assertThat(collListener.getReceived().get(count - 1).getId()).isEqualTo(count + count);
    logger.info("Timings: {}", sw);
}

From source file:fr.acxio.tools.agia.alfresco.configuration.SimpleNodeFactoryTest.java

@Test
public void testGetNodes() throws Exception {
    FolderDefinition aDefaultNodeDefinition = NodeFactoryUtils.createFolderDefinition("test", null, null, null);

    //      FieldSet aData = new DefaultFieldSet(new String[]{"A", "B", "C"}, new String[]{"A", "B", "C"});

    StopWatch aStopWatch = new StopWatch("testGetNodes");
    aStopWatch.start("Create a node list");

    SimpleNodeFactory aNodeFactory = new SimpleNodeFactory();
    aNodeFactory.setNamespaceContext(namespaceContext);
    aNodeFactory.setNodeDefinition(aDefaultNodeDefinition);
    NodeList aNodeList = aNodeFactory.getNodes(evaluationContext);

    aStopWatch.stop();//w w  w  .ja  va2 s  .c o  m

    assertNotNull(aNodeList);
    assertEquals(1, aNodeList.size());
    assertTrue(aNodeList.get(0) instanceof Folder);
    Folder aFolder = (Folder) aNodeList.get(0);
    assertEquals("test", aFolder.getName());
    assertNotNull(aFolder.getAspects());
    assertEquals(0, aFolder.getAspects().size());
    assertNotNull(aFolder.getAssociations());
    assertEquals(0, aFolder.getAssociations().size());
    assertNotNull(aFolder.getFolders());
    assertEquals(0, aFolder.getFolders().size());
    assertNotNull(aFolder.getDocuments());
    assertEquals(0, aFolder.getDocuments().size());
    assertNull(aFolder.getParent());
    assertEquals("/cm:test", aFolder.getPath());
    assertNotNull(aFolder.getType());
    assertEquals("{http://www.alfresco.org/model/content/1.0}folder", aFolder.getType().toString());

    System.out.println(aStopWatch.prettyPrint());
}

From source file:fr.acxio.tools.agia.alfresco.configuration.SimpleNodeFactoryTest.java

@Test
public void testConditionalTreeGetNodes() throws Exception {
    FolderDefinition aDefaultNodeDefinition = NodeFactoryUtils.createFolderDefinition("test", null, null, null);
    FolderDefinition aFolder1NodeDefinition = NodeFactoryUtils.createFolderDefinition("s1", null, "true", null);
    FolderDefinition aFolder2NodeDefinition = NodeFactoryUtils.createFolderDefinition("s2", null, "false",
            null);/*from   w w w  .  j av  a2 s  . c  om*/
    FolderDefinition aFolder3NodeDefinition = NodeFactoryUtils.createFolderDefinition("s3", null, "true", null);

    aDefaultNodeDefinition.addFolder(aFolder1NodeDefinition);
    aDefaultNodeDefinition.addFolder(aFolder2NodeDefinition);
    aDefaultNodeDefinition.addFolder(aFolder3NodeDefinition);

    DocumentDefinition aDocument1Definition = NodeFactoryUtils.createDocumentDefinition("doc1", null, null,
            null, null, null);
    DocumentDefinition aDocument2Definition = NodeFactoryUtils.createDocumentDefinition("doc2", null, null,
            null, null, null);
    DocumentDefinition aDocument3Definition = NodeFactoryUtils.createDocumentDefinition("doc3", null, null,
            null, null, null);

    aFolder1NodeDefinition.addDocument(aDocument1Definition);
    aFolder1NodeDefinition.addDocument(aDocument2Definition);
    aFolder2NodeDefinition.addDocument(aDocument3Definition);

    StopWatch aStopWatch = new StopWatch("testConditionalTreeGetNodes");
    aStopWatch.start("Create a node list");

    SimpleNodeFactory aNodeFactory = new SimpleNodeFactory();
    aNodeFactory.setNamespaceContext(namespaceContext);
    aNodeFactory.setNodeDefinition(aDefaultNodeDefinition);
    NodeList aNodeList = aNodeFactory.getNodes(evaluationContext);

    aStopWatch.stop();

    assertEquals(5, aNodeList.size());
    assertEquals("/cm:test", ((Folder) aNodeList.get(0)).getPath());
    assertEquals("/cm:test/cm:s1", ((Folder) aNodeList.get(1)).getPath());
    assertEquals("/cm:test/cm:s1/cm:doc1", ((Document) aNodeList.get(2)).getPath());
    assertEquals("/cm:test/cm:s1/cm:doc2", ((Document) aNodeList.get(3)).getPath());
    assertEquals("/cm:test/cm:s3", ((Folder) aNodeList.get(4)).getPath());

    System.out.println(aStopWatch.prettyPrint());
}

From source file:fr.acxio.tools.agia.alfresco.configuration.SimpleNodeFactoryTest.java

@Test
public void testEvaluationGetNodes() throws Exception {
    FolderDefinition aDefaultNodeDefinition = NodeFactoryUtils.createFolderDefinition("test", null, null, null);
    FolderDefinition aFolder1NodeDefinition = NodeFactoryUtils.createFolderDefinition("@{#in['level1']}", null,
            "@{#in['level1'].equals('s1')}", "@{#in['customfoldertype']}");
    FolderDefinition aFolder2NodeDefinition = NodeFactoryUtils.createFolderDefinition("@{#in['level2']}", null,
            "@{#in['level1'].equals('s2')}", null);
    FolderDefinition aFolder3NodeDefinition = NodeFactoryUtils.createFolderDefinition("@{#in['date']}", null,
            "@{#in['level2'].equals('s2')}", null);

    aDefaultNodeDefinition.addFolder(aFolder1NodeDefinition);
    aDefaultNodeDefinition.addFolder(aFolder2NodeDefinition);
    aDefaultNodeDefinition.addFolder(aFolder3NodeDefinition);

    DocumentDefinition aDocument1Definition = NodeFactoryUtils.createDocumentDefinition("my_@{#in['content1']}",
            "Some @{#in['content1']} title", "@{#in['path1']}", "@{#in['encoding']}", "@{#in['mimetype']}",
            "@{#in['customdoctype']}");
    DocumentDefinition aDocument2Definition = NodeFactoryUtils.createDocumentDefinition("my_@{#in['content2']}",
            "Some @{#in['content2']} title", "file:/otherpath/@{#in['filename2']}", null, null, null);
    DocumentDefinition aDocument3Definition = NodeFactoryUtils.createDocumentDefinition("doc3", null, null,
            null, null, null);/* w ww.  j a  v  a  2  s  . c om*/

    aFolder1NodeDefinition.addDocument(aDocument1Definition);
    aFolder1NodeDefinition.addDocument(aDocument2Definition);
    aFolder2NodeDefinition.addDocument(aDocument3Definition);

    StopWatch aStopWatch = new StopWatch("testEvaluationGetNodes");
    aStopWatch.start("Create a node list");

    SimpleNodeFactory aNodeFactory = new SimpleNodeFactory();
    aNodeFactory.setNamespaceContext(namespaceContext);
    aNodeFactory.setNodeDefinition(aDefaultNodeDefinition);
    NodeList aNodeList = aNodeFactory.getNodes(evaluationContext);

    aStopWatch.stop();

    assertEquals(5, aNodeList.size());
    assertEquals("/cm:test", ((Folder) aNodeList.get(0)).getPath());
    assertEquals("/cm:test/custom:s1", ((Folder) aNodeList.get(1)).getPath());
    assertEquals("/cm:test/custom:s1/custom:my_doc1", ((Document) aNodeList.get(2)).getPath());
    assertEquals("/cm:test/custom:s1/cm:my_doc2", ((Document) aNodeList.get(3)).getPath());
    assertEquals("/cm:test/cm:_x0032_012-07-05", ((Folder) aNodeList.get(4)).getPath()); // TODO : check the encoding

    assertEquals("Some doc1 title", NodeFactoryUtils
            .getPropertyValues(aNodeList.get(2), "{http://www.alfresco.org/model/content/1.0}title").get(0));
    assertEquals("Some doc2 title", NodeFactoryUtils
            .getPropertyValues(aNodeList.get(3), "{http://www.alfresco.org/model/content/1.0}title").get(0));
    assertEquals("file:/somepath/content1.pdf", ((Document) aNodeList.get(2)).getContentPath());
    assertEquals("file:/otherpath/content2.pdf", ((Document) aNodeList.get(3)).getContentPath());
    assertEquals("UTF-8", ((Document) aNodeList.get(2)).getEncoding());
    assertEquals("application/pdf", ((Document) aNodeList.get(2)).getMimeType());
    assertEquals("{http://custom}doc", ((Document) aNodeList.get(2)).getType().toString());
    assertEquals("{http://custom}folder", ((Folder) aNodeList.get(1)).getType().toString());

    System.out.println(aStopWatch.prettyPrint());
}

From source file:org.dd4t.core.factories.impl.GenericPageFactory.java

/**
 * Transform source into a page./*ww w.  j ava 2  s.c  om*/
 * 
 * @param source
 * @return
 */
public GenericPage getPageFromSource(String source) {

    StopWatch stopWatch = null;
    try {
        if (logger.isDebugEnabled()) {
            stopWatch = new StopWatch();
            stopWatch.start("getPageFromSource");
        }
        return (GenericPage) this.getSerializer().deserialize(source, GenericPage.class);
    } catch (Exception e) {
        logger.error("Exception when deserializing page: ", e);
        throw new RuntimeException(e);
    } finally {
        if (logger.isDebugEnabled()) {
            stopWatch.stop();
            logger.debug("Deserialization of page took: " + stopWatch.getLastTaskTimeMillis() + " ms");
        }
    }

}