Example usage for org.springframework.util StopWatch StopWatch

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

Introduction

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

Prototype

public StopWatch() 

Source Link

Document

Construct a new StopWatch .

Usage

From source file:ch.alv.sysinfos.config.apidoc.SwaggerConfiguration.java

/**
 * Swagger Spring MVC configuration.//from  w  w  w  . jav  a2  s.c  o  m
 */
@Bean
public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    SwaggerSpringMvcPlugin swaggerSpringMvcPlugin = new SwaggerSpringMvcPlugin(springSwaggerConfig)
            .apiInfo(apiInfo()).genericModelSubstitutes(ResponseEntity.class)
            .includePatterns(DEFAULT_INCLUDE_PATTERN);

    swaggerSpringMvcPlugin.build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return swaggerSpringMvcPlugin;
}

From source file:fr.univrouen.poste.services.GalaxieExcelParser.java

public void process(GalaxieExcel galaxieExcel) throws SQLException {

    StopWatch chrono = new StopWatch();
    chrono.start();//w ww .  ja va 2  s  . c  o m

    List<List<String>> cells = excelParser
            .getCells(galaxieExcel.getBigFile().getBinaryFile().getBinaryStream());

    Map<String, Long> cellsPosition = new HashMap<String, Long>();

    int p = 0;
    List<String> cellsHead = cells.remove(0);
    for (String cellName : cellsHead) {
        cellsPosition.put(cellName, new Long(p++));
    }
    galaxieMappingService.checkCellsHead(cellsPosition);

    Map<List<String>, GalaxieEntry> dbGalaxyEntries = new HashMap<List<String>, GalaxieEntry>();
    for (GalaxieEntry galaxieEntry : GalaxieEntry.findAllGalaxieEntrys()) {
        dbGalaxyEntries.put(getList4Id(galaxieEntry), galaxieEntry);
    }

    for (List<String> row : cells) {

        // create a new galaxyEntry
        GalaxieEntry galaxieEntry = new GalaxieEntry();
        for (String cellName : cellsPosition.keySet()) {
            int position = cellsPosition.get(cellName).intValue();
            if (row.size() > position) {
                String cellValue = row.get(position);
                galaxieMappingService.setAttrFromCell(galaxieEntry, cellName, cellValue);
            } else {
                logger.debug("can't get " + cellName + " for this row in excel file ...");
            }
        }

        // Rcupration d'un GalaxieEntry  chaque fois trop gourmand, mme avec l'index ...
        //TypedQuery<GalaxieEntry> query = GalaxieEntry.findGalaxieEntrysByNumEmploiAndNumCandidat(galaxieEntry.getNumEmploi(), galaxieEntry.getNumCandidat(), null, null);
        GalaxieEntry dbGalaxyEntrie = dbGalaxyEntries.get(getList4Id(galaxieEntry));

        if (dbGalaxyEntrie == null) {
            galaxieEntry.persist();
            dbGalaxyEntries.put(getList4Id(galaxieEntry), galaxieEntry);
        } else {
            // This GalaxyEntry exists already, we merge it if needed
            if (!fieldsEquals(dbGalaxyEntrie, galaxieEntry)) {
                dbGalaxyEntrie.setCivilite(galaxieEntry.getCivilite());
                dbGalaxyEntrie.setNom(galaxieEntry.getNom());
                dbGalaxyEntrie.setPrenom(galaxieEntry.getPrenom());
                if (dbGalaxyEntrie.getEmail().isEmpty()) {
                    if (!galaxieEntry.getEmail().isEmpty()) {
                        dbGalaxyEntrie.setEmail(galaxieEntry.getEmail());
                        logger.info("Le candidat " + dbGalaxyEntrie.getNumCandidat()
                                + " a maintenant renseign son email : " + galaxieEntry.getEmail());
                    }
                }
                // si email diffrent et si le candidat n'a pas activ son compte - on rinitialise le compte == on le supprime et on le rcr avec cette nvelle adresse mail
                else if (!dbGalaxyEntrie.getEmail().equals(galaxieEntry.getEmail())) {
                    try {
                        User user = User.findUsersByEmailAddress(dbGalaxyEntrie.getEmail()).getSingleResult();
                        if (user.getActivationDate() == null && !user.isCandidatActif()) {
                            logger.info("Le candidat " + dbGalaxyEntrie.getNumCandidat()
                                    + " a chang d'email alors qu'il n'avait pas encore activ son compte - on relance la procdure de cration de son compte/candidature.");

                            // cas o le candidat postule  plusieurs postes pris en compte ainsi
                            List<GalaxieEntry> userGalaxieEntries = GalaxieEntry
                                    .findGalaxieEntrysByCandidat(user).getResultList();
                            for (GalaxieEntry userGalaxieEntry : userGalaxieEntries) {
                                dbGalaxyEntries.remove(getList4Id(userGalaxieEntry));
                            }

                            user.remove();
                            galaxieEntry.persist();
                            dbGalaxyEntries.put(getList4Id(galaxieEntry), galaxieEntry);
                            continue;
                        }
                        dbGalaxyEntrie.setEmail(galaxieEntry.getEmail());
                    } catch (Exception e) {
                        logger.warn("Pb avec le candidat " + dbGalaxyEntrie.getNumCandidat()
                                + " qui a chang d'email ...", e);
                    }
                }
                dbGalaxyEntrie.setLocalisation(galaxieEntry.getLocalisation());
                dbGalaxyEntrie.setProfil(galaxieEntry.getProfil());
                dbGalaxyEntrie.setEtatDossier(galaxieEntry.getEtatDossier());
                dbGalaxyEntrie.merge();
            }
        }
    }

    chrono.stop();
    logger.info("Le traitement du fichier Excel Galaxie a t effectu en "
            + chrono.getTotalTimeMillis() / 1000.0 + " sec.");

}

From source file:be.craftworkz.ucll.config.apidoc.SwaggerConfiguration.java

/**
 * Swagger Springfox configuration./*from w w  w .  j  av a2 s. co  m*/
 */
@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
            .genericModelSubstitutes(ResponseEntity.class).forCodeGeneration(true)
            .genericModelSubstitutes(ResponseEntity.class)
            .directModelSubstitute(org.joda.time.LocalDate.class, String.class)
            .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class)
            .directModelSubstitute(org.joda.time.DateTime.class, Date.class)
            .directModelSubstitute(java.time.LocalDate.class, String.class)
            .directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
            .directModelSubstitute(java.time.LocalDateTime.class, Date.class).select()
            .paths(regex(DEFAULT_INCLUDE_PATTERN)).build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}

From source file:com.springboot.demo.config.apidoc.SwaggerConfiguration.java

/**
 * Swagger Springfox configuration./*from  ww w .j  a v  a 2  s. co m*/
 */
@Bean
public Docket swaggerSpringfoxDocket() {
    log.info("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
            .genericModelSubstitutes(ResponseEntity.class).forCodeGeneration(true)
            .genericModelSubstitutes(ResponseEntity.class)
            .directModelSubstitute(org.joda.time.LocalDate.class, String.class)
            .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class)
            .directModelSubstitute(org.joda.time.DateTime.class, Date.class)
            .directModelSubstitute(java.time.LocalDate.class, String.class)
            .directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
            .directModelSubstitute(java.time.LocalDateTime.class, Date.class).select()
            .paths(regex(DEFAULT_INCLUDE_PATTERN)).build();
    watch.stop();
    log.info("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}

From source file:cn.fintecher.print.service.summons.config.apidoc.SwaggerConfiguration.java

/**
 * Swagger Springfox configuration./*www  .  j  a  v a 2s.  co  m*/
 *
 * @param summonsServiceProperties the properties of the application
 * @return the Swagger Springfox configuration
 */
@Bean
public Docket swaggerSpringfoxDocket(SummonsServiceProperties summonsServiceProperties) {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Contact contact = new Contact(summonsServiceProperties.getSwagger().getContactName(),
            summonsServiceProperties.getSwagger().getContactUrl(),
            summonsServiceProperties.getSwagger().getContactEmail());

    ApiInfo apiInfo = new ApiInfo(summonsServiceProperties.getSwagger().getTitle(),
            summonsServiceProperties.getSwagger().getDescription(),
            summonsServiceProperties.getSwagger().getVersion(),
            summonsServiceProperties.getSwagger().getTermsOfServiceUrl(), contact,
            summonsServiceProperties.getSwagger().getLicense(),
            summonsServiceProperties.getSwagger().getLicenseUrl());

    Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).forCodeGeneration(true)
            .genericModelSubstitutes(ResponseEntity.class).select().paths(regex(DEFAULT_INCLUDE_PATTERN))
            .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}

From source file:org.zalando.zmon.actuator.ZmonMetricsFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws ServletException, IOException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();// ww  w  . ja v a2s  . c  om

    String path = new UrlPathHelper().getPathWithinApplication(request);
    int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
    try {
        chain.doFilter(request, response);
        status = getStatus(response);
    } finally {
        stopWatch.stop();
        metricsWrapper.recordClientRequestMetrics(request, path, status, stopWatch.getTotalTimeMillis());
    }
}

From source file:org.impalaframework.extension.mvc.flash.FlashStateEnabledAnnotationHandlerAdapter.java

public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    RequestModelHelper.maybeDebugRequest(logger, request);

    StopWatch watch = null;//from  w w  w  . j av a2  s.  c  o m

    final boolean debugEnabled;

    if (logger.isDebugEnabled()) {
        debugEnabled = true;
    } else {
        debugEnabled = false;
    }
    try {

        if (debugEnabled) {
            watch = new StopWatch();
            watch.start();
            logger.debug(MemoryUtils.getMemoryInfo().toString());
        }

        beforeHandle(request);

        ModelAndView modelAndView = super.handle(request, response, handler);

        if (modelAndView != null) {

            afterHandle(request, modelAndView);

            return modelAndView;

        }
    } finally {

        if (debugEnabled) {
            watch.stop();
            logger.debug("Request executed in " + watch.getTotalTimeMillis() + " milliseconds");
        }
    }

    return null;
}

From source file:com.alienlab.SwaggerConfiguration.java

@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();//from ww w.j a v  a 2 s  . c  o  m
    Contact contact = new Contact(contactName, contactUrl, contactEmail);

    ApiInfo apiInfo = new ApiInfo(title, description, version, termsOfServiceUrl, contact, license, licenseUrl);

    Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).forCodeGeneration(true)
            .genericModelSubstitutes(ResponseEntity.class).select().paths(regex(DEFAULT_INCLUDE_PATTERN))
            .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}

From source file:org.bpmscript.correlation.CorrelationSupportTest.java

public void testHashPerformance() throws Exception {
    CorrelationSupport correlationSupport = new CorrelationSupport();
    StopWatch md5Watch = new StopWatch();

    Object[] values = new Object[3];
    values[0] = 100000;/*from w ww  .  j  a  v  a 2 s  .co  m*/
    values[1] = "test ";
    values[2] = "randomblahblah";
    byte[] bytes = correlationSupport.getBytes(values);

    md5Watch.start();

    for (int i = 0; i < 100000; i++) {
        getHashMD5(bytes);
    }

    md5Watch.stop();

    System.out.println(md5Watch.getTotalTimeMillis());

    StopWatch hashCodeWatch = new StopWatch();

    hashCodeWatch.start();

    for (int i = 0; i < 100000; i++) {
        getHashHashCode(bytes);
    }

    hashCodeWatch.stop();

    System.out.println(hashCodeWatch.getTotalTimeMillis());
}

From source file:com.persistent.cloudninja.scheduler.TenantDBBandwidthGenerator.java

@Override
public boolean execute() {
    StopWatch watch = new StopWatch();
    boolean retVal = true;
    try {/*from  w w w. j a  va  2 s.  c o m*/
        watch.start();
        LOGGER.debug("In generator");
        TenantDBBandwidthQueue queue = (TenantDBBandwidthQueue) getWorkQueue();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String currentTime = dateFormat.format(calendar.getTime());
        queue.enqueue(currentTime);
        LOGGER.info("Generator : msg added is " + currentTime);
        watch.stop();
        taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                "GenerateMeterTenantDBBandwidthWork", "");
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}