List of usage examples for org.apache.commons.lang.time StopWatch stop
public void stop()
Stop the stopwatch.
This method ends a new timing session, allowing the time to be retrieved.
From source file:edu.internet2.middleware.psp.grouper.PspChangeLogConsumer.java
/** * Call the method of the {@link EventType} enum which matches the {@link ChangeLogEntry} category and action (the * change log type).//from ww w .ja v a 2 s . c o m * * @param changeLogEntry the change log entry * @throws Exception if an error occurs processing the change log entry */ public void processChangeLogEntry(ChangeLogEntry changeLogEntry) throws Exception { try { // find the method to run via the enum String enumKey = changeLogEntry.getChangeLogType().getChangeLogCategory() + "__" + changeLogEntry.getChangeLogType().getActionName(); EventType ldappcEventType = EventType.valueOf(enumKey); if (ldappcEventType == null) { LOG.debug("PSP Consumer '{}' - Change log entry '{}' Unsupported category and action.", name, toString(changeLogEntry)); } else { // process the change log event LOG.info("PSP Consumer '{}' - Change log entry '{}'", name, toStringDeep(changeLogEntry)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); ldappcEventType.process(this, changeLogEntry); stopWatch.stop(); LOG.info("PSP Consumer '{}' - Change log entry '{}' Finished processing. Elapsed time {}", new Object[] { name, toString(changeLogEntry), stopWatch, }); if (LOG.isDebugEnabled()) { for (String stats : PspCLI.getAllCacheStats()) { LOG.debug(stats); } } } } catch (IllegalArgumentException e) { LOG.debug("PSP Consumer '{}' - Change log entry '{}' Unsupported category and action.", name, toString(changeLogEntry)); } }
From source file:com.liferay.portal.search.elasticsearch.internal.ElasticsearchQuerySuggester.java
protected Suggest doSuggest(Suggester suggester, SearchContext searchContext) { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from w w w . j a v a2s.co m*/ Client client = elasticsearchConnectionManager.getClient(); SuggestRequestBuilder suggestRequestBuilder = client .prepareSuggest(indexNameBuilder.getIndexName(searchContext.getCompanyId())); SuggestBuilder suggestBuilder = suggesterTranslator.translate(suggester, searchContext); for (SuggestBuilder.SuggestionBuilder<?> suggestionBuilder : suggestBuilder.getSuggestion()) { suggestRequestBuilder.addSuggestion(suggestionBuilder); } if (suggester instanceof AggregateSuggester) { AggregateSuggester aggregateSuggester = (AggregateSuggester) suggester; suggestRequestBuilder.setSuggestText(aggregateSuggester.getValue()); } SuggestResponse suggestResponse = suggestRequestBuilder.get(); Suggest suggest = suggestResponse.getSuggest(); if (_log.isInfoEnabled()) { stopWatch.stop(); _log.info("Spell checked keywords in " + stopWatch.getTime() + "ms"); } return suggest; }
From source file:edu.utah.further.i2b2.hook.further.FurtherInterceptionFilter.java
/** * Send the i2b2 query request message to the FURTHeR FQE. Must be run after the i2b2 * processing chain, because it depends on the i2b2 query ID generated by the i2b2 * server./*from www. ja v a 2s . c o m*/ * * @param request * @param i2b2QueryId * i2b2 query ID, obtained from the i2b2 response */ private void spawnFurtherRequest(final HttpServletRequest request, final long i2b2QueryId) { if (log.isDebugEnabled()) { log.debug("Read i2b2QueryId from request: " + i2b2QueryId); } try { // Need to read create from request.getInputStream() multiple times // in this method ==> save a copy in a buffer first // inputStream is already at the end of the file. final InputStream inputStream = request.getInputStream(); final byte[] buffer = CoreUtil.readBytesFromStream(inputStream); inputStream.close(); // Decide whether to fork or not if (StringUtil.isValidLong(i2b2QueryId) && isProcessRequest(buffer)) { // Read the FURTHeR section of the i2b2 request body final String requestXml = new String(buffer); // Request contains an FQE processing flag, send to FURTHeR if (log.isDebugEnabled()) { ServletUtil.printRequestHeaders(request); ServletUtil.printRequestParameters(request); ServletUtil.printRequestAttributes(request); } // TODO: read query instance id from i2b2 response and pass to the // following call final QueryContextIdentifier id = furtherServices.i2b2QueryRequest(requestXml, i2b2QueryId); // Make available to response through the request, ensures thread safety // instead of using instance var request.setAttribute(QUERY_ID, id); QueryState state = furtherServices.getQueryState(id).getState(); final StopWatch stopWatch = new StopWatch(); final int interval = 10; int i = 0; stopWatch.start(); // Poll state every sec final long maxQueryTimeMillis = furtherServices.getMaxQueryTime() * 1000; while (state != QueryState.COMPLETED && state != QueryState.STOPPED && state != QueryState.FAILED && state != QueryState.INVALID && state != null && stopWatch.getTime() < maxQueryTimeMillis) { Thread.yield(); state = furtherServices.getQueryState(id).getState(); if (log.isDebugEnabled() && ((i % interval) == 0)) { log.debug("QueryState for query " + id.getId() + ": " + state); } i++; } stopWatch.stop(); } else { if (log.isDebugEnabled()) { log.info("Ignoring unrecognized/irrelvant requestXml"); } } } catch (final Throwable throwable) { if (log.isDebugEnabled()) { log.error("Caught " + throwable + ", ignoring", throwable); } } }
From source file:com.redhat.rhn.manager.errata.test.ErrataManagerTest.java
public void xxxxLookupErrataByAdvisoryType() throws IOException { String bugfix = "Bug Fix Advisory"; String pea = "Product Enhancement Advisory"; String security = "Security Advisory"; StopWatch st = new StopWatch(); st.start();//from ww w .ja v a 2 s. co m List erratas = ErrataManager.lookupErrataByType(bugfix); outputErrataList(erratas); System.out.println("Got bugfixes: " + erratas.size() + " time: " + st); assertTrue(erratas.size() > 0); erratas = ErrataManager.lookupErrataByType(pea); outputErrataList(erratas); System.out.println("Got pea enhancments: " + erratas.size() + " time: " + st); assertTrue(erratas.size() > 0); erratas = ErrataManager.lookupErrataByType(security); outputErrataList(erratas); assertTrue(erratas.size() > 0); System.out.println("Got security advisories: " + erratas.size() + " time: " + st); st.stop(); System.out.println("TIME: " + st.getTime()); }
From source file:net.nan21.dnet.core.web.controller.data.AbstractAsgnController.java
/** * Cancel changes/*from w w w. j a va2s .c o m*/ * * @param resourceName * @param dataFormat * @param objectId * @param selectionId * @param request * @param response * @return * @throws Exception */ @RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "=" + Constants.ASGN_ACTION_RESET) @ResponseBody public String reset(@PathVariable String resourceName, @PathVariable String dataFormat, @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId, @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId, HttpServletRequest request, HttpServletResponse response) throws Exception { try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (logger.isInfoEnabled()) { logger.info("Processing request: {}.{} -> action = {} ", new String[] { resourceName, dataFormat, Constants.ASGN_ACTION_RESET }); } if (logger.isDebugEnabled()) { logger.debug(" --> request-filter: objectId={}, selectionId={} ", new String[] { objectId, selectionId }); } this.prepareRequest(request, response); IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName)); service.reset(selectionId, objectId); stopWatch.stop(); return ""; } catch (Exception e) { return this.handleException(e, response); } finally { this.finishRequest(); } }
From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java
public List<TopicDocument> getTopicDocuments(final Long documentId) { final StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w. ja v a 2 s .c o m 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(); logger.debug(stopWatch.toString()); return filteredTopicDocuments; }
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 v a2s .com*/ * @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:au.id.hazelwood.xmltvguidebuilder.runner.App.java
public void run(File configFile, File outFile) throws InvalidConfigException, JAXBException, IOException { LOGGER.info("Running XMLTV Guide Builder"); StopWatch watch = new StopWatch(); watch.start();//from w w w.j a v a 2 s. c o m LOGGER.info("Reading config file '{}'", configFile.getCanonicalPath()); Config config = configFactory.create(configFile); DateTime today = new DateTime().withTimeAtStartOfDay(); DateTime from = today.plusDays(config.getOffset()); DateTime to = from.plusDays(config.getDays()); LOGGER.info("Getting listing from foxtel grabber between {} and {}", toISODateTime(from), toISODateTime(to)); ChannelListings channelListings = grabber.getListing(config, from, to, config.getChannelConfigs()); LOGGER.info("Verifying listings for all channels between {} and {}", new Object[] { toISODateTime(from), toISODateTime(to) }); DateTime subsetTo = from.plusDays(7).isBefore(to) ? from.plusDays(7) : to; listingVerifier.verifyListing(channelListings, from, to, subsetTo); LOGGER.info("Backup old output files"); backupOldOutputFiles(outFile); LOGGER.info("Writing result to {}", outFile.getCanonicalPath()); Writer writer = new BufferedWriter(new FileWriterWithEncoding(outFile, "UTF-8")); bindingService.marshal(xmltvMapper.toXmltv(channelListings), writer); IOUtils.closeQuietly(writer); watch.stop(); LOGGER.info("XMLTV Guide Builder successful in {}", formatDurationWords(watch.getTime())); }
From source file:net.nan21.dnet.core.web.controller.data.AbstractAsgnController.java
/** * Save changes//from w ww . j ava 2s.c om * * @param resourceName * @param dataFormat * @param objectId * @param selectionId * @param request * @param response * @return * @throws Exception */ @RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "=" + Constants.ASGN_ACTION_SAVE) @ResponseBody public String save(@PathVariable String resourceName, @PathVariable String dataFormat, @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId, @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId, HttpServletRequest request, HttpServletResponse response) throws Exception { try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (logger.isInfoEnabled()) { logger.info("Processing request: {}.{} -> action = {} ", new String[] { resourceName, dataFormat, Constants.ASGN_ACTION_SAVE }); } if (logger.isDebugEnabled()) { logger.debug(" --> request-filter: objectId={}, selectionId={} ", new String[] { objectId, selectionId }); } this.prepareRequest(request, response); this.authorizeAsgnAction(resourceName, "update"); IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName)); service.save(selectionId, objectId); stopWatch.stop(); return ""; } catch (Exception e) { return this.handleException(e, response); } finally { this.finishRequest(); } }
From source file:de.pro.dbw.application.testdata.service.ReflectionService.java
@Override protected Task<Void> createTask() { return new Task<Void>() { {/*w w w. j a va2 s. co m*/ updateProgress(0, saveMaxEntities); } @Override protected Void call() throws Exception { LoggerFacade.INSTANCE.deactivate(Boolean.TRUE); final StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ICrudService crudService = DatabaseFacade.INSTANCE.getCrudService(entityName); long id = -1_000_000_000L + DatabaseFacade.INSTANCE.getCrudService().count(entityName); for (int i = 1; i <= saveMaxEntities; i++) { crudService.beginTransaction(); final ReflectionModel model = new ReflectionModel(); model.setGenerationTime(ReflectionService.this.createGenerationTime()); model.setId(id++); model.setTitle(LoremIpsum.getDefault().getTitle()); model.setText(LoremIpsum.getDefault().getText()); crudService.create(model, false); updateProgress(i - 1, saveMaxEntities); crudService.commitTransaction(); } LoggerFacade.INSTANCE.deactivate(Boolean.FALSE); stopWatch.split(); LoggerFacade.INSTANCE.debug(this.getClass(), " + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Reflections."); // NOI18N stopWatch.stop(); return null; } }; }