Example usage for org.apache.commons.lang.time StopWatch start

List of usage examples for org.apache.commons.lang.time StopWatch start

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch start.

Prototype

public void start() 

Source Link

Document

Start the stopwatch.

This method starts a new timing session, clearing any previous values.

Usage

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public List<TopicDocument> getTopicDocuments(final Long documentId) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final Long userId = CurrentUserUtil.getCurrentUserId();

    final Query query = this.em.createQuery("select td " + "from TopicDocument td join td.topic topic "
            + "where td.document.id = :documentId and topic.userId = :userId " + "order by td.score desc");
    query.setParameter("userId", userId);
    query.setParameter("documentId", documentId);
    @SuppressWarnings("unchecked")
    final List<TopicDocument> filteredTopicDocuments = (List<TopicDocument>) query.getResultList();

    stopWatch.stop();/*w  w w. j  a va 2 s.c  o  m*/
    logger.debug(stopWatch.toString());
    return filteredTopicDocuments;
}

From source file:biz.netcentric.cq.tools.actool.aceservice.impl.AceServiceImpl.java

private void installAuthorizables(AcInstallationHistoryPojo history,
        Set<AuthorizableInstallationHistory> authorizableHistorySet,
        Map<String, Set<AuthorizableConfigBean>> authorizablesMapfromConfig)
        throws RepositoryException, Exception {
    // --- installation of Authorizables from configuration ---

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

    String msg = "*** Starting installation of " + authorizablesMapfromConfig.size() + " authorizables...";
    LOG.info(msg);/*ww  w. j av a 2  s.c om*/
    history.addMessage(msg);

    // create own session for installation of authorizables since these have
    // to be persisted in order
    // to have the principals available when installing the ACEs

    // therefore the installation of all ACEs from all configurations uses
    // an own session (which get passed as
    // parameter to this method), which only get saved when no exception was
    // thrown during the installation of the ACEs

    // in case of an exception during the installation of the ACEs the
    // performed installation of authorizables from config
    // has to be reverted using the rollback method
    Session authorizableInstallationSession = repository.loginAdministrative(null);
    try {
        // only save session if no exceptions occured
        AuthorizableInstallationHistory authorizableInstallationHistory = new AuthorizableInstallationHistory();
        authorizableHistorySet.add(authorizableInstallationHistory);
        authorizableCreatorService.createNewAuthorizables(authorizablesMapfromConfig,
                authorizableInstallationSession, history, authorizableInstallationHistory);
        authorizableInstallationSession.save();
    } catch (Exception e) {
        throw new AuthorizableCreatorException(e);
    } finally {
        if (authorizableInstallationSession != null) {
            authorizableInstallationSession.logout();
        }
    }

    String message = "Finished installation of authorizables without errors in "
            + AcInstallationHistoryPojo.msHumanReadable(stopWatch.getTime());
    history.addMessage(message);
    LOG.info(message);
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public DataRange<Document> listDocumentsByOwner(final Long userId, final int first, final int count) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final SortOrder sortOrder = SortOrder.DATE_DESC;
    final DataRange<DocumentScore> scoredRange = this.searchWithAllOptions(userId, false, null, null, sortOrder,
            null /* ignore start date */, null /* ignore end date */, first, count);

    final List<Document> range = new ArrayList<Document>(scoredRange.getRange().size());

    for (final DocumentScore scoredDoc : scoredRange.getRange()) {
        range.add(scoredDoc.getDocument());
    }//w  w  w . j a va2s .c  om

    final DataRange<Document> dataRange = new DataRange<Document>(range, scoredRange.getFirstRow(),
            scoredRange.getTotalRowsAvailable());

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return dataRange;
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public DataRange<Document> listDocumentsInTopicsByOwner(final Long userId, final int first, final int count) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final SortOrder sortOrder = SortOrder.DATE_DESC;
    final DataRange<DocumentScore> scoredRange = this.searchWithAllOptions(userId, true,
            DocumentState.MATCHED_TO_TOPICS, null, sortOrder, null, null, first, count);

    final List<Document> range = new ArrayList<Document>(scoredRange.getRange().size());

    for (final DocumentScore scoredDoc : scoredRange.getRange()) {
        range.add(scoredDoc.getDocument());
    }//from w w  w .  ja  va2  s .  co  m

    final DataRange<Document> dataRange = new DataRange<Document>(range, scoredRange.getFirstRow(),
            scoredRange.getTotalRowsAvailable());

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return dataRange;
}

From source file:biz.netcentric.cq.tools.actool.aceservice.impl.AceServiceImpl.java

/** Common entry point for JMX and install hook. */
@Override/*from   ww w  . ja v a2  s .  com*/
public void installConfigurationFiles(AcInstallationHistoryPojo history,
        Map<String, String> configurationFileContentsByFilename,
        Set<AuthorizableInstallationHistory> authorizableInstallationHistorySet, String[] restrictedToPaths)
        throws Exception {

    String origThreadName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName(origThreadName + "-ACTool-Config-Worker");
        StopWatch sw = new StopWatch();
        sw.start();
        isExecuting = true;
        String message = "*** Applying AC Tool Configuration...";
        LOG.info(message);
        history.addMessage(message);

        if (configurationFileContentsByFilename != null) {

            history.setConfigFileContentsByName(configurationFileContentsByFilename);

            AcConfiguration acConfiguration = configurationMerger
                    .getMergedConfigurations(configurationFileContentsByFilename, history, configReader);
            history.setAcConfiguration(acConfiguration);

            installMergedConfigurations(history, authorizableInstallationHistorySet, acConfiguration,
                    restrictedToPaths);

            // this runs as "own transaction" after session.save() of ACLs
            removeObsoleteAuthorizables(history, acConfiguration.getObsoleteAuthorizables());

        }
        sw.stop();
        long executionTime = sw.getTime();
        LOG.info("Successfully applied AC Tool configuration in " + msHumanReadable(executionTime));
        history.setExecutionTime(executionTime);
    } catch (Exception e) {
        history.addError(e.toString()); // ensure exception is added to history before it's persisted in log in finally clause
        throw e; // handling is different depending on JMX or install hook case
    } finally {
        try {
            acHistoryService.persistHistory(history);
        } catch (Exception e) {
            LOG.warn("Could not persist history, e=" + e, e);
        }

        Thread.currentThread().setName(origThreadName);
        isExecuting = false;
    }

}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public List<Document> listTopDocuments(Long userId, Date startDate, Date endDate, int count) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final Query query = this.em
            .createQuery("select d from Topic topic join topic.topicDocuments td join td.document d "
                    + "   where topic.userId = :userId "
                    + "     and td.creationDate > :startDate and td.creationDate < :endDate "
                    + "     and td.score > 0.2                                            "
                    + "     order by td.score desc");
    query.setParameter("userId", userId);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    query.setFirstResult(0);//from w  ww . j av  a  2s  .co  m
    query.setMaxResults(count);

    query.setLockMode(LockModeType.NONE);

    @SuppressWarnings("unchecked")
    final List<Document> range = query.getResultList();

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return range;
}

From source file:eagle.service.generic.ListQueryResource.java

/**
 * <b>TODO</b> remove the legacy deprecated implementation of listQueryWithoutCoprocessor
 *
 * @see #listQuery(String, String, String, int, String, boolean, boolean, long, int, boolean, int, String,Boolean)
 *
 * @param query/*w w w . ja v  a  2  s.c  o m*/
 * @param startTime
 * @param endTime
 * @param pageSize
 * @param startRowkey
 * @param treeAgg
 * @param timeSeries
 * @param intervalmin
 * @return
 */
@GET
@Path("/legacy")
@Produces({ MediaType.APPLICATION_JSON })
@Deprecated
public ListQueryAPIResponseEntity listQueryWithoutCoprocessor(@QueryParam("query") String query,
        @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
        @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey,
        @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries,
        @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
        @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel,
        @QueryParam("metricName") String metricName, @QueryParam("verbose") Boolean verbose) {
    StopWatch watch = new StopWatch();
    watch.start();
    ListQueryAPIResponseEntity result = new ListQueryAPIResponseEntity();
    try {
        validateQueryParameters(startRowkey, pageSize);
        ListQueryCompiler comp = new ListQueryCompiler(query, filterIfMissing);
        String serviceName = comp.serviceName();

        SearchCondition condition = new SearchCondition();
        condition.setFilter(comp.filter());
        condition.setQueryExpression(comp.getQueryExpression());
        if (comp.sortOptions() == null && top > 0) {
            LOG.warn(
                    "Parameter \"top\" is only used for sort query! Ignore top parameter this time since it's not a sort query");
        }

        // TODO: For now we don't support one query to query multiple partitions. In future
        // if partition is defined for the entity, internally We need to spawn multiple
        // queries and send one query for each search condition for each partition
        final List<String[]> partitionValues = comp.getQueryPartitionValues();
        if (partitionValues != null) {
            condition.setPartitionValues(Arrays.asList(partitionValues.get(0)));
        }
        EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName(serviceName);
        if (ed.isTimeSeries()) {
            // TODO check timestamp exists for timeseries or topology data
            condition.setStartTime(startTime);
            condition.setEndTime(endTime);
        }
        condition.setOutputVerbose(verbose == null || verbose);
        condition.setOutputAlias(comp.getOutputAlias());
        condition.setOutputAll(comp.isOutputAll());
        condition.setStartRowkey(startRowkey);
        condition.setPageSize(pageSize);

        List<String> outputFields = comp.outputFields();
        if (outputFields == null)
            outputFields = new ArrayList<String>();

        /**
         * TODO ugly logic, waiting for refactoring
         */
        if (!comp.hasAgg() && !serviceName.equals(GenericMetricEntity.GENERIC_METRIC_SERVICE)) { // pure list query
            //            List<String> outputFields = comp.outputFields();
            Set<String> filterFields = comp.getFilterFields();
            if (filterFields != null)
                outputFields.addAll(filterFields);
            condition.setOutputFields(outputFields);
            if (condition.isOutputAll()) {
                LOG.info("Output: ALL");
            } else {
                LOG.info("Output: " + StringUtils.join(condition.getOutputFields(), ", "));
            }
            GenericEntityBatchReader reader = new GenericEntityBatchReader(serviceName, condition);
            List<? extends TaggedLogAPIEntity> entityList = reader.read();
            result.setObj(entityList);
            result.setTotalResults(entityList.size());
            result.setSuccess(true);
            result.setLastTimestamp(reader.getLastTimestamp());
            result.setFirstTimestamp(reader.getFirstTimestamp());
        } else if (!comp.hasAgg() && serviceName.equals(GenericMetricEntity.GENERIC_METRIC_SERVICE)) {
            // validate metric name
            if (metricName == null || metricName.isEmpty()) {
                throw new IllegalArgumentException("metricName should not be empty for metric list query");
            }
            //            List<String> outputFields = comp.outputFields();
            Set<String> filterFields = comp.getFilterFields();
            if (filterFields != null)
                outputFields.addAll(filterFields);
            condition.setOutputFields(outputFields);
            if (condition.isOutputAll()) {
                LOG.info("Output: ALL");
            } else {
                LOG.info("Output: " + StringUtils.join(condition.getOutputFields(), ", "));
            }
            GenericMetricEntityBatchReader reader = new GenericMetricEntityBatchReader(metricName, condition);
            List<? extends TaggedLogAPIEntity> entityList = reader.read();
            result.setObj(entityList);
            result.setTotalResults(entityList.size());
            result.setSuccess(true);
            result.setLastTimestamp(reader.getLastTimestamp());
            result.setFirstTimestamp(reader.getFirstTimestamp());
        } else if (!treeAgg && !timeSeries && parallel <= 0) { // non time-series based aggregate query, not hierarchical
            List<String> groupbyFields = comp.groupbyFields();
            List<String> aggregateFields = comp.aggregateFields();
            Set<String> filterFields = comp.getFilterFields();
            //            List<String> outputFields = new ArrayList<String>();
            if (groupbyFields != null)
                outputFields.addAll(groupbyFields);
            if (filterFields != null)
                outputFields.addAll(filterFields);
            outputFields.addAll(aggregateFields);

            if (GenericMetricEntity.GENERIC_METRIC_SERVICE.equals(serviceName)
                    && !outputFields.contains(GenericMetricEntity.VALUE_FIELD)) {
                outputFields.add(GenericMetricEntity.VALUE_FIELD);
            }

            FlatAggregator agg = new FlatAggregator(groupbyFields, comp.aggregateFunctionTypes(),
                    comp.aggregateFields());
            StreamReader reader = null;
            if (ed.getMetricDefinition() == null) {
                reader = new GenericEntityStreamReader(serviceName, condition);
            } else { // metric aggregation need metric reader
                reader = new GenericMetricEntityDecompactionStreamReader(metricName, condition);
            }
            condition.setOutputFields(outputFields);
            if (condition.isOutputAll()) {
                LOG.info("Output: ALL");
            } else {
                LOG.info("Output: " + StringUtils.join(condition.getOutputFields(), ", "));
            }
            reader.register(agg);
            reader.readAsStream();
            ArrayList<Map.Entry<List<String>, List<Double>>> obj = new ArrayList<Map.Entry<List<String>, List<Double>>>();
            obj.addAll(agg.result().entrySet());
            if (comp.sortOptions() == null) {
                result.setObj(obj);
            } else { // has sort options
                result.setObj(PostFlatAggregateSort.sort(agg.result(), comp.sortOptions(), top));
            }
            result.setTotalResults(0);
            result.setSuccess(true);
            result.setLastTimestamp(reader.getLastTimestamp());
            result.setFirstTimestamp(reader.getFirstTimestamp());
        } else if (!treeAgg && !timeSeries && parallel > 0) { // TODO ugly branch, let us refactor
            List<String> groupbyFields = comp.groupbyFields();
            List<String> aggregateFields = comp.aggregateFields();
            Set<String> filterFields = comp.getFilterFields();
            //            List<String> outputFields = new ArrayList<String>();
            if (groupbyFields != null)
                outputFields.addAll(groupbyFields);
            if (filterFields != null)
                outputFields.addAll(filterFields);
            outputFields.addAll(aggregateFields);
            if (GenericMetricEntity.GENERIC_METRIC_SERVICE.equals(serviceName)
                    && !outputFields.contains(GenericMetricEntity.VALUE_FIELD)) {
                outputFields.add(GenericMetricEntity.VALUE_FIELD);
            }
            condition.setOutputFields(outputFields);
            if (condition.isOutputAll()) {
                LOG.info("Output: ALL");
            } else {
                LOG.info("Output: " + StringUtils.join(condition.getOutputFields(), ", "));
            }
            FlatAggregator agg = new FlatAggregator(groupbyFields, comp.aggregateFunctionTypes(),
                    comp.aggregateFields());
            EntityCreationListener listener = EntityCreationListenerFactory
                    .synchronizedEntityCreationListener(agg);
            StreamReader reader = new GenericEntityStreamReaderMT(serviceName, condition, parallel);
            reader.register(listener);
            reader.readAsStream();
            ArrayList<Map.Entry<List<String>, List<Double>>> obj = new ArrayList<Map.Entry<List<String>, List<Double>>>();
            obj.addAll(agg.result().entrySet());
            if (comp.sortOptions() == null) {
                result.setObj(obj);
            } else { // has sort options
                result.setObj(PostFlatAggregateSort.sort(agg.result(), comp.sortOptions(), top));
            }
            result.setTotalResults(0);
            result.setSuccess(true);
            result.setLastTimestamp(reader.getLastTimestamp());
            result.setFirstTimestamp(reader.getFirstTimestamp());
        } else if (!treeAgg && timeSeries) { // time-series based aggregate query, not hierarchical
            List<String> groupbyFields = comp.groupbyFields();
            List<String> sortFields = comp.sortFields();
            List<String> aggregateFields = comp.aggregateFields();
            Set<String> filterFields = comp.getFilterFields();
            //            List<String> outputFields = new ArrayList<String>();
            if (groupbyFields != null)
                outputFields.addAll(groupbyFields);
            if (filterFields != null)
                outputFields.addAll(filterFields);
            if (sortFields != null)
                outputFields.addAll(sortFields);
            outputFields.addAll(aggregateFields);
            if (GenericMetricEntity.GENERIC_METRIC_SERVICE.equals(serviceName)
                    && !outputFields.contains(GenericMetricEntity.VALUE_FIELD)) {
                outputFields.add(GenericMetricEntity.VALUE_FIELD);
            }
            StreamReader reader = null;
            if (ed.getMetricDefinition() == null) {
                if (parallel <= 0) { // TODO ugly quick win
                    reader = new GenericEntityStreamReader(serviceName, condition);
                } else {
                    reader = new GenericEntityStreamReaderMT(serviceName, condition, parallel);
                }
            } else { // metric aggregation need metric reader
                reader = new GenericMetricEntityDecompactionStreamReader(metricName, condition);
                if (!outputFields.contains(GenericMetricEntity.VALUE_FIELD)) {
                    outputFields.add(GenericMetricEntity.VALUE_FIELD);
                }
            }
            condition.setOutputFields(outputFields);
            if (condition.isOutputAll()) {
                LOG.info("Output: ALL");
            } else {
                LOG.info("Output: " + StringUtils.join(condition.getOutputFields(), ", "));
            }
            TimeSeriesAggregator tsAgg = new TimeSeriesAggregator(groupbyFields, comp.aggregateFunctionTypes(),
                    aggregateFields, DateTimeUtil.humanDateToDate(condition.getStartTime()).getTime(),
                    DateTimeUtil.humanDateToDate(condition.getEndTime()).getTime(), intervalmin * 60 * 1000);
            if (parallel <= 0) {
                reader.register(tsAgg);
            } else {
                EntityCreationListener listener = EntityCreationListenerFactory
                        .synchronizedEntityCreationListener(tsAgg);
                reader.register(listener);
            }
            // for sorting
            FlatAggregator sortAgg = null;
            if (comp.sortOptions() != null) {
                sortAgg = new FlatAggregator(groupbyFields, comp.sortFunctions(), comp.sortFields());
                if (parallel <= 0) {
                    reader.register(sortAgg);
                } else {
                    EntityCreationListener listener = EntityCreationListenerFactory
                            .synchronizedEntityCreationListener(sortAgg);
                    reader.register(listener);
                }
            }
            reader.readAsStream();
            ArrayList<Map.Entry<List<String>, List<double[]>>> obj = new ArrayList<Map.Entry<List<String>, List<double[]>>>();
            obj.addAll(tsAgg.getMetric().entrySet());
            if (comp.sortOptions() == null) {
                result.setObj(obj);
            } else { // has sort options
                result.setObj(TimeSeriesPostFlatAggregateSort.sort(sortAgg.result(), tsAgg.getMetric(),
                        comp.sortOptions(), top));
            }
            result.setTotalResults(0);
            result.setSuccess(true);
            result.setLastTimestamp(reader.getLastTimestamp());
            result.setFirstTimestamp(reader.getFirstTimestamp());
        } else { // use hierarchical aggregate mode
            List<String> groupbyFields = comp.groupbyFields();
            List<String> aggregateFields = comp.aggregateFields();
            Set<String> filterFields = comp.getFilterFields();
            //            List<String> outputFields = new ArrayList<String>();
            if (groupbyFields != null)
                outputFields.addAll(groupbyFields);
            if (filterFields != null)
                outputFields.addAll(filterFields);
            outputFields.addAll(aggregateFields);
            if (GenericMetricEntity.GENERIC_METRIC_SERVICE.equals(serviceName)
                    && !outputFields.contains(GenericMetricEntity.VALUE_FIELD)) {
                outputFields.add(GenericMetricEntity.VALUE_FIELD);
            }
            condition.setOutputFields(outputFields);
            if (condition.isOutputAll()) {
                LOG.info("Output: ALL");
            } else {
                LOG.info("Output: " + StringUtils.join(condition.getOutputFields(), ", "));
            }
            GenericEntityStreamReader reader = new GenericEntityStreamReader(serviceName, condition);
            HierarchicalAggregator agg = new HierarchicalAggregator(groupbyFields,
                    comp.aggregateFunctionTypes(), comp.aggregateFields());
            reader.register(agg);
            reader.readAsStream();
            if (comp.sortOptions() == null) {
                result.setObj(agg.result());
            } else { // has sort options
                result.setObj(PostHierarchicalAggregateSort.sort(agg.result(), comp.sortOptions()));
            }
            result.setTotalResults(0);
            result.setSuccess(true);
            result.setLastTimestamp(reader.getLastTimestamp());
            result.setFirstTimestamp(reader.getFirstTimestamp());
        }
    } catch (Exception ex) {
        LOG.error("Fail executing list query: " + query, ex);
        result.setException(EagleExceptionWrapper.wrap(ex));
        result.setSuccess(false);
        return result;
    } finally {
        watch.stop();
        result.setElapsedms(watch.getTime());
    }
    LOG.info("Query done " + watch.getTime() + " ms");
    return result;
}

From source file:com.qualogy.qafe.mgwt.server.RPCServiceImpl.java

public UIVOCluster getUISFromApplicationContext(Map<String, String> parameters) throws GWTServiceException {
    if (getServletContext().getAttribute("init_failure") != null) {
        Throwable throwable = (Throwable) getServletContext().getAttribute("init_failure");
        getServletContext().removeAttribute("init_failure");
        getServletContext().removeAttribute("init_failure_message");
        throw handleException(throwable);
    } else {/*from  w w  w .ja va2s.c  o m*/
        try {
            UIVOCluster cluster = null;

            Iterator<ApplicationIdentifier> contextItr = ApplicationCluster.getInstance().keysIterator();
            String appId = null;
            String windowSession = null;
            cluster = new UIVOCluster();
            cluster.setExternalProperties(ApplicationClusterUtil.getExternalProperties());
            cluster.setDebugMode(ContextLoaderHelper.isDebugMode());
            cluster.setShowLog(ContextLoaderHelper.showLog());
            cluster.setGlobalDateFormat(ApplicationClusterUtil.getGlobalDateFormat());
            cluster.setReloadable(ContextLoaderHelper.isReloadable(getThreadLocalRequest()));
            cluster.setUseDockMode(ContextLoaderHelper.isDockMode());

            cluster.setSystemMenuApplication(
                    service.getSystemApplication(ApplicationCluster.getInstance().getSystemApplicationContext(),
                            appId, windowSession, getLocale(), parameters));
            List<UIGVO> gvoList = new ArrayList<UIGVO>();

            StopWatch stopWatch = new StopWatch();

            while (contextItr.hasNext()) {
                ApplicationIdentifier key = contextItr.next();
                if (!ApplicationClusterUtil.isSystemApplication(key)) {
                    stopWatch.start();

                    UIGVO uigvo = null;
                    ApplicationContext context = ApplicationCluster.getInstance().get(key);

                    if (context.getLoadException() == null) {
                        try {
                            uigvo = service.getUI(context.getId(), appId, windowSession, getLocale(),
                                    parameters);
                        } catch (Exception e) {
                            String errorMessage = e != null ? "(" + e.getMessage() + ")" : "";
                            String message = key.toString() + " caused exception : " + errorMessage;
                            cluster.getMessages().add(message);
                        }

                    }

                    if (uigvo != null) {
                        uigvo.setAppId(context.getId().toString());
                        uigvo.setDebug(Boolean.valueOf(context.getConfigurationItem(/*
                                                                                    * Configuration.
                                                                                    * DEVELOPMENT_MODE
                                                                                    */"")));

                        uigvo.setTitle(context.getName());
                        stopWatch.stop();
                        uigvo.setTime(Long.valueOf(stopWatch.getTime()));
                        logger.info("Application -" + context.getName() + " is rendered in  "
                                + stopWatch.getTime() + "ms");

                        stopWatch.reset();
                        gvoList.add(uigvo);
                    } else {
                        stopWatch.stop();
                        stopWatch.reset();
                        String errorMessage = context.getLoadException() != null
                                ? "(" + context.getLoadException().getMessage() + ")"
                                : "";
                        String message = "Application with id " + key.toString() + " is not loaded! "
                                + errorMessage;

                        cluster.getMessages().add(message);
                    }

                    if (context.getWarningMessages() != null) {
                        for (String strMsg : context.getWarningMessages()) {
                            cluster.getMessages().add(strMsg);
                        }
                    }

                }
            }

            cluster.setVos(gvoList.toArray(new UIGVO[] {}));
            cluster = service.stripCluster(cluster);
            String css = CssProvider.getInstance().generateTypedCSS("gwt", null);
            cluster.setCss(css);
            return cluster;

        } catch (Exception e) {
            throw handleException(e);

        }
    }

}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

@Override
public ScrollableResults scrollableSearch(Long userId, DocumentState state, String queryString,
        SortOrder sortOrder, Date startDate, Date endDate) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final FullTextQuery fullTextQuery = this.buildFullTextQuery(queryString, userId, startDate, endDate, false,
            state, FullTextQuery.THIS, FullTextQuery.SCORE);

    final Sort sort;
    switch (sortOrder) {
    case DATE_ASC:
        sort = new Sort(new SortField("id", SortField.LONG));
        break;//from www.j a  v  a 2 s  .  com
    case DATE_DESC:
        sort = new Sort(new SortField("id", SortField.LONG, true));
        break;
    case RELEVANCE:
        sort = new Sort(SortField.FIELD_SCORE, new SortField("id", SortField.LONG, true));
        break;
    default:
        throw new IllegalArgumentException("Unexpected SortOrder: " + sortOrder.name());
    }
    fullTextQuery.setSort(sort);

    fullTextQuery.setFetchSize(50);
    fullTextQuery.setReadOnly(true);
    fullTextQuery.setCacheable(false);
    fullTextQuery.setCacheMode(CacheMode.IGNORE);

    final ScrollableResults result = fullTextQuery.scroll(ScrollMode.FORWARD_ONLY);

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return result;
}

From source file:com.liferay.portlet.InvokerPortletImpl.java

public void render(RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

    PortletException portletException = (PortletException) renderRequest
            .getAttribute(_portletId + PortletException.class.getName());

    if (portletException != null) {
        throw portletException;
    }// ww  w .  ja va2 s.  co  m

    StopWatch stopWatch = null;

    if (_log.isDebugEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();
    }

    String remoteUser = renderRequest.getRemoteUser();

    if ((remoteUser == null) || (_expCache == null) || (_expCache.intValue() == 0)) {

        invokeRender(renderRequest, renderResponse);
    } else {
        RenderResponseImpl renderResponseImpl = (RenderResponseImpl) renderResponse;

        StringServletResponse stringResponse = (StringServletResponse) renderResponseImpl
                .getHttpServletResponse();

        PortletSession portletSession = renderRequest.getPortletSession();

        long now = System.currentTimeMillis();

        Layout layout = (Layout) renderRequest.getAttribute(WebKeys.LAYOUT);

        Map<String, InvokerPortletResponse> sessionResponses = getResponses(portletSession);

        String sessionResponseId = encodeResponseKey(layout.getPlid(), _portletId,
                LanguageUtil.getLanguageId(renderRequest));

        InvokerPortletResponse response = sessionResponses.get(sessionResponseId);

        if (response == null) {
            String title = invokeRender(renderRequest, renderResponse);

            response = new InvokerPortletResponse(title, stringResponse.getString(),
                    now + Time.SECOND * _expCache.intValue());

            sessionResponses.put(sessionResponseId, response);
        } else if ((response.getTime() < now) && (_expCache.intValue() > 0)) {
            String title = invokeRender(renderRequest, renderResponse);

            response.setTitle(title);
            response.setContent(stringResponse.getString());
            response.setTime(now + Time.SECOND * _expCache.intValue());
        } else {
            renderResponseImpl.setTitle(response.getTitle());
            stringResponse.getWriter().print(response.getContent());
        }
    }

    Map<String, String[]> properties = ((RenderResponseImpl) renderResponse).getProperties();

    if (properties.containsKey("clear-request-parameters")) {
        Map<String, String[]> renderParameters = ((RenderRequestImpl) renderRequest).getRenderParameters();

        renderParameters.clear();
    }

    if (_log.isDebugEnabled()) {
        _log.debug("render for " + _portletId + " takes " + stopWatch.getTime() + " ms");
    }
}