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:com.excilys.ebi.spring.dbunit.DbUnitDatabasePopulator.java

@Override
public void populate(Connection connection) throws SQLException {

    LOGGER.debug("populating");

    StopWatch sw = new StopWatch("DbUnitDatabasePopulator");

    DatabaseOperation operation = phase.getOperation(dataSetConfiguration);
    try {//from w  w  w.  ja va  2  s .  c o m
        IDataSet dataSet = decorateDataSetIfNeeded(dataSetConfiguration.getDataSet(),
                dataSetConfiguration.getDecorators());
        String schema = dataSetConfiguration.getSchema();
        DatabaseConnection databaseConnection = getDatabaseConnection(connection, schema, dataSetConfiguration);
        sw.start("populating");
        operation.execute(databaseConnection, dataSet);
        sw.stop();
        LOGGER.debug(sw.prettyPrint());

    } catch (BatchUpdateException e) {
        LOGGER.error("BatchUpdateException while loading dataset", e);
        LOGGER.error("Caused by : ", e.getNextException());
        throw e;

    } catch (DatabaseUnitException e) {
        throw new DbUnitException(e);
    } catch (IOException e) {
        throw new DbUnitException(e);
    }
}

From source file:de.uniwue.dmir.heatmap.heatmaps.DefaultHeatmap.java

@Override
public TTile getTile(TileCoordinates tileCoordinates) {

    // initializing stop watch
    StopWatch stopWatch = new StopWatch();

    // tile coordinates to top-left reference system
    TileCoordinates projectedTileCoordinates = this.settings.getTileProjection()
            .fromCustomToTopLeft(tileCoordinates, this.settings.getZoomLevelMapper());

    // loading data seed 

    this.logger.debug("Loading data seed.");

    stopWatch.start("loading data seed");

    TTile tile = this.seed.getTile(projectedTileCoordinates);

    stopWatch.stop();//from   w ww  . j a v  a2s .c o m
    if (tile == null) {
        this.logger.debug("No data seed available: {}", stopWatch.toString());
    } else {
        this.logger.debug("Done loading data seed: {}", stopWatch.toString());
    }

    // get data

    this.logger.debug("Loading data points.");

    stopWatch.start("loading data points");

    Iterator<TPoint> externalData = this.pointsource.getPoints(projectedTileCoordinates, this.filter);

    stopWatch.stop();
    this.logger.debug("Done loading data points: {}", stopWatch.toString());

    // return null if no data was found
    if (externalData == null || !externalData.hasNext()) {

        this.logger.debug("No external data found for this tile: {}", tileCoordinates);

        if (tile == null) {

            this.logger.debug("No data seed available for his tile: returnung null.");
            return null;

        } else if (!this.returnSeedTilesWithNoExternalData) {

            this.logger.debug("Data seed available, but no external data found: returning null.");
            return null;
        }

    }

    // initializing tile if no seed is available
    if (tile == null) {
        this.logger.debug("No data seed available; initializing empty tile.");
        tile = this.tileFactory.newInstance(this.settings.getTileSize(), projectedTileCoordinates);
    }

    // add external data to tile

    this.logger.debug("Adding data points to tile: {}", tileCoordinates);

    stopWatch.start("adding data points to tile");

    int externalDataPointCount = 0;
    while (externalData.hasNext()) {
        TPoint externalDataPoint = externalData.next();
        this.filter.filter(externalDataPoint, tile, this.settings.getTileSize(), tileCoordinates);
        externalDataPointCount++;
    }

    stopWatch.stop();
    this.logger.debug("Done adding {} data points to tile: {}", externalDataPointCount, stopWatch.toString());

    return tile;
}

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testLargeMatchingPrimitiveArray() {
    if (LogFactory.getLog(BeanWrapperTests.class).isTraceEnabled()) {
        // Skip this test: Trace logging blows the time limit.
        return;//w  w  w . j  a  va  2  s  . co m
    }

    PrimitiveArrayBean tb = new PrimitiveArrayBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(tb);
    int[] input = new int[1024];
    StopWatch sw = new StopWatch();
    sw.start("array1");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    long time1 = sw.getLastTaskTimeMillis();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
    sw.start("array2");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

    bw.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
    sw.start("array3");
    for (int i = 0; i < 1000; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

    bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
    sw.start("array4");
    for (int i = 0; i < 100; i++) {
        bw.setPropertyValue("array", input);
    }
    sw.stop();
    assertEquals(1024, tb.getArray().length);
    assertEquals(0, tb.getArray()[0]);
    assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}

From source file:sample.contact.ClientApplication.java

public void invokeContactService(Authentication authentication, int nrOfCalls) {
    StopWatch stopWatch = new StopWatch(nrOfCalls + " ContactService call(s)");
    Map<String, ContactService> contactServices = this.beanFactory.getBeansOfType(ContactService.class, true,
            true);/* w w w  . ja v a2  s .  co m*/

    SecurityContextHolder.getContext().setAuthentication(authentication);

    for (String beanName : contactServices.keySet()) {
        Object object = this.beanFactory.getBean("&" + beanName);

        try {
            System.out.println("Trying to find setUsername(String) method on: " + object.getClass().getName());

            Method method = object.getClass().getMethod("setUsername", new Class[] { String.class });
            System.out.println("Found; Trying to setUsername(String) to " + authentication.getPrincipal());
            method.invoke(object, authentication.getPrincipal());
        } catch (NoSuchMethodException ignored) {
            System.out.println("This client proxy factory does not have a setUsername(String) method");
        } catch (IllegalAccessException ignored) {
            ignored.printStackTrace();
        } catch (InvocationTargetException ignored) {
            ignored.printStackTrace();
        }

        try {
            System.out.println("Trying to find setPassword(String) method on: " + object.getClass().getName());

            Method method = object.getClass().getMethod("setPassword", new Class[] { String.class });
            method.invoke(object, authentication.getCredentials());
            System.out.println("Found; Trying to setPassword(String) to " + authentication.getCredentials());
        } catch (NoSuchMethodException ignored) {
            System.out.println("This client proxy factory does not have a setPassword(String) method");
        } catch (IllegalAccessException ignored) {
        } catch (InvocationTargetException ignored) {
        }

        ContactService remoteContactService = contactServices.get(beanName);
        System.out.println("Calling ContactService '" + beanName + "'");

        stopWatch.start(beanName);

        List<Contact> contacts = null;

        for (int i = 0; i < nrOfCalls; i++) {
            contacts = remoteContactService.getAll();
        }

        stopWatch.stop();

        if (contacts.size() != 0) {
            for (Contact contact : contacts) {
                System.out.println("Contact: " + contact);
            }
        } else {
            System.out.println("No contacts found which this user has permission to");
        }

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

    SecurityContextHolder.clearContext();
}

From source file:com.jxt.web.controller.ScatterChartController.java

/**
 * @param applicationName//w  ww. j a v  a2  s  .co m
 * @param from
 * @param to
 * @param limit           max number of data return. if the requested data exceed this limit, we need additional calls to
 *                        fetch the rest of the data
 * @return
 */
@RequestMapping(value = "/getScatterData", method = RequestMethod.GET)
public ModelAndView getScatterData(@RequestParam("application") String applicationName,
        @RequestParam("from") long from, @RequestParam("to") long to,
        @RequestParam("xGroupUnit") int xGroupUnit, @RequestParam("yGroupUnit") int yGroupUnit,
        @RequestParam("limit") int limit,
        @RequestParam(value = "backwardDirection", required = false, defaultValue = "true") boolean backwardDirection,
        @RequestParam(value = "filter", required = false) String filterText,
        @RequestParam(value = "_callback", required = false) String jsonpCallback,
        @RequestParam(value = "v", required = false, defaultValue = "1") int version) {
    limit = LimitUtils.checkRange(limit);

    StopWatch watch = new StopWatch();
    watch.start("getScatterData");

    // TODO range check verification exception occurs. "from" is bigger than "to"
    final Range range = Range.createUncheckedRange(from, to);
    logger.debug(
            "fetch scatter data. RANGE={}, X-Group-Unit:{}, Y-Group-Unit:{}, LIMIT={}, BACKWARD_DIRECTION:{}, FILTER:{}",
            range, xGroupUnit, yGroupUnit, limit, backwardDirection, filterText);

    ModelAndView mv = null;
    if (StringUtils.isEmpty(filterText)) {
        mv = selectScatterData(applicationName, range, xGroupUnit, yGroupUnit, limit, backwardDirection,
                version);
    } else {
        mv = selectFilterScatterData(applicationName, range, xGroupUnit, yGroupUnit, limit, backwardDirection,
                filterText, version);
    }

    if (jsonpCallback == null) {
        mv.setViewName("jsonView");
    } else {
        mv.setViewName("jsonpView");
    }

    watch.stop();

    logger.info("Fetch scatterData time : {}ms", watch.getLastTaskTimeMillis());

    return mv;
}

From source file:com.navercorp.pinpoint.web.controller.ScatterChartController.java

/**
 * @param applicationName//from  w  w w . java2s.co m
 * @param from
 * @param to
 * @param limit           max number of data return. if the requested data exceed this limit, we need additional calls to
 *                        fetch the rest of the data
 * @return
 */
@RequestMapping(value = "/getScatterData", method = RequestMethod.GET)
public ModelAndView getScatterData(@RequestParam("application") String applicationName,
        @RequestParam("from") long from, @RequestParam("to") long to,
        @RequestParam("xGroupUnit") int xGroupUnit, @RequestParam("yGroupUnit") int yGroupUnit,
        @RequestParam("limit") int limit,
        @RequestParam(value = "backwardDirection", required = false, defaultValue = "true") boolean backwardDirection,
        @RequestParam(value = "filter", required = false) String filterText,
        @RequestParam(value = "_callback", required = false) String jsonpCallback,
        @RequestParam(value = "v", required = false, defaultValue = "1") int version) {
    if (xGroupUnit <= 0) {
        throw new IllegalArgumentException("xGroupUnit(" + xGroupUnit + ") must be positive number");
    }
    if (yGroupUnit < 0) {
        throw new IllegalArgumentException("yGroupUnit(" + yGroupUnit + ") may not be negative number");
    }

    limit = LimitUtils.checkRange(limit);

    StopWatch watch = new StopWatch();
    watch.start("getScatterData");

    // TODO range check verification exception occurs. "from" is bigger than "to"
    final Range range = Range.createUncheckedRange(from, to);
    logger.debug(
            "fetch scatter data. RANGE={}, X-Group-Unit:{}, Y-Group-Unit:{}, LIMIT={}, BACKWARD_DIRECTION:{}, FILTER:{}",
            range, xGroupUnit, yGroupUnit, limit, backwardDirection, filterText);

    ModelAndView mv = null;
    if (StringUtils.isEmpty(filterText)) {
        mv = selectScatterData(applicationName, range, xGroupUnit, Math.max(yGroupUnit, 1), limit,
                backwardDirection, version);
    } else {
        mv = selectFilterScatterData(applicationName, range, xGroupUnit, Math.max(yGroupUnit, 1), limit,
                backwardDirection, filterText, version);
    }

    if (jsonpCallback == null) {
        mv.setViewName("jsonView");
    } else {
        mv.setViewName("jsonpView");
    }

    watch.stop();

    logger.info("Fetch scatterData time : {}ms", watch.getLastTaskTimeMillis());

    return mv;
}

From source file:no.abmu.abmstatistikk.annualstatistic.service.hibernate2.AnnualStatisticServiceHelper.java

private ReportStatus[] getReportStatusBySchemaTypeAndYear(ReportStatus[] reportStatusSurvey,
        String schemaTypeName, int reportYear) {

    StopWatch stopWatch = new StopWatch();

    Long orgUnitId;//w w w  .ja  v a  2 s.  c o  m
    ReportStatus reportStatus;
    String reportFinish;
    Report report;
    ReportHelper reportHelper;
    Answer answer;
    String reportFinishAnswer;

    int numberOfReports = reportStatusSurvey.length;

    String finishFieldNumber = getFinishFieldNumberForSchemaTypeAndReportYear(schemaTypeName, reportYear);

    if (numberOfReports > 1) {
        logger.info("Start prosessing of reportStatus for schemaType:" + schemaTypeName + " with "
                + numberOfReports + " elements");
    }
    stopWatch.start("getReportStatusBySchemaTypeAndYear");

    for (int row = 0; row < reportStatusSurvey.length; row++) {
        reportStatus = reportStatusSurvey[row];
        orgUnitId = reportStatus.getOrganisationUnitId();

        StopWatch stopWatchForGetReport = new StopWatch();
        stopWatchForGetReport.start("test");

        report = service.getReport(orgUnitId.longValue(), schemaTypeName, reportYear, false);

        stopWatchForGetReport.stop();
        logger.info("Getting report for organisationUnitId: '" + orgUnitId + "' and schemaType: "
                + schemaTypeName + " tok [" + stopWatchForGetReport.getTotalTimeMillis() + "] ms");

        if (report != null) {
            //                reportStatus.setReport("Ja");
            StopWatch stopWatchForCreatingReportHelper = new StopWatch();
            stopWatchForCreatingReportHelper.start("ReportHelper");

            reportHelper = new ReportHelper(report);
            answer = reportHelper.getAnswerByFieldName(finishFieldNumber);

            stopWatchForCreatingReportHelper.stop();
            logger.info("Getting reportHelper and answer for organisationUnitId: '" + orgUnitId
                    + "' and schemaType: " + schemaTypeName + " tok ["
                    + stopWatchForCreatingReportHelper.getTotalTimeMillis() + "] ms");

            if (answer != null) {
                reportFinishAnswer = answer.getValue();
                if (reportFinishAnswer != null) {
                    reportFinish = (reportFinishAnswer.equals("true") ? "Ja" : "Nei");
                    //                        reportStatus.setReportFinish(reportFinish);
                }
            }
        }
        if (((row + 1) % 100) == 0) {
            logger.info("Has processed reportStatus " + (row + 1) + " of " + numberOfReports
                    + " for schemaType:" + schemaTypeName);
        }
    }

    stopWatch.stop();

    if (numberOfReports > 1) {
        logger.info("Finish prosessing of reportStatus for schemaType:" + schemaTypeName + " with "
                + numberOfReports + " elements in " + stopWatch.getTotalTimeMillis() + " ms");
    }

    return reportStatusSurvey;

}

From source file:no.abmu.abmstatistikk.annualstatistic.webflow.AnnualStatisticFormAction.java

protected Object createFormObject(RequestContext context) {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing createFormObject");
    }//from w  w  w .j  a  v a 2s . com
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("createFormObject");

    WebSchemaDefinition webSchema = webFlowService.createWebSchema(context);

    String submitEvent = context.getRequestParameters().get("_eventId_submit.y");
    if (submitEvent == null) {
        // Getting values from database into webSchema 
        // and show these values to user
        // e.g. webSchema --> formObject to user
        if (logger.isDebugEnabled()) {
            logger.debug("[createFormObject] submitEvent == null (webSchema --> formObject to user) ");
        }
    } else {
        // Getting values from user and sending user input 
        // to binding and eventually validation.
        // e.g. webSchema --> formObject from user
        if (logger.isDebugEnabled()) {
            logger.debug("[createFormObject] submitEvent != null (webSchema --> formObject from user)");
        }
    }
    webFlowService.databaseValuesToWebSchema(webSchema);

    stopWatch.stop();
    logger.info("[createFormObject] tok [" + stopWatch.getTotalTimeMillis() + "] ms");

    return webSchema;
}

From source file:no.abmu.abmstatistikk.annualstatistic.webflow.hibernate2.WebFlowServiceImpl.java

/**
 * Getting values from webSchema to an new databaseSchema, e.g. values from
 * user input to database schema./*www. ja va2 s  .  co  m*/
 * 
 * @param webFlowValidator - WebFlowValidator validator.
 * @param webSchemaDefinition - webSchema
 * @return - SchemaReport database schema. 
 */
public SchemaReport webSchemaValuesToDataBaseSchema(WebFlowValidator webFlowValidator,
        WebSchemaDefinition webSchema) {

    Assert.checkRequiredArgument("webFlowValidator", webFlowValidator);
    Assert.checkRequiredArgument("webSchema", webSchema);

    if (logger.isDebugEnabled()) {
        logger.debug("Executing webSchemaValuesToDataBaseSchema with parameters, WebFlowValidator='"
                + webFlowValidator + ", WebSchemaDefinition='" + webSchema + "'");
    }

    StopWatch stopWatch = new StopWatch();
    stopWatch.start("webSchemaValuesToDataBaseSchema");

    int notPassedValidation = 0;
    Object dataBaseSchema = getDatabaseSchema(webSchema);

    // Set up validation keys
    webFlowValidator.computeValidateFieldKeys();

    Set<String> validateFieldKeys = webFlowValidator.getValidateFieldKeys();
    if (logger.isDebugEnabled()) {
        for (String validateFieldKey : validateFieldKeys) {
            logger.debug("FieldKey to be validated='" + validateFieldKey + "'");
        }
    }

    for (String fieldNumberAsString : validateFieldKeys) {
        String methodGetFieldName = "getField" + fieldNumberAsString;
        String methodGetCommentName = "getComment" + fieldNumberAsString;

        String value = (String) MethodUtil.getValueOfPublicMethod(webSchema, methodGetFieldName);
        String comment = (String) MethodUtil.getValueOfPublicMethod(webSchema, methodGetCommentName);
        Answer answer = (Answer) MethodUtil.getValueOfPublicMethod(dataBaseSchema, methodGetFieldName);
        answer.setValue(value);
        answer.setComment(comment);
        answer.setPassedvalidation(notPassedValidation);

        if (logger.isDebugEnabled()) {
            Answer newAnswer = (Answer) MethodUtil.getValueOfPublicMethod(dataBaseSchema, methodGetFieldName);
            logger.debug("Field '" + fieldNumberAsString + "' method get name '" + methodGetFieldName
                    + "' web value '" + value + "' web comment '" + comment + "'");

            logger.debug("Field '" + fieldNumberAsString + "' validation '" + answer.getPassedvalidation()
                    + "' new db value '" + newAnswer.getValue() + "' new db comment '" + newAnswer.getComment()
                    + "'");
        }

    }

    SchemaReport schemaReport = (SchemaReport) dataBaseSchema;

    stopWatch.stop();
    logger.info("[private:webSchemaValuesToDataBaseSchema] tok [" + stopWatch.getTotalTimeMillis() + "] ms");

    return schemaReport;
}

From source file:no.abmu.abmstatistikk.annualstatistic.webflow.hibernate2.WebFlowServiceImpl.java

/**
 * Getting database schema and values from database.
 * // www . j  ava 2  s.c  o  m
 * @param webSchema - WebSchemaDefinition, schema which specify database
 * schema and version.
 * @return - Database schema with values fram database.
 */
private Object getDatabaseSchema(WebSchemaDefinition webSchema) {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing getDatabaseSchema");
    }
    Assert.checkRequiredArgument("webSchema", webSchema);

    StopWatch stopWatch = new StopWatch();
    stopWatch.start("getDatabaseSchema");

    Long id = webSchema.getId().longValue();
    String dataBaseSchemaName = webSchema.getDataBaseSchemaName();
    String dataBaseSchemaVersion = webSchema.getDataBaseSchemaVersion();
    Integer year = Integer.valueOf(dataBaseSchemaVersion);

    Assert.assertNotNull("OrganisationUnitId was null ", id);
    Assert.assertNotNull("DataBaseSchemaTypeName was null ", dataBaseSchemaName);
    Assert.assertNotNull("SchemaVersion was null ", dataBaseSchemaVersion);

    Report report = annualStatisticService.getReport(id, dataBaseSchemaName, year.intValue(), true);

    SchemaReport schemaReport;
    if (report == null) {
        logger.error("Couldn't find report for schema " + dataBaseSchemaName + " for Organisation " + id);
        throw new IllegalArgumentException(
                "Couldn't find report for schema " + dataBaseSchemaName + " for Organisation " + id);
    } else {
        schemaReport = new SchemaReport(report);
    }

    Object dataBaseSchema;
    if (dataBaseSchemaName.equals(SchemaTypeNameConst.FOLKEBIBLIOTEK_SHORT_NAME)) {
        dataBaseSchema = new FolkeBibScreen(schemaReport.getReport());
    } else {
        throw new SchemaTypeNameNotFoundException(dataBaseSchemaName);
    }
    stopWatch.stop();
    logger.info("[getDatabaseSchema] tok [" + stopWatch.getTotalTimeMillis() + "] ms");

    return dataBaseSchema;
}