List of usage examples for org.springframework.util StopWatch start
public void start() throws IllegalStateException
From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java
protected void resolveComponent(GenericComponent component, GenericPage page) { StopWatch stopWatch = null; if (logger.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); }//from w w w.j a v a 2s.com if (component != null) { // resolve regular content resolveMap(component.getContent()); // resolve metadata resolveMap(component.getMetadata()); /* don't resolve Component itself; * this may very likely lead to performance issues when using * the experience manager. */ // getLinkResolver().resolve(component, page); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("ResolveComponent for " + component.getId() + " finished in " + stopWatch.getTotalTimeMillis() + " ms"); } }
From source file:com.auditbucket.engine.service.MediationFacade.java
public Integer createHeaders(final Company company, final Fortress fortress, final List<MetaInputBean> inputBeans) throws DatagioException { fortress.setCompany(company);/* w w w . j av a2 s . c o m*/ Long id = DateTime.now().getMillis(); StopWatch watch = new StopWatch(); watch.start(); logger.info("Starting Batch [{}] - size [{}]", id, inputBeans.size()); boolean newMode = true; if (newMode) { // Tune to balance against concurrency and batch transaction insert efficiency. List<List<MetaInputBean>> splitList = Lists.partition(inputBeans, 20); for (List<MetaInputBean> metaInputBeans : splitList) { class DLCommand implements Command { Iterable<MetaInputBean> headers = null; DLCommand(List<MetaInputBean> processList) { this.headers = new CopyOnWriteArrayList<>(processList); } @Override public Command execute() throws DatagioException { //fortressService.registerFortress(company, new FortressInputBean(headers.iterator().next().getFortress()), true); Iterable<TrackResultBean> resultBeans = trackService.createHeaders(headers, company, fortress); processLogs(company, resultBeans); return this; } } DeadlockRetry.execute(new DLCommand(metaInputBeans), "creating headers", 20); } } else { logger.info("Processing in slow Transaction mode"); for (MetaInputBean inputBean : inputBeans) { createHeader(company, fortress, inputBean); } } watch.stop(); logger.info("Completed Batch [{}] - secs= {}, RPS={}", id, f.format(watch.getTotalTimeSeconds()), f.format(inputBeans.size() / watch.getTotalTimeSeconds())); return inputBeans.size(); }
From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java
protected void resolveXhtmlField(XhtmlField xhtmlField) { StopWatch stopWatch = null; if (logger.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); }//from www.ja va 2 s .c o m List<Object> xhtmlValues = xhtmlField.getValues(); List<String> newValues = new ArrayList<String>(); if (useXslt) { // find all component links and try to resolve them for (Object xhtmlValue : xhtmlValues) { String result = xslTransformer.transformSourceFromFilesource( "<ddtmproot>" + (String) xhtmlValue + "</ddtmproot>", "/resolveXhtmlWithLinks.xslt", params); newValues.add(XSLTPattern.matcher(result).replaceAll("")); } } else { // find all component links and try to resolve them for (Object xhtmlValue : xhtmlValues) { Matcher m = RegExpPattern.matcher((String) xhtmlValue); StringBuffer sb = new StringBuffer(); String resolvedLink = null; while (m.find()) { resolvedLink = getLinkResolver().resolve(m.group(1)); // if not possible to resolve the link do nothing if (resolvedLink != null) { m.appendReplacement(sb, "href=\"" + resolvedLink + "\""); } } m.appendTail(sb); newValues.add(sb.toString()); } } xhtmlField.setTextValues(newValues); if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Parsed rich text field '" + xhtmlField.getName() + "' in " + stopWatch.getTotalTimeMillis() + " ms."); } }
From source file:org.dd4t.core.factories.impl.SimplePageFactory.java
private Page getSimplePage(String uri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException("use of getPage is not allowed when a SecurityFilter is set"); }/*from ww w . ja v a 2 s. c o m*/ StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getSimplePage with uri: " + uri); stopWatch = new StopWatch("getSimplePage"); stopWatch.start(); } PageMeta pageMeta = null; Page page = null; try { TCMURI tcmUri = new TCMURI(uri); pageMeta = brokerPageProvider.getPageMetaById(tcmUri.getPublicationId(), tcmUri.getItemId()); page = (Page) getPageFromMeta(pageMeta); try { // run all filters regardless if they are allowed to be cached // or not doFilters(page, context, BaseFilter.RunPhase.Both); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } } catch (ParseException e) { logger.error("Parse exception when searching for page: " + uri, e); throw new RuntimeException(e); } catch (StorageException e) { logger.error("Storage exception when searching for page: " + uri, e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getSimplePage (" + stopWatch.getTotalTimeMillis() + " ms)"); } return page; }
From source file:org.dd4t.core.factories.impl.SimpleComponentFactory.java
/** * Get the component by the component uri and component template uri * /*w w w .j a v a2 s . c o m*/ * @return the component * @throws ItemNotFoundException * if no item found * @throws NotAuthorizedException * if the user is not authorized to get the item * @throws NotAuthenticatedException */ @Override public Component getComponent(String componentUri, String componentTemplateUri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException("use of getComponent is not allowed when a SecurityFilter is set"); } StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getComponent url: " + componentUri + " and componentTemplateUri: " + componentTemplateUri); stopWatch = new StopWatch("getComponent"); stopWatch.start(); } Component component = null; try { TCMURI tcmUri = new TCMURI(componentUri); ComponentMeta componentMeta = componentProvider.getComponentMeta(tcmUri.getItemId(), tcmUri.getPublicationId()); component = new SimpleComponentImpl(); component.setId(TridionUtils.createUri(componentMeta).toString()); component.setTitle(componentMeta.getTitle()); component.setNativeMetadata(componentMeta); PublicationImpl pub = new PublicationImpl(); pub.setId(String.valueOf(componentMeta.getPublicationId())); component.setPublication(pub); Schema schema = new SchemaImpl(); schema.setId(String.valueOf(componentMeta.getSchemaId())); component.setSchema(schema); if (componentTemplateUri != null) { TCMURI ctUri = new TCMURI(componentTemplateUri); component.setSource(componentProvider.getComponentXMLByTemplate(tcmUri.getItemId(), ctUri.getItemId(), tcmUri.getItemId())); } else { component.setSource(componentProvider.getComponentXML(tcmUri.getItemId(), tcmUri.getItemId())); } try { doFilters(component, context, BaseFilter.RunPhase.Both); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } } catch (ParseException e) { logger.error("Not able to parse uri: " + componentUri, e); throw new RuntimeException(e); } catch (StorageException e) { logger.error("Not possible to get uri: " + componentUri, e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getComponent (" + stopWatch.getTotalTimeMillis() + " ms)"); } return component; }
From source file:org.dd4t.core.factories.impl.GenericComponentFactory.java
public DynamicComponent getDCPFromSource(com.tridion.dcp.ComponentPresentation dcp) { StopWatch stopWatch = null; DynamicComponentImpl dynComp = null; if (logger.isDebugEnabled()) { stopWatch = new StopWatch("getComponentFromSource"); stopWatch.start(); }/*from w w w . jav a2s. c o m*/ try { if (logger.isDebugEnabled()) { stopWatch.stop(); stopWatch.start(); } dynComp = (DynamicComponentImpl) this.getSerializer().deserialize(dcp.getContent(), DynamicComponentImpl.class); dynComp.setNativeDCP(dcp); } catch (Exception e) { logger.error("error when deserializing component", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Deserialization of component took: " + stopWatch.getLastTaskTimeMillis() + " ms"); } } return dynComp; }
From source file:org.dd4t.core.factories.impl.SimpleBinaryFactory.java
private SimpleBinary getBinaryFromUri(String uri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, ParseException, StorageException, NotAuthenticatedException { StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getBinaryFromUri with uri: " + uri); stopWatch = new StopWatch("getBinaryFromUri"); stopWatch.start(); }/*from w ww. j av a 2s . com*/ SimpleBinaryImpl simpleBinary; // retrieve the SimpleComponent for this mm component ComponentFactory compFactory = new SimpleComponentFactory(); // make sure there are no filters set, we need only the simple component // factory logic itself! compFactory.setFilters(new LinkedList<Filter>()); Component mmComp = compFactory.getComponent(uri, context); simpleBinary = new SimpleBinaryImpl(); simpleBinary.setNativeMetadata(mmComp.getNativeMetadata()); simpleBinary.setFactory(this); simpleBinary.setId(TridionUtils.createUri(mmComp.getNativeMetadata()).toString()); simpleBinary.setTitle(mmComp.getNativeMetadata().getTitle()); try { doFilters(simpleBinary, context, null); } catch (FilterException e) { logger.warn("Error in filter. ", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getBinaryFromUri (" + stopWatch.getTotalTimeMillis() + " ms)"); } } return simpleBinary; }
From source file:com.persistent.cloudninja.scheduler.TenantWebBandWidthUsageGenerator.java
@Override public boolean execute() { StopWatch watch = new StopWatch(); LOGGER.info("Start of TenantWebBandWidthUsageGenerator:execute"); // Generate Queue TenantWebBandWidthUsageQueue queue = (TenantWebBandWidthUsageQueue) getWorkQueue(); boolean returnFlag = true; int batchSize = SchedulerSettings.WEB_BANDWIDTH_USAGE_BATCH_SIZE; int numBatchesPrepared = 0; int webLogMeteringBatchListSize = 0; try {//from w ww . j av a2s . c om watch.start(); List<WebLogMeteringBatch> webLogMeteringBatchList = tenantWebBandWidthUsageGeneratorUtility .retrieveTomcatLogs(); webLogMeteringBatchListSize = webLogMeteringBatchList.size(); for (int i = 0; i < webLogMeteringBatchListSize; i = i + batchSize) { List<WebLogMeteringBatch> batchToProcess = new ArrayList<WebLogMeteringBatch>(); for (int j = 0; j < batchSize && ((numBatchesPrepared * batchSize) + j) < webLogMeteringBatchList.size(); j++) { batchToProcess.add(webLogMeteringBatchList.get(j + i)); } // Enqueue queue.enqueue(batchToProcess); numBatchesPrepared++; } LOGGER.debug("TenantWebBandWidthUsageGenerator:execute ---> Number of batched processed" + numBatchesPrepared); LOGGER.info("End of TenantWebBandWidthUsageGenerator:execute"); watch.stop(); taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateMeterWebAppBandwidthWork", "Measure " + webLogMeteringBatchListSize + " logs in " + numBatchesPrepared + " batches."); } catch (StorageException stgException) { LOGGER.error(stgException.getMessage(), stgException); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return returnFlag; }
From source file:org.dd4t.core.factories.impl.SimplePageFactory.java
private Page findSimplePageByUrl(String url, int publicationId, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException("use of findPageByUrl is not allowed when a SecurityFilter is set"); }/*from www .java 2 s . c o m*/ StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter findSimplePageByUrl url: " + url + " and publicationId: " + publicationId); stopWatch = new StopWatch("findSimplePageByUrl"); stopWatch.start(); } PageMeta pageMeta = null; Page page = null; try { pageMeta = brokerPageProvider.getPageMetaByURL(url, publicationId); if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Got pageMeta in " + stopWatch.getTotalTimeMillis() + " ms"); stopWatch.start(); } page = (Page) getPageFromMeta(pageMeta); if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Got Page in " + stopWatch.getTotalTimeMillis() + " ms"); stopWatch.start(); } try { // run all filters regardless if they are allowed to be cached // or not doFilters(page, context, BaseFilter.RunPhase.Both); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Ran filters in " + stopWatch.getTotalTimeMillis() + " ms"); stopWatch.start(); } } catch (StorageException e) { logger.error("Storage exception when searching for page: " + url, e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit findSimplePageByUrl (" + stopWatch.getTotalTimeMillis() + " ms)"); } return page; }
From source file:org.dd4t.core.factories.impl.SimpleBinaryFactory.java
/** * Returns a BinaryMeta object or throws ItemNotFoundException if not found. * // ww w . ja va 2s . c o m * @param pubId * @param url * @return * @throws ItemNotFoundException * @throws StorageException */ private BinaryVariant getBinaryVariantByUrl(int pubId, String url) throws ItemNotFoundException, StorageException { StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getBinaryMetaByUrl with url: " + url + " and publicationId: " + pubId); stopWatch = new StopWatch("getBinaryMetaByUrl"); stopWatch.start(); } BinaryVariantDAO binaryVariantDAO = HomeUtils.getInstance().getBinaryVariantDao(pubId); BinaryVariant binaryVariant = null; try { binaryVariant = binaryVariantDAO.findByURL(pubId, url); if (binaryVariant == null) { if (logger.isDebugEnabled()) { logger.debug("Cannot find BinaryVariant in Tridion."); } throw new ItemNotFoundException("No binary found with url :" + url); } if (logger.isDebugEnabled()) { logger.debug("Returning BinaryMeta " + binaryVariant); } } catch (StorageException e) { logger.error("StorageException caught throw runtime exception"); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getBinaryMetaByUrl (" + stopWatch.getTotalTimeMillis() + " ms)"); } } return binaryVariant; }