Example usage for org.springframework.util StopWatch stop

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

Introduction

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

Prototype

public void stop() throws IllegalStateException 

Source Link

Document

Stop the current task.

Usage

From source file:ro.cs.ts.ws.client.om.OMWebServiceClient.java

public WSLogo getLogo(int organizationId)
        throws BusinessException, XmlMappingException, IOException, ro.cs.ts.exception.WSClientException {
    logger.debug("getLogo START");
    StopWatch sw = new StopWatch();
    sw.start("getLogo");

    WSLogo logo = null;/*from  www.  j  av a  2  s.  c o  m*/
    try {
        //create the bean  marshalled into the request
        GetLogoRequest getLogoRequest = new GetLogoRequest();
        getLogoRequest.setOrganisationId(organizationId);
        //unmarshall the response to an OrganisationSimple bean
        GetLogoResponse jaxbLogo = (GetLogoResponse) getWebServiceTemplate()
                .marshalSendAndReceive(getLogoRequest);
        logger.debug(
                "-------------------------------------------------------------------------------------------------");
        logger.debug(jaxbLogo);
        logger.debug(
                "-------------------------------------------------------------------------------------------------");
        logo = jaxbLogo.getLogo();
    } catch (SoapFaultClientException soapFault) {

        SoapFaultDetail soapFaultDetail = soapFault.getSoapFault().getFaultDetail();
        //if the soap fault detail field is empty, it means another type of exception than EndpointException has been thrown
        if (soapFaultDetail == null) {
            throw new WSClientException(soapFault.getFaultCode().toString(), soapFault.getFaultStringOrReason(),
                    soapFault);
            //soap fault detail field not empty means the Web Service has thrown an EndpointException
        } else {
            SoapFaultDetailElement soapFaultDetailElement = (SoapFaultDetailElement) soapFaultDetail
                    .getDetailEntries().next();
            //unmarshall the soap fault detail element to a WS specific bean named dmeEndpointExceptionBean
            JAXBElement<OMEndpointExceptionBean> omEndpointExceptionBean = (JAXBElement<OMEndpointExceptionBean>) getWebServiceTemplate()
                    .getUnmarshaller().unmarshal(soapFaultDetailElement.getSource());
            //throw a new WSClientException with the code and message of the DMEEndpointExceptionBean retrieved previously
            throw new WSClientException(omEndpointExceptionBean.getValue().getCode(),
                    omEndpointExceptionBean.getValue().getMessage(), soapFault);
        }
    }
    logger.debug("getLogo END");
    sw.stop();
    logger.debug(sw.prettyPrint());
    return logo;
}

From source file:ubic.gemma.core.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Get information on the conditions to be searched. This is not part of the query for the results themselves, but
 * uses the database to get metadata/summaries about the analyses that will be used. Initializes the searchResult
 * value object. Later, values which are non-missing will be replaced with either 'non-significant' or 'significant'
 * results./*from w w  w .  j ava 2 s.  c o m*/
 *
 * @param searchResult to be initialized
 * @return list of the resultSets that should be queried.
 */
private List<DiffExResultSetSummaryValueObject> addConditionsToSearchResultValueObject(
        DifferentialExpressionGenesConditionsValueObject searchResult) {

    StopWatch watch = new StopWatch("addConditionsToSearchResultValueObject");
    watch.start("Add conditions to search result value object");
    List<DiffExResultSetSummaryValueObject> usedResultSets = new LinkedList<>();

    int i = 0;

    DifferentialExpressionSearchTaskImpl.log.info("Loading " + experimentGroupName + " experiments...");

    // database hit: important that this be fast.
    Map<ExpressionExperimentDetailsValueObject, Collection<DifferentialExpressionAnalysisValueObject>> analyses = differentialExpressionAnalysisService
            .getAnalysesByExperiment(EntityUtils.getIds(experimentGroup));

    experiment: for (ExpressionExperimentDetailsValueObject bas : analyses.keySet()) {

        Collection<DifferentialExpressionAnalysisValueObject> analysesForExperiment = this
                .filterAnalyses(analyses.get(bas));

        if (analysesForExperiment.isEmpty()) {
            continue;
        }

        /*
         * There will often just be one analysis for the experiment. Exception would be when there is subsetting.
         */
        for (DifferentialExpressionAnalysisValueObject analysis : analysesForExperiment) {

            List<DiffExResultSetSummaryValueObject> resultSets = this.filterResultSets(analysis);
            usedResultSets.addAll(resultSets);

            if (resultSets.isEmpty()) {
                DifferentialExpressionSearchTaskImpl.log.info("No resultSets usable for " + bas.getId());
            }

            for (DiffExResultSetSummaryValueObject resultSet : resultSets) {

                // this is taken care of by the filterResultSets
                assert resultSet.getNumberOfDiffExpressedProbes() != null; // sanity check.
                assert resultSet.getExperimentalFactors().size() == 1; // interactions not okay

                ExperimentalFactorValueObject factor = resultSet.getExperimentalFactors().iterator().next();

                Collection<FactorValueValueObject> factorValues = this.filterFactorValues(analysis,
                        factor.getValues(), resultSet.getBaselineGroup().getId());

                if (factorValues.isEmpty()) {
                    /*
                     * This can only happen if there is just a baseline factorvalue. Even for one-sided tests //
                     * that // won't be the case.
                     */
                    DifferentialExpressionSearchTaskImpl.log
                            .warn("Nothing usable for resultSet=" + resultSet.getResultSetId());
                    continue;
                }

                for (FactorValueValueObject factorValue : factorValues) {

                    Condition condition = searchResult.new Condition(bas, analysis, resultSet, factorValue);

                    condition.setExperimentGroupName(experimentGroupName);

                    /*
                     * SANITY CHECKS these fields should be filled in. If not, we are going to skip the results.
                     */
                    if (condition.getNumberDiffExpressedProbes() == -1) {
                        DifferentialExpressionSearchTaskImpl.log
                                .warn(bas + ": Error: No hit list sizes for resultSet with ID="
                                        + resultSet.getResultSetId());
                        continue;
                    }
                    if (condition.getNumberOfProbesOnArray() == null
                            || condition.getNumberDiffExpressedProbes() == null) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas
                                + ": Error: Null counts for # diff ex probe or # probes on array, Skipping");
                        continue experiment;
                    } else if (condition.getNumberOfProbesOnArray() < condition
                            .getNumberDiffExpressedProbes()) {
                        DifferentialExpressionSearchTaskImpl.log.error(
                                bas + ": Error: More diff expressed probes than probes on array. Skipping.");
                        continue experiment;
                    }

                    searchResult.addCondition(condition);

                    i++;
                }
            }
        }

    }

    watch.stop();
    if (watch.getTotalTimeMillis() > 100) {
        // This does not include getting the actual diff ex results.
        DifferentialExpressionSearchTaskImpl.log.info("Get information on conditions/analyses for " + i
                + " factorValues: " + watch.getTotalTimeMillis() + "ms");
    }

    return usedResultSets;
}

From source file:ubic.gemma.core.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Main processing: fetch diff ex results.
 *
 * @param resultSets   to be searched//  w w w  .j  a v  a 2  s. c o  m
 * @param geneIds      to be searched
 * @param searchResult holds the results
 */
private void fetchDifferentialExpressionResults(List<DiffExResultSetSummaryValueObject> resultSets,
        List<Long> geneIds, DifferentialExpressionGenesConditionsValueObject searchResult) {

    StopWatch watch = new StopWatch("Process differential expression search");
    watch.start("Fetch diff ex results");

    // Main query for results; the main time sink.
    Map<Long, Map<Long, DiffExprGeneSearchResult>> resultSetToGeneResults = differentialExpressionResultService
            .findDiffExAnalysisResultIdsInResultSets(resultSets, geneIds);
    watch.stop();

    Collection<DiffExprGeneSearchResult> aggregatedResults = this
            .aggregateAcrossResultSets(resultSetToGeneResults);

    watch.start("Fetch details for contrasts for " + aggregatedResults.size() + " results");
    Map<Long, ContrastsValueObject> detailedResults = this.getDetailsForContrasts(aggregatedResults);

    this.processHits(searchResult, resultSetToGeneResults, resultSets, detailedResults);

    watch.stop();
    DifferentialExpressionSearchTaskImpl.log.info("Diff ex search finished:\n" + watch.prettyPrint());
}

From source file:ubic.gemma.core.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Retrieve the details (contrasts) for results which meet the criterion. (PVALUE_CONTRAST_SELECT_THRESHOLD).
 * Requires a database hit./*from  ww  w . j av  a 2 s. c om*/
 *
 * @param diffExResults results
 * @return map
 */
private Map<Long, ContrastsValueObject> getDetailsForContrasts(
        Collection<DiffExprGeneSearchResult> diffExResults) {

    StopWatch timer = new StopWatch();
    timer.start();
    List<Long> resultsWithContrasts = new ArrayList<>();

    for (DiffExprGeneSearchResult r : diffExResults) {
        if (r.getResultId() == null) {
            // it is a dummy result. It means there is no result for this gene in this resultset.
            continue;
        }

        /*
         * this check will not be needed if we only store the 'good' results, but we do store everything.
         */
        // Here I am trying to avoid fetching them when there is no hope that the results will be interesting.
        if (r instanceof MissingResult || r instanceof NonRetainedResult || r
                .getCorrectedPvalue() > DifferentialExpressionSearchTaskImpl.PVALUE_CONTRAST_SELECT_THRESHOLD) {
            // Then it won't have contrasts; no need to fetch.
            continue;
        }

        resultsWithContrasts.add(r.getResultId());
    }

    Map<Long, ContrastsValueObject> detailedResults = new HashMap<>();
    if (!resultsWithContrasts.isEmpty()) {
        // uses a left join so it will have all the results.
        detailedResults = differentialExpressionResultService
                .loadContrastDetailsForResults(resultsWithContrasts);
    }

    timer.stop();
    if (timer.getTotalTimeMillis() > 1) {
        DifferentialExpressionSearchTaskImpl.log.info("Fetch contrasts for " + resultsWithContrasts.size()
                + " results: " + timer.getTotalTimeMillis() + "ms");
    }
    return detailedResults;
}

From source file:ubic.gemma.persistence.util.monitor.MonitorAdvice.java

@Around("@annotation(ubic.gemma.persistence.util.monitor.Monitored)")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();/*from  www.  j  a  v  a 2 s  .  c o m*/
    Object retVal = pjp.proceed();

    stopWatch.stop();

    log.info(pjp.getSignature().toString() + " took " + stopWatch.getLastTaskTimeMillis() + "ms.");

    return retVal;

}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Get information on the conditions to be searched. This is not part of the query for the results themselves, but
 * uses the database to get metadata/summaries about the analyses that will be used. Initializes the searchResult
 * value object. Later, values which are non-missing will be replaced with either 'non-significant' or 'significant'
 * results./*from   www.  j a  v a  2 s  .  co m*/
 * 
 * @param searchResult to be initialized
 * @return lsit of the resultSets that should be queried.
 */
private List<ExpressionAnalysisResultSet> addConditionsToSearchResultValueObject(
        DifferentialExpressionGenesConditionsValueObject searchResult) {

    StopWatch watch = new StopWatch("addConditionsToSearchResultValueObject");
    watch.start("Add conditions to search result value object");
    List<ExpressionAnalysisResultSet> usedResultSets = new LinkedList<ExpressionAnalysisResultSet>();

    int experimentGroupIndex = 0;
    int i = 0;
    for (Collection<ExpressionExperiment> experimentGroup : experimentGroups) {

        log.info("Loading " + experimentGroupNames.get(experimentGroupIndex) + " experiments...");

        // database hit: important that this be fast.
        Map<BioAssaySet, Collection<DifferentialExpressionAnalysis>> analyses = differentialExpressionAnalysisService
                .getAnalyses(experimentGroup);

        experiment: for (BioAssaySet bas : analyses.keySet()) {

            if (!(bas instanceof ExpressionExperiment)) {
                log.warn("Subsets not supported yet (" + bas + "), skipping");
                continue;
            }

            ExpressionExperiment experiment = (ExpressionExperiment) bas;

            Collection<DifferentialExpressionAnalysis> analysesForExperiment = filterAnalyses(
                    analyses.get(experiment));

            if (analysesForExperiment.isEmpty()) {
                continue;
            }

            for (DifferentialExpressionAnalysis analysis : analysesForExperiment) {

                List<ExpressionAnalysisResultSet> resultSets = filterResultSets(analysis.getResultSets());
                usedResultSets.addAll(resultSets);

                if (resultSets.isEmpty()) {
                    log.info("No resultSets usable for " + experiment.getShortName());
                }

                for (ExpressionAnalysisResultSet resultSet : resultSets) {

                    // this is taken care of by the filterResultSets
                    assert resultSet.getHitListSizes() != null;
                    assert resultSet.getExperimentalFactors().size() == 1;

                    ExperimentalFactor factor = resultSet.getExperimentalFactors().iterator().next();
                    Collection<FactorValue> factorValues = filterFactorValues(factor.getFactorValues(),
                            resultSet.getBaselineGroup().getId());

                    for (FactorValue factorValue : factorValues) {

                        Condition condition = searchResult.new Condition(experiment, analysis, resultSet,
                                factorValue);

                        condition.setExperimentGroupName(experimentGroupNames.get(experimentGroupIndex));
                        condition.setExperimentGroupIndex(experimentGroupIndex);

                        /*
                         * SANITY CHECKS these fields should be filled in. If not, we are going to skip the results.
                         */
                        if (condition.getNumberDiffExpressedProbes() == -1) {
                            log.warn(bas + ": Error: No hit list sizes for resultSet with ID="
                                    + resultSet.getId());
                            continue;
                        }
                        if (condition.getNumberOfProbesOnArray() == null
                                || condition.getNumberDiffExpressedProbes() == null) {
                            log.error(bas
                                    + ": Error: Null counts for # diff ex probe or # probes on array, Skipping");
                            continue experiment;
                        } else if (condition.getNumberOfProbesOnArray() < condition
                                .getNumberDiffExpressedProbes()) {
                            log.error(bas
                                    + ": Error: More diff expressed probes than probes on array. Skipping.");
                            continue experiment;
                        }

                        searchResult.addCondition(condition);

                        i++;
                    }
                }
            }
        }
        experimentGroupIndex++;
    }

    watch.stop();
    if (watch.getTotalTimeMillis() > 100) {
        // This does not include getting the actual diff ex results.
        log.info("Get information on conditions/analyses for " + i + " factorValues: "
                + watch.getTotalTimeMillis() + "ms");
    }

    return usedResultSets;
}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * The actual business of fetching the differential expression results.
 * //from w  ww .  jav a  2  s .c  o m
 * @param resultSets
 * @param geneIds
 * @param searchResult holds the results
 */
private void fetchDifferentialExpressionResults(
        Map<ExpressionAnalysisResultSet, Collection<Long>> resultSetIdsToArrayDesignsUsed, List<Long> geneIds,
        DifferentialExpressionGenesConditionsValueObject searchResult) {

    StopWatch watch = new StopWatch("Process differential expression search");
    watch.start("Fetch diff ex results");

    // Main query for results; the main time sink.
    Map<Long, Map<Long, DiffExprGeneSearchResult>> resultSetToGeneResults = differentialExpressionResultService
            .findDifferentialExpressionAnalysisResultIdsInResultSet(resultSetIdsToArrayDesignsUsed, geneIds);
    watch.stop();

    Map<Long, ExpressionAnalysisResultSet> resultSetMap = EntityUtils
            .getIdMap(resultSetIdsToArrayDesignsUsed.keySet());
    Collection<DiffExprGeneSearchResult> aggregatedResults = aggregateAcrossResultSets(resultSetToGeneResults);

    watch.start("Fetch details for contrasts for " + aggregatedResults.size() + " results");
    Map<Long, ContrastsValueObject> detailedResults = getDetailsForContrasts(aggregatedResults);

    processHits(searchResult, resultSetToGeneResults, resultSetMap, detailedResults);

    watch.stop();
    log.info("Diff ex search finished:\n" + watch.prettyPrint());
}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Staging for getting the diff ex results.
 * /*  ww w .ja v a2  s  .  co  m*/
 * @param resultSets to be searched
 * @param geneIds to be searched
 * @param searchResult holds the results
 */
private void fetchDifferentialExpressionResults(List<ExpressionAnalysisResultSet> resultSets,
        List<Long> geneIds, DifferentialExpressionGenesConditionsValueObject searchResult) {

    Map<ExpressionAnalysisResultSet, Collection<Long>> resultSetIdsToArrayDesignsUsed = new HashMap<ExpressionAnalysisResultSet, Collection<Long>>();

    StopWatch timer = new StopWatch();
    timer.start();
    // DATABASE CALL HERE, but should be quite fast.
    for (ExpressionAnalysisResultSet rs : resultSets) {
        resultSetIdsToArrayDesignsUsed.put(rs,
                EntityUtils.getIds(eeService.getArrayDesignsUsed(rs.getAnalysis().getExperimentAnalyzed())));
    }
    timer.stop();
    if (timer.getTotalTimeMillis() > 100) {
        log.info("Fetch array designs used: " + timer.getTotalTimeMillis() + "ms");
    }

    fetchDifferentialExpressionResults(resultSetIdsToArrayDesignsUsed, geneIds, searchResult);

}

From source file:ubic.gemma.tasks.visualization.DifferentialExpressionSearchTaskImpl.java

/**
 * Retrieve the details (contrasts) for results which meet the criterion. (PVALUE_CONTRAST_SELECT_THRESHOLD)
 * /*from   w w  w .  j a v  a2  s .  c o  m*/
 * @param geneToProbeResult
 * @return
 */
private Map<Long, ContrastsValueObject> getDetailsForContrasts(
        Collection<DiffExprGeneSearchResult> diffExResults) {

    StopWatch timer = new StopWatch();
    timer.start();
    List<Long> resultsWithContrasts = new ArrayList<Long>();

    for (DiffExprGeneSearchResult r : diffExResults) {
        if (r.getResultId() == null) {
            // it is a dummy result. It means there is no result for this gene in this resultset.
            continue;
        }

        /*
         * this check will not be needed if we only store the 'good' results?
         */
        // Here I am trying to avoid fetching them when there is no hope that the results will be interesting.
        if (r instanceof MissingResult || r instanceof NonRetainedResult
                || r.getCorrectedPvalue() > PVALUE_CONTRAST_SELECT_THRESHOLD) {
            // Then it won't have contrasts; no need to fetch.
            continue;
        }

        resultsWithContrasts.add(r.getResultId());
    }

    Map<Long, ContrastsValueObject> detailedResults = new HashMap<Long, ContrastsValueObject>();
    if (!resultsWithContrasts.isEmpty()) {
        // uses a left join so it will have all the results.
        detailedResults = differentialExpressionResultService
                .loadContrastDetailsForResults(resultsWithContrasts);
    }

    timer.stop();
    if (timer.getTotalTimeMillis() > 1) {
        log.info("Fetch contrasts for " + resultsWithContrasts.size() + " results: "
                + timer.getTotalTimeMillis() + "ms");
    }
    return detailedResults;
}

From source file:uk.ac.ebi.atlas.experimentimport.analyticsindex.baseline.BaselineAnalyticsIndexerService.java

public int index(BaselineExperiment experiment) {
    String experimentAccession = experiment.getAccession();
    ExperimentType experimentType = experiment.getType();

    String defaultQueryFactorType = experiment.getExperimentalFactors().getDefaultQueryFactorType();
    ExperimentDesign experimentDesign = experiment.getExperimentDesign();

    ImmutableMap<String, String> ensemblSpeciesGroupedByAssayGroupId = SpeciesGrouper
            .buildEnsemblSpeciesGroupedByAssayGroupId(experiment);

    ImmutableSetMultimap<String, String> ontologyTermIdsByAssayAccession = expandOntologyTerms(
            experimentDesign.getAllOntologyTermIdsByAssayAccession());

    ImmutableSetMultimap<String, String> conditionSearchTermsByAssayGroupId = buildConditionSearchTermsByAssayGroupId(
            experiment, ontologyTermIdsByAssayAccession);

    checkArgument(StringUtils.isNotBlank(defaultQueryFactorType));

    LOGGER.info("Start indexing " + experimentAccession);
    StopWatch stopWatch = new StopWatch(getClass().getSimpleName());
    stopWatch.start();//from w w  w.j  a  v a 2 s .c  o m

    //TODO: move this to another class
    ObjectInputStream<BaselineAnalytics> inputStream = (experimentType == ExperimentType.PROTEOMICS_BASELINE)
            ? proteomicsBaselineAnalyticsInputStreamFactory.create(experimentAccession)
            : baselineAnalyticsInputStreamFactory.create(experimentAccession);

    int count = indexRnaSeqBaselineExperimentAnalytics(experimentAccession, experimentType,
            defaultQueryFactorType, conditionSearchTermsByAssayGroupId, ensemblSpeciesGroupedByAssayGroupId,
            inputStream);

    stopWatch.stop();
    LOGGER.info(String.format("Done indexing %s, indexed %,d documents in %s seconds", experimentAccession,
            count, stopWatch.getTotalTimeSeconds()));

    return count;
}