List of usage examples for org.apache.commons.lang.time StopWatch start
public void start()
Start the stopwatch.
This method starts a new timing session, clearing any previous values.
From source file:com.liferay.mail.imap.IMAPConnection.java
protected void testIncomingConnection() throws MailException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); try {/* www . j ava 2 s. co m*/ Store store = getStore(false); store.close(); } catch (Exception e) { throw new MailException(MailException.ACCOUNT_INCOMING_CONNECTION_FAILED, e); } finally { if (_log.isDebugEnabled()) { stopWatch.stop(); _log.debug("Testing incoming connection completed in " + stopWatch.getTime() + " ms"); } } }
From source file:com.liferay.portal.search.internal.SearchEngineInitializer.java
protected void doReIndex(int delay) { if (IndexWriterHelperUtil.isIndexReadOnly()) { return;//from w w w. ja v a2 s . c o m } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene started"); } if (delay < 0) { delay = 0; } try { if (delay > 0) { Thread.sleep(Time.SECOND * delay); } } catch (InterruptedException ie) { } ExecutorService executorService = _portalExecutorManager .getPortalExecutor(SearchEngineInitializer.class.getName()); StopWatch stopWatch = new StopWatch(); stopWatch.start(); try { SearchEngineHelperUtil.removeCompany(_companyId); SearchEngineHelperUtil.initialize(_companyId); long backgroundTaskId = BackgroundTaskThreadLocal.getBackgroundTaskId(); List<FutureTask<Void>> futureTasks = new ArrayList<>(); Set<String> searchEngineIds = new HashSet<>(); for (Indexer<?> indexer : IndexerRegistryUtil.getIndexers()) { String searchEngineId = indexer.getSearchEngineId(); if (searchEngineIds.add(searchEngineId)) { IndexWriterHelperUtil.deleteEntityDocuments(searchEngineId, _companyId, indexer.getClassName(), true); } FutureTask<Void> futureTask = new FutureTask<>(new Callable<Void>() { @Override public Void call() throws Exception { BackgroundTaskThreadLocal.setBackgroundTaskId(backgroundTaskId); reindex(indexer); return null; } }); executorService.submit(futureTask); futureTasks.add(futureTask); } for (FutureTask<Void> futureTask : futureTasks) { futureTask.get(); } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene completed in " + (stopWatch.getTime() / Time.SECOND) + " seconds"); } } catch (Exception e) { _log.error("Error encountered while reindexing", e); if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene failed"); } } _finished = true; }
From source file:com.liferay.mail.imap.IMAPConnection.java
protected void testOutgoingConnection() throws MailException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); try {/*from w w w. j av a 2 s .c o m*/ Transport transport = getTransport(); transport.isConnected(); transport.close(); } catch (Exception e) { throw new MailException(MailException.ACCOUNT_OUTGOING_CONNECTION_FAILED, e); } finally { if (_log.isDebugEnabled()) { stopWatch.stop(); _log.debug("Testing outgoing connection completed in " + stopWatch.getTime() + " ms"); } } }
From source file:com.liferay.vldap.server.handler.SearchLdapHandler.java
protected void addEntries(InternalSearchRequest internalSearchRequest, List<InternalResponse> internalResponses, LdapHandlerContext ldapHandlerContext, Directory directory) throws Exception { SearchScope searchScope = internalSearchRequest.getScope(); StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (searchScope.equals(SearchScope.OBJECT)) { addObjectEntry(internalSearchRequest, internalResponses, ldapHandlerContext, directory, stopWatch); } else if (searchScope.equals(SearchScope.ONELEVEL)) { for (Directory curDirectory : directory.getDirectories()) { addObjectEntry(internalSearchRequest, internalResponses, ldapHandlerContext, curDirectory, stopWatch);/*from w ww .j a v a2 s .c om*/ } } else if (searchScope.equals(SearchScope.SUBTREE)) { addSubtreeEntries(internalSearchRequest, internalResponses, ldapHandlerContext, directory, stopWatch); } }
From source file:com.nridge.connector.fs.con_fs.core.RunPublishFS.java
/** * When an object implementing interface <code>Runnable</code> is used * to create a thread, starting the thread causes the object's * <code>run</code> method to be called in that separately executing * thread./*from www . java2 s . co m*/ * * The general contract of the method <code>run</code> is that it may * take any action whatsoever. * * @see Thread#run() */ @Override public void run() { Document conDoc; DocumentXML documentXML; String docId, queueItem, srcPathFileName; Logger appLogger = mAppMgr.getLogger(this, "run"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); boolean isPublisherInitialized = true; DataBag schemaBag = (DataBag) mAppMgr.getProperty(Connector.PROPERTY_SCHEMA_NAME); Publishers indexPublishers = new Publishers(mAppMgr, mCrawlQueue, Constants.CFG_PROPERTY_PREFIX); try { indexPublishers.initialize(schemaBag); } catch (NSException e) { isPublisherInitialized = false; appLogger.error("Publisher initialization: " + e.getMessage()); } if (isPublisherInitialized) { BlockingQueue transformQueue = (BlockingQueue) mAppMgr.getProperty(Connector.QUEUE_TRANSFORM_NAME); BlockingQueue publishQueue = (BlockingQueue) mAppMgr.getProperty(Connector.QUEUE_PUBLISH_NAME); long queueWaitTimeout = mAppMgr.getLong(Constants.CFG_PROPERTY_PREFIX + ".queue.wait_timeout", Constants.QUEUE_POLL_TIMEOUT_DEFAULT); do { try { queueItem = (String) transformQueue.poll(queueWaitTimeout, TimeUnit.SECONDS); if (mCrawlQueue.isQueueItemDocument(queueItem)) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); docId = Connector.docIdFromQueueItem(queueItem); appLogger.debug(String.format("Transform Queue Item: %s", docId)); srcPathFileName = mCrawlQueue.docPathFileName(Connector.QUEUE_TRANSFORM_NAME, docId); try { documentXML = new DocumentXML(); documentXML.load(srcPathFileName); conDoc = documentXML.getDocument(); indexPublishers.send(conDoc); File srcFile = new File(srcPathFileName); if (!srcFile.delete()) appLogger.warn(String.format("%s: Unable to delete.", srcPathFileName)); stopWatch.stop(); queueItem = Connector.queueItemIdPhaseTime(queueItem, Connector.PHASE_PUBLISH, stopWatch.getTime()); try { // If queue is full, this thread may block. publishQueue.put(queueItem); } catch (InterruptedException e) { // Restore the interrupted status so parent can handle (if it wants to). Thread.currentThread().interrupt(); } } catch (Exception e) { String msgStr = String.format("%s: %s", docId, e.getMessage()); appLogger.error(msgStr, e); MailManager mailManager = (MailManager) mAppMgr .getProperty(Connector.PROPERTY_MAIL_NAME); mailManager.addMessage(Connector.PHASE_PUBLISH, Connector.STATUS_MAIL_ERROR, msgStr, Constants.MAIL_DETAIL_MESSAGE); } } } catch (InterruptedException e) { queueItem = StringUtils.EMPTY; } } while (!mCrawlQueue.isPhaseComplete(Connector.PHASE_TRANSFORM, queueItem)); // Forward the marker queue item to the next queue. if (mCrawlQueue.isQueueItemMarker(queueItem)) { try { // If queue is full, this thread may block. publishQueue.put(queueItem); } catch (InterruptedException e) { // Restore the interrupted status so parent can handle (if it wants to). Thread.currentThread().interrupt(); } } // Now we can shutdown our search indexer publisher. try { indexPublishers.shutdown(); } catch (NSException e) { appLogger.error("Publisher shutdown: " + e.getMessage()); } } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.liferay.portal.search.elasticsearch.ElasticsearchQuerySuggester.java
@Override public String[] suggestKeywordQueries(SearchContext searchContext, int max) { StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); }/* w w w. j av a2 s . co m*/ SuggestBuilder.SuggestionBuilder<PhraseSuggestionBuilder> suggestionBuilder = SuggestBuilder .phraseSuggestion(_REQUEST_TYPE_KEYWORD_QUERY); Suggest.Suggestion<?> suggestion = getSuggestion(searchContext, suggestionBuilder, DocumentTypes.KEYWORD_QUERY, Field.KEYWORD_SEARCH, _REQUEST_TYPE_KEYWORD_QUERY, max); List<?> entries = suggestion.getEntries(); Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option> suggestionEntry = (Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>) entries .get(0); List<String> keywordQueries = new ArrayList<String>(); for (Suggest.Suggestion.Entry.Option option : suggestionEntry.getOptions()) { String optionText = String.valueOf(option.getText()); keywordQueries.add(optionText); } if (_log.isInfoEnabled()) { stopWatch.stop(); _log.info("Suggested keyword queries in " + stopWatch.getTime() + "ms"); } return keywordQueries.toArray(new String[keywordQueries.size()]); }
From source file:com.liferay.portal.search.lucene.LuceneIndexer.java
protected void doReIndex(int delay) { if (SearchEngineUtil.isIndexReadOnly()) { return;/* w w w . j a v a 2 s . co m*/ } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene started"); } if (delay < 0) { delay = 0; } try { if (delay > 0) { Thread.sleep(Time.SECOND * delay); } } catch (InterruptedException ie) { } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } try { LuceneHelperUtil.delete(_companyId); List<Portlet> portlets = PortletLocalServiceUtil.getPortlets(_companyId); portlets = ListUtil.sort(portlets, new PortletLuceneComparator()); for (Portlet portlet : portlets) { if (!portlet.isActive()) { continue; } List<Indexer> indexers = portlet.getIndexerInstances(); if (indexers == null) { continue; } for (Indexer indexer : indexers) { reindex(indexer); } } if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene completed in " + (stopWatch.getTime() / Time.SECOND) + " seconds"); } } catch (Exception e) { _log.error("Error encountered while reindexing", e); if (_log.isInfoEnabled()) { _log.info("Reindexing Lucene failed"); } } _finished = true; }
From source file:net.nan21.dnet.core.web.controller.data.AbstractDsRpcController.java
/** * Default handler for remote procedure call on a filter. * //from ww w .j a va 2 s. c o m * @param resourceName * @param dataformat * @param dataString * @param paramString * @return * @throws Exception */ @RequestMapping(method = RequestMethod.POST, params = { Constants.REQUEST_PARAM_ACTION + "=" + Constants.DS_ACTION_RPC, Constants.DS_ACTION_RPC + "Type=filter" }) @ResponseBody public String rpcFilter(@PathVariable String resourceName, @PathVariable String dataFormat, @RequestParam(value = Constants.REQUEST_PARAM_SERVICE_NAME_PARAM, required = true) String rpcName, @RequestParam(value = Constants.REQUEST_PARAM_DATA, required = false, defaultValue = "{}") String dataString, @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString, HttpServletRequest request, HttpServletResponse response) throws Exception { try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (logger.isInfoEnabled()) { logger.info("Processing request: {}.{} -> action = {}-filter / {}", new String[] { resourceName, dataFormat, Constants.DS_ACTION_RPC, rpcName }); } if (logger.isDebugEnabled()) { logger.debug(" --> request-data: {} ", new String[] { dataString }); logger.debug(" --> request-params: {} ", new String[] { paramString }); } this.prepareRequest(request, response); this.authorizeDsAction(resourceName, Constants.DS_ACTION_RPC, rpcName); IDsService<M, F, P> service = this.findDsService(resourceName); IDsMarshaller<M, F, P> marshaller = service.createMarshaller(dataFormat); F filter = marshaller.readFilterFromString(dataString); P params = marshaller.readParamsFromString(paramString); service.rpcFilter(rpcName, filter, params); IActionResultRpcFilter result = this.packRpcFilterResult(filter, params); stopWatch.stop(); result.setExecutionTime(stopWatch.getTime()); return marshaller.writeResultToString(result); } finally { this.finishRequest(); } }
From source file:com.liferay.portal.search.elasticsearch.ElasticsearchQuerySuggester.java
@Override public Map<String, List<String>> spellCheckKeywords(SearchContext searchContext, int max) { StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); }/*from ww w . j a v a2s . c o m*/ SuggestBuilder.SuggestionBuilder<TermSuggestionBuilder> suggestionBuilder = SuggestBuilder .termSuggestion(_REQUEST_TYPE_SPELL_CHECK); Suggest.Suggestion<?> suggestion = getSuggestion(searchContext, suggestionBuilder, DocumentTypes.SPELL_CHECK, Field.SPELL_CHECK_WORD, _REQUEST_TYPE_SPELL_CHECK, max); Map<String, List<String>> suggestionsMap = new HashMap<String, List<String>>(); for (Object entry : suggestion.getEntries()) { Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option> suggestionEntry = (Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>) entry; String text = String.valueOf(suggestionEntry.getText()); List<String> suggestionsList = suggestionsMap.get(text); if (suggestionsList == null) { suggestionsList = new ArrayList<String>(); suggestionsMap.put(text, suggestionsList); } for (Suggest.Suggestion.Entry.Option option : suggestionEntry.getOptions()) { String optionText = String.valueOf(option.getText()); suggestionsList.add(optionText); } } if (_log.isInfoEnabled()) { stopWatch.stop(); _log.info("Spell checked keywords in " + stopWatch.getTime() + "ms"); } return suggestionsMap; }
From source file:com.liferay.portal.scripting.ScriptingImpl.java
public Map<String, Object> eval(Set<String> allowedClasses, Map<String, Object> inputObjects, Set<String> outputNames, String language, String script) throws ScriptingException { ScriptingExecutor scriptingExecutor = _scriptingExecutors.get(language); if (scriptingExecutor == null) { throw new UnsupportedLanguageException(language); }/* w ww .j av a 2 s .co m*/ StopWatch stopWatch = null; if (_log.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } try { return scriptingExecutor.eval(allowedClasses, inputObjects, outputNames, script); } catch (Exception e) { throw new ScriptingException(getErrorMessage(script, e), e); } finally { if (_log.isDebugEnabled()) { _log.debug("Evaluated script in " + stopWatch.getTime() + " ms"); } } }