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() throws IllegalStateException 

Source Link

Document

Start an unnamed task.

Usage

From source file:no.abmu.organisationregister.util.OrganisationUnitImportExcelParser.java

public int organisationUnitDuplicationCount() {

    logger.info("Executing organisationUnitDuplicationCount");
    int duplicationCount = 0;

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    load();//from w  ww. j  a v a 2s.c  om
    for (; hasNext(); next()) {
        String organisationUnitName = getCellValueAsString("NAME BOKMAL");
        Set<OrganisationUnit> orgUnits = DataLoaderUtils.findOrganisationUnitByName(baseService,
                organisationUnitName);

        if (orgUnits.size() > 0) {
            String warningMessage = "On row " + +getCurrentRowIdx() + " " + orgUnits.size()
                    + " organisationUnits has the name: '" + organisationUnitName + "'.";
            logger.warn(warningMessage);
            duplicationCount++;
        }
    }

    if (duplicationCount > 0) {
        logger.error(duplicationCount + " dublication found to bad ... ");
    } else {
        logger.info("No duplication found, good.");
    }
    stopWatch.stop();
    logger.info("Testing for dublication tok " + stopWatch.getTotalTimeMillis() + " ms.");

    return duplicationCount;
}

From source file:no.abmu.questionnaire.service.QuestionnaireServiceHelperH3Impl.java

public ReportStatus[] getReportStatusBySchemaTypeNameAndVersion(
        List<OrganisationUnitForBrowsing> orgUnitsForBrowsing,
        SchemaTypeNameAndVersion schemaTypeNameAndVersion) {

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

    String codeFieldNumber = schemaTypeNameAndVersion.getCodeFinishField();

    String dbSchemaName = schemaTypeNameAndVersion.getDbSchemaName();
    String version = schemaTypeNameAndVersion.getVersion();

    List<ReportStatus> reportStatusAsList = new ArrayList<ReportStatus>();

    for (OrganisationUnitForBrowsing orgForBrowse : orgUnitsForBrowsing) {

        QuestionnaireData questionnaireData = getQuestionnaireData(orgForBrowse.getOrganisationUnitId(),
                dbSchemaName, version);/*from   w  ww.j  a v a 2s  .c  o  m*/

        reportStatusAsList.add(createReportStatus(orgForBrowse, questionnaireData, codeFieldNumber));
    }

    stopWatch.stop();

    logger.info("Finish prosessing of reportStatus for schemaTypeNameAndVersion:" + schemaTypeNameAndVersion
            + " with " + orgUnitsForBrowsing.size() + " elements in " + stopWatch.getTotalTimeMillis() + " ms");

    return reportStatusAsList.toArray(new ReportStatus[reportStatusAsList.size()]);

}

From source file:org.alfresco.repo.search.impl.solr.DbOrIndexSwitchingQueryLanguage.java

public ResultSet executeQuery(SearchParameters searchParameters, ADMLuceneSearcherImpl admLuceneSearcher) {
    QueryConsistency consistency = searchParameters.getQueryConsistency();
    if (consistency == QueryConsistency.DEFAULT) {
        consistency = queryConsistency;//ww w  . j a v a 2  s . c  o  m
    }

    switch (consistency) {
    case EVENTUAL:
        if (indexQueryLanguage != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
            }
            StopWatch stopWatch = new StopWatch("index only");
            stopWatch.start();
            ResultSet results = indexQueryLanguage.executeQuery(searchParameters, admLuceneSearcher);
            stopWatch.stop();
            if (logger.isDebugEnabled()) {
                logger.debug("SOLR returned " + results.length() + " results in "
                        + stopWatch.getLastTaskTimeMillis() + "ms");
            }
            return results;
        } else {
            throw new QueryModelException("No query language available");
        }
    case TRANSACTIONAL:
        if (dbQueryLanguage != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
            }
            StopWatch stopWatch = new StopWatch("database only");
            stopWatch.start();
            ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters),
                    admLuceneSearcher);
            stopWatch.stop();
            if (logger.isDebugEnabled()) {
                logger.debug("DB returned " + results.length() + " results in "
                        + stopWatch.getLastTaskTimeMillis() + "ms");
            }
            return results;
        } else {
            throw new QueryModelException("No query language available");
        }
    case HYBRID:
        if (!hybridEnabled) {
            throw new DisabledFeatureException("Hybrid query is disabled.");
        }
        return executeHybridQuery(searchParameters, admLuceneSearcher);
    case DEFAULT:
    case TRANSACTIONAL_IF_POSSIBLE:
    default:
        StopWatch stopWatch = new StopWatch("DB if possible");
        if (dbQueryLanguage != null) {
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
                }
                stopWatch.start();
                ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters),
                        admLuceneSearcher);
                stopWatch.stop();
                if (logger.isDebugEnabled()) {
                    logger.debug("DB returned " + results.length() + " results in "
                            + stopWatch.getLastTaskTimeMillis() + "ms");
                }
                return results;
            } catch (QueryModelException qme) {
                if (stopWatch.isRunning()) {
                    stopWatch.stop();
                }
                // MNT-10323: Logging configuration on JBoss leads to clogging of the log with a lot of these errors because of INFO level when WQS module is installed
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "DB query failed for " + dbQueryLanguage.getName() + " for " + searchParameters,
                            qme);
                }

                if (indexQueryLanguage != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
                    }
                    stopWatch.start();
                    ResultSet results = indexQueryLanguage.executeQuery(searchParameters, admLuceneSearcher);
                    stopWatch.stop();
                    if (logger.isDebugEnabled()) {
                        logger.debug("SOLR returned " + results.length() + " results in "
                                + stopWatch.getLastTaskTimeMillis() + "ms");
                    }
                    return results;
                }
            }
        } else {
            if (indexQueryLanguage != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("(No DB QL) Using SOLR query: " + "dbQueryLanguage==null" + " for "
                            + searchParameters);
                }
                stopWatch.start();
                ResultSet results = indexQueryLanguage.executeQuery(searchParameters, admLuceneSearcher);
                stopWatch.stop();
                if (logger.isDebugEnabled()) {
                    logger.debug("SOLR returned " + results.length() + " results in "
                            + stopWatch.getLastTaskTimeMillis() + "ms");
                }
                return results;
            }
        }
        throw new QueryModelException("No query language available");
    }

}

From source file:org.flockdata.integration.FileProcessor.java

private int processJsonEntities(String fileName, ExtractProfile extractProfile) throws FlockException {
    int rows = 0;

    File file = new File(fileName);
    InputStream stream = null;/*  w  ww .  java 2 s.  c  om*/
    if (!file.exists()) {
        stream = ClassLoader.class.getResourceAsStream(fileName);
        if (stream == null) {
            logger.error("{} does not exist", fileName);
            return 0;
        }
    }
    StopWatch watch = new StopWatch();

    JsonFactory jfactory = new JsonFactory();
    JsonParser jParser;
    List<EntityToEntityLinkInput> referenceInputBeans = new ArrayList<>();

    try {

        //String docType = mappable.getDataType();
        watch.start();
        ObjectMapper om = FdJsonObjectMapper.getObjectMapper();
        try {

            if (stream != null)
                jParser = jfactory.createParser(stream);
            else
                jParser = jfactory.createParser(file);

            JsonToken currentToken = jParser.nextToken();
            long then = new DateTime().getMillis();
            JsonNode node;
            if (currentToken == JsonToken.START_ARRAY || currentToken == JsonToken.START_OBJECT) {
                while (currentToken != null && currentToken != JsonToken.END_OBJECT) {

                    while (currentToken != null && jParser.nextToken() != JsonToken.END_ARRAY) {
                        node = om.readTree(jParser);
                        if (node != null) {
                            processJsonNode(node, extractProfile.getContentModel(), referenceInputBeans);
                            if (stopProcessing(rows++, then)) {
                                break;
                            }

                        }
                        currentToken = jParser.nextToken();

                    }
                }
            } else if (currentToken == JsonToken.START_OBJECT) {

                //om.readTree(jParser);
                node = om.readTree(jParser);
                processJsonNode(node, extractProfile.getContentModel(), referenceInputBeans);
            }

        } catch (IOException e1) {
            logger.error("Unexpected", e1);
        }

    } finally {
        getPayloadWriter().flush();
    }

    return endProcess(watch, rows, 0);
}

From source file:org.flockdata.integration.FileProcessor.java

private int processXMLFile(String file, ExtractProfile extractProfile) throws IOException, FlockException,
        IllegalAccessException, InstantiationException, ClassNotFoundException {
    try {//from w w w .  ja  v  a  2s. c  om
        int rows = 0;
        StopWatch watch = new StopWatch();
        StreamSource source = new StreamSource(file);
        XMLInputFactory xif = XMLInputFactory.newFactory();
        XMLStreamReader xsr = xif.createXMLStreamReader(source);

        XmlMappable mappable = (XmlMappable) Class.forName(extractProfile.getHandler()).newInstance();
        mappable.positionReader(xsr);

        String dataType = mappable.getDataType();
        watch.start();
        try {
            long then = new DateTime().getMillis();
            while (xsr.getLocalName().equals(dataType)) {
                EntityInputBean entityInputBean = Transformer.toEntity(mappable, xsr,
                        extractProfile.getContentModel());
                rows++;
                xsr.nextTag();
                getPayloadWriter().writeEntity(entityInputBean);

                if (stopProcessing(rows, then)) {
                    break;
                }

            }
        } finally {
            getPayloadWriter().flush();
        }
        return endProcess(watch, rows, 0);

    } catch (XMLStreamException | JAXBException e1) {
        throw new IOException(e1);
    }
}

From source file:org.flockdata.integration.FileProcessor.java

private int processCSVFile(String file, ExtractProfile extractProfile) throws IOException,
        IllegalAccessException, InstantiationException, FlockException, ClassNotFoundException {

    StopWatch watch = new StopWatch();
    int ignoreCount = 0;
    int currentRow = 0;

    BufferedReader br;/*from   ww w . j a  va 2 s  .co  m*/
    Reader fileObject = getReader(file);

    br = new BufferedReader(fileObject);

    try {
        CSVReader csvReader;
        if (extractProfile.getQuoteCharacter() != null)
            csvReader = new CSVReader(br, extractProfile.getDelimiter(),
                    extractProfile.getQuoteCharacter().charAt(0));
        else
            csvReader = new CSVReader(br, extractProfile.getDelimiter());

        String[] headerRow = null;
        String[] nextLine;
        if (extractProfile.hasHeader()) {
            while ((nextLine = csvReader.readNext()) != null) {
                if (isHeaderRow(nextLine)) {
                    headerRow = nextLine;
                    break;
                }
            }
        }
        watch.start();

        if (skipCount > 0)
            logger.info("Skipping first {} rows", skipCount);

        long then = System.currentTimeMillis();

        while ((nextLine = csvReader.readNext()) != null) {
            if (!ignoreRow(nextLine)) {
                if (headerRow == null) {
                    headerRow = TransformationHelper.defaultHeader(nextLine, extractProfile.getContentModel());
                }
                currentRow++;
                if (currentRow >= skipCount) {
                    if (currentRow == skipCount)
                        logger.info("Processing now begins at row {}", skipCount);

                    nextLine = preProcess(nextLine, extractProfile);

                    Map<String, Object> map = Transformer.convertToMap(headerRow, nextLine, extractProfile);

                    if (map != null) {
                        if (extractProfile.getContentModel().isTagModel()) {
                            Collection<TagInputBean> tagInputBean = Transformer.toTags(map,
                                    extractProfile.getContentModel());
                            if (tagInputBean != null) {
                                getPayloadWriter().writeTags(tagInputBean, "TagInputBean");
                            }
                        } else {
                            EntityInputBean entityInputBean = Transformer.toEntity(map,
                                    extractProfile.getContentModel());
                            // Dispatch/load mechanism
                            if (entityInputBean != null)
                                getPayloadWriter().writeEntity(entityInputBean);
                        }
                        if (stopProcessing(currentRow, then)) {
                            break;
                        }
                    }
                }
            } else {
                ignoreCount++;
            }
        }
    } finally {

        getPayloadWriter().flush();
        br.close();
    }

    return endProcess(watch, currentRow, ignoreCount);
}

From source file:org.hyperic.hq.monitor.aop.aspects.PerformanceMonitor.java

/**
 * We could bind the @Transactional annotation to the context but there's no
 * way to know if the method or the type is annotated, causing a false
 * negative.//from   w w  w  .j  a  va 2s . co m
 * @see org.hyperic.hq.monitor.aop.MonitorArchitecture
 * @param pjp
 */
@Around("org.hyperic.hq.monitor.aop.MonitorArchitecture.serviceLayerOperationDuration()")
public Object monitorServiceMethod(ProceedingJoinPoint pjp) throws Throwable {

    Object invocation = null;

    final StopWatch timer = new StopWatch(pjp.getSignature() + Thread.currentThread().getName());

    try {
        timer.start();
        invocation = pjp.proceed();
    } finally {
        timer.stop();
    }

    long duration = timer.getTotalTimeMillis();

    if (duration > maximumDuration) {
        logger.warn(new StringBuilder(warningMessage).append(pjp.getSignature()).append(" executed in ")
                .append(timer.getTotalTimeMillis()).append(":ms").toString());
    }

    return invocation;
}

From source file:org.kuali.kfs.gl.batch.PreScrubberStep.java

@Override
protected CustomBatchExecutor getCustomBatchExecutor() {
    return new CustomBatchExecutor() {
        public boolean execute() {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            String inputFile = batchFileDirectoryName + File.separator
                    + GeneralLedgerConstants.BatchFileSystem.BACKUP_FILE
                    + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
            String outputFile = batchFileDirectoryName + File.separator
                    + GeneralLedgerConstants.BatchFileSystem.PRE_SCRUBBER_FILE
                    + GeneralLedgerConstants.BatchFileSystem.EXTENSION;

            PreScrubberReportData preScrubberReportData = null;
            LineIterator oeIterator = null;
            try {
                oeIterator = FileUtils.lineIterator(new File(inputFile));
                preScrubberReportData = preScrubberService.preprocessOriginEntries(oeIterator, outputFile);
            } catch (IOException e) {
                LOG.error("IO exception occurred during pre scrubbing.", e);
                throw new RuntimeException("IO exception occurred during pre scrubbing.", e);
            } finally {
                LineIterator.closeQuietly(oeIterator);
            }//w ww .  jav  a  2  s  . c o  m

            if (preScrubberReportData != null) {
                new PreScrubberReport().generateReport(preScrubberReportData, preScrubberReportWriterService);
            }

            stopWatch.stop();
            if (LOG.isDebugEnabled()) {
                LOG.debug("scrubber step of took " + (stopWatch.getTotalTimeSeconds() / 60.0)
                        + " minutes to complete");
            }
            return true;
        }
    };
}

From source file:org.kuali.kfs.module.ld.batch.LaborPreScrubberStep.java

/**
 * @see org.kuali.kfs.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor()
 *///w  w w .  j  ava 2 s . c o  m
@Override
protected CustomBatchExecutor getCustomBatchExecutor() {
    return new CustomBatchExecutor() {

        /**
         * @see org.kuali.kfs.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor#execute()
         */
        public boolean execute() {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            String inputFile = batchFileDirectoryName + File.separator
                    + LaborConstants.BatchFileSystem.BACKUP_FILE
                    + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
            String outputFile = batchFileDirectoryName + File.separator
                    + LaborConstants.BatchFileSystem.PRE_SCRUBBER_FILE
                    + GeneralLedgerConstants.BatchFileSystem.EXTENSION;

            PreScrubberReportData preScrubberReportData = null;
            LineIterator oeIterator = null;
            try {
                oeIterator = FileUtils.lineIterator(new File(inputFile));
                preScrubberReportData = laborPreScrubberService.preprocessOriginEntries(oeIterator, outputFile);
            } catch (IOException e) {
                LOG.error("IO exception occurred during pre scrubbing.", e);
                throw new RuntimeException("IO exception occurred during pre scrubbing.", e);
            } finally {
                LineIterator.closeQuietly(oeIterator);
            }
            if (preScrubberReportData != null) {
                ((WrappingBatchService) laborPreScrubberReportWriterService).initialize();
                new PreScrubberReport().generateReport(preScrubberReportData,
                        laborPreScrubberReportWriterService);
                ((WrappingBatchService) laborPreScrubberReportWriterService).destroy();
            }

            stopWatch.stop();
            if (LOG.isDebugEnabled()) {
                LOG.debug("labor pre-scrubber scrubber step took " + (stopWatch.getTotalTimeSeconds() / 60.0)
                        + " minutes to complete");
            }
            return true;
        }

    };
}

From source file:org.ownchan.server.joint.scheduler.service.SchedulerService.java

public <T> void waitForCronjobFutures(List<Future<T>> futures, String jobName, Logger jobLogger) {
    jobLogger.debug(jobName + " started...");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    long countProcessed = 0;
    long countFailed = 0;
    for (Future<T> future : futures) {
        try {/*  w w w.  java 2s  .  co  m*/
            // result might be of type Void, so in fact we might not get a result at all ...
            T result = future.get();
            if (result instanceof Boolean && !(Boolean) result) {
                ++countFailed;
            }
        } catch (Exception e) {
            Throwable t = unwrapExecutionExceptionIfPossible(e);
            jobLogger.error(t.getMessage(), t);
            ++countFailed;
        }

        ++countProcessed;
    }

    stopWatch.stop();

    jobLogger.info(MESSAGE_TEMPLATE_PROCESSED, jobName, countProcessed, countFailed,
            DurationFormatUtils.formatDurationHMS(stopWatch.getTotalTimeMillis()));
}