List of usage examples for org.springframework.util StopWatch getTotalTimeMillis
public long getTotalTimeMillis()
From source file:org.dd4t.core.factories.impl.SimpleComponentFactory.java
/** * Get the component by the component uri and component template uri * //from w w w . j a v a 2 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.GenericPageFactory.java
private GenericPage getGenericPage(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 w w w . j a va 2 s .co m*/ StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getGenericPage with uri: " + uri); stopWatch = new StopWatch("getGenericPage"); stopWatch.start(); } GenericPage page = (GenericPage) getCacheProvider().loadFromLocalCache(uri); if (page == null) { try { TCMURI tcmUri = new TCMURI(uri); PageMeta pageMeta = getPageProvider().getPageMetaById(tcmUri.getItemId(), tcmUri.getPublicationId()); if (pageMeta == null) throw new ItemNotFoundException("Unable to find page by id " + tcmUri); page = getPageFromMeta(pageMeta); try { // run only the filters where the result is allowed to be // cached. doFilters(page, context, BaseFilter.RunPhase.BeforeCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } getCacheProvider().storeInItemCache(uri, page, tcmUri.getPublicationId(), tcmUri.getItemId()); } catch (IOException e) { logger.error("IOException when processing page: " + uri, e); throw new RuntimeException(e); } catch (ParseException e) { logger.error("ParseException when searching for page: " + uri, e); throw new RuntimeException(e); } catch (StorageException e) { logger.error("StorageException when searching for page: " + uri, e); throw new RuntimeException(e); } } try { // run only the filters where the result is not allowed to be // cached. doFilters(page, context, BaseFilter.RunPhase.AfterCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getGenericPage (" + stopWatch.getTotalTimeMillis() + " ms)"); } } return page; }
From source file:com.googlecode.flyway.core.validation.DbValidator.java
/** * Validate the checksum of all existing sql migration in the metadata table with the checksum of the sql migrations * in the classpath/* w w w . j a v a 2 s .c o m*/ * * @param resolvedMigrations All migrations available on the classpath, sorted by version, newest first. * @return description of validation error or NULL if no validation error was found */ public String validate(List<Migration> resolvedMigrations) { if (ValidationMode.NONE.equals(validationMode)) { return null; } LOG.debug(String.format("Validating (mode %s) migrations ...", validationMode)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); final List<MetaDataTableRow> appliedMigrations = new ArrayList<MetaDataTableRow>( metaDataTable.allAppliedMigrations()); if (appliedMigrations.isEmpty()) { LOG.info("No migrations applied yet. No validation necessary."); return null; } List<Migration> migrations = new ArrayList<Migration>(resolvedMigrations); // migrations now with newest last Collections.reverse(migrations); final MetaDataTableRow firstAppliedMigration = appliedMigrations.get(0); if (MigrationType.INIT.equals(firstAppliedMigration.getMigrationType())) { // if first migration is INIT, just check checksum of following migrations final SchemaVersion initVersion = firstAppliedMigration.getVersion(); appliedMigrations.remove(firstAppliedMigration); Iterator<Migration> iterator = migrations.iterator(); while (iterator.hasNext()) { Migration migration = iterator.next(); if (migration.getVersion().compareTo(initVersion) <= 0) { iterator.remove(); } } } if (appliedMigrations.size() > migrations.size()) { List<SchemaVersion> schemaVersions = new ArrayList<SchemaVersion>(); for (MetaDataTableRow metaDataTableRow : appliedMigrations) { schemaVersions.add(metaDataTableRow.getVersion()); } for (Migration migration : migrations) { schemaVersions.remove(migration.getVersion()); } String diff = StringUtils.collectionToCommaDelimitedString(schemaVersions); return String.format( "More applied migrations than classpath migrations: DB=%s, Classpath=%s, Missing migrations=(%s)", appliedMigrations.size(), migrations.size(), diff); } for (int i = 0; i < appliedMigrations.size(); i++) { MetaDataTableRow appliedMigration = appliedMigrations.get(i); //Migrations are sorted in the opposite order: newest first. Migration classpathMigration = migrations.get(i); if (!appliedMigration.getVersion().equals(classpathMigration.getVersion())) { return String.format("Version mismatch for migration %s: DB=%s, Classpath=%s", appliedMigration.getScript(), appliedMigration.getVersion(), classpathMigration.getVersion()); } if (!appliedMigration.getMigrationType().equals(classpathMigration.getMigrationType())) { return String.format("Migration Type mismatch for migration %s: DB=%s, Classpath=%s", appliedMigration.getScript(), appliedMigration.getMigrationType(), classpathMigration.getMigrationType()); } final Integer appliedChecksum = appliedMigration.getChecksum(); final Integer classpathChecksum = classpathMigration.getChecksum(); if (!ObjectUtils.nullSafeEquals(appliedChecksum, classpathChecksum)) { return String.format("Checksum mismatch for migration %s: DB=%s, Classpath=%s", appliedMigration.getScript(), appliedChecksum, classpathMigration.getChecksum()); } } stopWatch.stop(); if (appliedMigrations.size() == 1) { LOG.info(String.format("Validated 1 migration (mode: %s) (execution time %s)", validationMode, TimeFormat.format(stopWatch.getTotalTimeMillis()))); } else { LOG.info(String.format("Validated %d migrations (mode: %s) (execution time %s)", appliedMigrations.size(), validationMode, TimeFormat.format(stopWatch.getTotalTimeMillis()))); } return null; }
From source file:org.dd4t.core.factories.impl.GenericComponentFactory.java
/** * Get the component by the component uri and template uri. * /*w w w . j a va2 s . c om*/ * @return the component * @throws ItemNotFoundException * if no item found NotAuthorizedException if the user is not * authorized to get the component * @throws NotAuthenticatedException */ public DynamicComponent getComponent(String componentUri, String componentTemplateUri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException( "use of getComponent without a context is not allowed when a SecurityFilter is set"); } if (!componentUri.endsWith("-16")) { componentUri += "-16"; } StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getComponent with uri: " + componentUri); stopWatch = new StopWatch("getComponent"); stopWatch.start(); } DynamicComponent component = (DynamicComponent) getCacheProvider().loadFromLocalCache(componentUri); if (component == null) { TCMURI tcmUri; ComponentMeta componentMeta; com.tridion.dcp.ComponentPresentation dcp; try { tcmUri = new TCMURI(componentUri); componentMeta = getComponentProvider().getComponentMeta(tcmUri.getItemId(), tcmUri.getPublicationId()); if (componentMeta == null) { throw new ItemNotFoundException("Unable to find item with id " + componentUri + " in the broker. Is the item published?"); } if (componentTemplateUri != null) { TCMURI ctUri = new TCMURI(componentTemplateUri); dcp = getComponentProvider().getDynamicComponentPresentation(tcmUri.getItemId(), ctUri.getItemId(), tcmUri.getPublicationId()); } else { dcp = getComponentProvider().getDynamicComponentPresentation(tcmUri.getItemId(), 0, tcmUri.getPublicationId()); } } catch (ParseException e1) { logger.error("No item found with uri: " + componentUri + "; could not parse the URI: " + e1); throw new ItemNotFoundException( "No item found with uri: " + componentUri + "; could not parse the URI: " + e1); } catch (StorageException e2) { logger.error("No item found with uri: " + componentUri + "; broker is down."); throw new ItemNotFoundException("No item found with uri: " + componentUri + "; broker is down."); } if (dcp.getContent() == null) { logger.error( "Source is null for item: " + componentUri + " and templateUri: " + componentTemplateUri); throw new ItemNotFoundException( "No item found with uri: " + componentUri + " and templateUri: " + componentTemplateUri); } try { component = getDCPFromSource(dcp); component.setNativeMetadata(componentMeta); // Rogier Oudshoorn, 7/2/2012 // object size is roughly half the xml string size; ((BasePublishedItem) component).setSourceSize(dcp.getContent().length()); try { doFilters(component, context, BaseFilter.RunPhase.BeforeCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } getCacheProvider().storeInItemCache(componentUri, component, component.getNativeMetadata().getPublicationId(), component.getNativeMetadata().getItemId()); } catch (Exception e) { logger.error("error when deserializing component", e); throw new RuntimeException(e); } } try { doFilters(component, context, BaseFilter.RunPhase.AfterCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getComponent (" + stopWatch.getTotalTimeMillis() + " ms)"); } return component; }
From source file:fr.univrouen.poste.services.GalaxieExcelParser.java
public void process(GalaxieExcel galaxieExcel) throws SQLException { StopWatch chrono = new StopWatch(); chrono.start();//from ww w . j av a 2 s .com List<List<String>> cells = excelParser .getCells(galaxieExcel.getBigFile().getBinaryFile().getBinaryStream()); Map<String, Long> cellsPosition = new HashMap<String, Long>(); int p = 0; List<String> cellsHead = cells.remove(0); for (String cellName : cellsHead) { cellsPosition.put(cellName, new Long(p++)); } galaxieMappingService.checkCellsHead(cellsPosition); Map<List<String>, GalaxieEntry> dbGalaxyEntries = new HashMap<List<String>, GalaxieEntry>(); for (GalaxieEntry galaxieEntry : GalaxieEntry.findAllGalaxieEntrys()) { dbGalaxyEntries.put(getList4Id(galaxieEntry), galaxieEntry); } for (List<String> row : cells) { // create a new galaxyEntry GalaxieEntry galaxieEntry = new GalaxieEntry(); for (String cellName : cellsPosition.keySet()) { int position = cellsPosition.get(cellName).intValue(); if (row.size() > position) { String cellValue = row.get(position); galaxieMappingService.setAttrFromCell(galaxieEntry, cellName, cellValue); } else { logger.debug("can't get " + cellName + " for this row in excel file ..."); } } // Rcupration d'un GalaxieEntry chaque fois trop gourmand, mme avec l'index ... //TypedQuery<GalaxieEntry> query = GalaxieEntry.findGalaxieEntrysByNumEmploiAndNumCandidat(galaxieEntry.getNumEmploi(), galaxieEntry.getNumCandidat(), null, null); GalaxieEntry dbGalaxyEntrie = dbGalaxyEntries.get(getList4Id(galaxieEntry)); if (dbGalaxyEntrie == null) { galaxieEntry.persist(); dbGalaxyEntries.put(getList4Id(galaxieEntry), galaxieEntry); } else { // This GalaxyEntry exists already, we merge it if needed if (!fieldsEquals(dbGalaxyEntrie, galaxieEntry)) { dbGalaxyEntrie.setCivilite(galaxieEntry.getCivilite()); dbGalaxyEntrie.setNom(galaxieEntry.getNom()); dbGalaxyEntrie.setPrenom(galaxieEntry.getPrenom()); if (dbGalaxyEntrie.getEmail().isEmpty()) { if (!galaxieEntry.getEmail().isEmpty()) { dbGalaxyEntrie.setEmail(galaxieEntry.getEmail()); logger.info("Le candidat " + dbGalaxyEntrie.getNumCandidat() + " a maintenant renseign son email : " + galaxieEntry.getEmail()); } } // si email diffrent et si le candidat n'a pas activ son compte - on rinitialise le compte == on le supprime et on le rcr avec cette nvelle adresse mail else if (!dbGalaxyEntrie.getEmail().equals(galaxieEntry.getEmail())) { try { User user = User.findUsersByEmailAddress(dbGalaxyEntrie.getEmail()).getSingleResult(); if (user.getActivationDate() == null && !user.isCandidatActif()) { logger.info("Le candidat " + dbGalaxyEntrie.getNumCandidat() + " a chang d'email alors qu'il n'avait pas encore activ son compte - on relance la procdure de cration de son compte/candidature."); // cas o le candidat postule plusieurs postes pris en compte ainsi List<GalaxieEntry> userGalaxieEntries = GalaxieEntry .findGalaxieEntrysByCandidat(user).getResultList(); for (GalaxieEntry userGalaxieEntry : userGalaxieEntries) { dbGalaxyEntries.remove(getList4Id(userGalaxieEntry)); } user.remove(); galaxieEntry.persist(); dbGalaxyEntries.put(getList4Id(galaxieEntry), galaxieEntry); continue; } dbGalaxyEntrie.setEmail(galaxieEntry.getEmail()); } catch (Exception e) { logger.warn("Pb avec le candidat " + dbGalaxyEntrie.getNumCandidat() + " qui a chang d'email ...", e); } } dbGalaxyEntrie.setLocalisation(galaxieEntry.getLocalisation()); dbGalaxyEntrie.setProfil(galaxieEntry.getProfil()); dbGalaxyEntrie.setEtatDossier(galaxieEntry.getEtatDossier()); dbGalaxyEntrie.merge(); } } } chrono.stop(); logger.info("Le traitement du fichier Excel Galaxie a t effectu en " + chrono.getTotalTimeMillis() / 1000.0 + " sec."); }
From source file:com.jxt.web.service.FilteredMapServiceImpl.java
/** * filtered application map// ww w . j ava2 s .co m */ @Override public ApplicationMap selectApplicationMap(List<TransactionId> transactionIdList, Range originalRange, Range scanRange, Filter filter) { if (transactionIdList == null) { throw new NullPointerException("transactionIdList must not be null"); } if (filter == null) { throw new NullPointerException("filter must not be null"); } StopWatch watch = new StopWatch(); watch.start(); final List<List<SpanBo>> filterList = selectFilteredSpan(transactionIdList, filter); DotExtractor dotExtractor = createDotExtractor(scanRange, filterList); ApplicationMap map = createMap(originalRange, scanRange, filterList); ApplicationMapWithScatterScanResult applicationMapWithScatterScanResult = new ApplicationMapWithScatterScanResult( map, dotExtractor.getApplicationScatterScanResult()); watch.stop(); logger.debug("Select filtered application map elapsed. {}ms", watch.getTotalTimeMillis()); return applicationMapWithScatterScanResult; }
From source file:com.jxt.web.service.FilteredMapServiceImpl.java
@Override public ApplicationMap selectApplicationMapWithScatterData(List<TransactionId> transactionIdList, Range originalRange, Range scanRange, int xGroupUnit, int yGroupUnit, Filter filter) { if (transactionIdList == null) { throw new NullPointerException("transactionIdList must not be null"); }//from w w w . j a v a2s . c o m if (filter == null) { throw new NullPointerException("filter must not be null"); } StopWatch watch = new StopWatch(); watch.start(); final List<List<SpanBo>> filterList = selectFilteredSpan(transactionIdList, filter); DotExtractor dotExtractor = createDotExtractor(scanRange, filterList); ApplicationMap map = createMap(originalRange, scanRange, filterList); ApplicationMapWithScatterData applicationMapWithScatterData = new ApplicationMapWithScatterData(map, dotExtractor.getApplicationScatterData(originalRange.getFrom(), originalRange.getTo(), xGroupUnit, yGroupUnit)); watch.stop(); logger.debug("Select filtered application map elapsed. {}ms", watch.getTotalTimeMillis()); return applicationMapWithScatterData; }
From source file:io.mandrel.worker.Loop.java
protected Blob processBlob(Uri uri, StopWatch watch, Requester<? extends Strategy> r) throws Exception { Blob blob;//from ww w.j a v a 2 s . c om blob = r.get(uri); watch.stop(); log.trace("> Start parsing data for {}", uri); blob.getMetadata().getFetchMetadata().setTimeToFetch(watch.getTotalTimeMillis()); updateMetrics(watch, blob); Map<String, Instance<?>> cachedSelectors = new HashMap<>(); if (spider.getExtractors() != null && spider.getExtractors().getData() != null) { log.trace("> - Extracting documents for {}...", uri); spider.getExtractors().getData().forEach(ex -> { List<Document> documents = extractorService.extractThenFormatThenStore(spider.getId(), cachedSelectors, blob, ex); if (documents != null) { spiderAccumulator.incDocumentForExtractor(ex.getName(), documents.size()); } }); log.trace("> - Extracting documents for {} done!", uri); } if (spider.getExtractors().getOutlinks() != null) { log.trace("> - Extracting outlinks for {}...", uri); final Uri theUri = uri; spider.getExtractors().getOutlinks().forEach(ol -> { Set<Link> allFilteredOutlinks = extractorService .extractAndFilterOutlinks(spider, theUri, cachedSelectors, blob, ol).getRight(); blob.getMetadata().getFetchMetadata().setOutlinks(allFilteredOutlinks); add(spider.getId(), allFilteredOutlinks.stream().map(l -> l.getUri()).collect(Collectors.toSet())); }); log.trace("> - Extracting outlinks done for {}!", uri); } BlobStores.get(spider.getId()).ifPresent(b -> b.putBlob(blob.getMetadata().getUri(), blob)); log.trace("> - Storing metadata for {}...", uri); MetadataStores.get(spider.getId()).addMetadata(blob.getMetadata().getUri(), blob.getMetadata()); log.trace("> - Storing metadata for {} done!", uri); log.trace("> End parsing data for {}", uri); return blob; }
From source file:no.abmu.abmstatistikk.annualstatistic.service.hibernate2.AnnualStatisticServiceHelper.java
protected ReportStatus[] getReportStatusBySchemaTypeAndYear( List<OrganisationUnitForBrowsing> orgUnitsForBrodwsing, String schemaTypeName, int reportYear) { StopWatch stopWatch = new StopWatch(); stopWatch.start();// w ww . j a va 2s . c o m List<ReportStatus> reportStatusAsList = new ArrayList<ReportStatus>(); String finishFieldNumber = getFinishFieldNumberForSchemaTypeAndReportYear(schemaTypeName, reportYear); for (OrganisationUnitForBrowsing orgForBrowse : orgUnitsForBrodwsing) { Report report = service.getReport(orgForBrowse.getOrganisationUnitId(), schemaTypeName, reportYear, false); reportStatusAsList.add(createReportStatus(orgForBrowse, report, finishFieldNumber)); } stopWatch.stop(); logger.info("Finish prosessing of reportStatus for schemaType:" + schemaTypeName + " with " + orgUnitsForBrodwsing.size() + " elements in " + stopWatch.getTotalTimeMillis() + " ms"); return reportStatusAsList.toArray(new ReportStatus[reportStatusAsList.size()]); }