Example usage for org.springframework.util StopWatch StopWatch

List of usage examples for org.springframework.util StopWatch StopWatch

Introduction

In this page you can find the example usage for org.springframework.util StopWatch StopWatch.

Prototype

public StopWatch() 

Source Link

Document

Construct a new StopWatch .

Usage

From source file:org.dd4t.core.filters.impl.DefaultLinkResolverFilter.java

/**
 * Recursively resolves all components links.
 * //w  w  w .java2  s.c o m
 * @param item the to resolve the links
 * @param context the requestContext
 */
@Override
public void doFilter(Item item, RequestContext context) throws FilterException {

    this.getLinkResolver().setContextPath(contextPath);

    StopWatch stopWatch = null;
    if (logger.isDebugEnabled()) {
        stopWatch = new StopWatch();
        stopWatch.start();
    }
    if (item instanceof GenericPage) {
        resolvePage((GenericPage) item);
    } else if (item instanceof GenericComponent) {
        resolveComponent((GenericComponent) item);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "DefaultLinkResolverFilter. Item is not a GenericPage or GenericComponent so no component to resolve");
        }
    }
    if (logger.isDebugEnabled()) {
        stopWatch.stop();
        logger.debug("LinkResolverFilter for " + item.getId() + " finished in " + stopWatch.getTotalTimeMillis()
                + " ms");
    }
}

From source file:de.uniwue.dmir.heatmap.heatmaps.DefaultHeatmap.java

@Override
public TTile getTile(TileCoordinates tileCoordinates) {

    // initializing stop watch
    StopWatch stopWatch = new StopWatch();

    // tile coordinates to top-left reference system
    TileCoordinates projectedTileCoordinates = this.settings.getTileProjection()
            .fromCustomToTopLeft(tileCoordinates, this.settings.getZoomLevelMapper());

    // loading data seed 

    this.logger.debug("Loading data seed.");

    stopWatch.start("loading data seed");

    TTile tile = this.seed.getTile(projectedTileCoordinates);

    stopWatch.stop();/*www.java 2 s  . c o m*/
    if (tile == null) {
        this.logger.debug("No data seed available: {}", stopWatch.toString());
    } else {
        this.logger.debug("Done loading data seed: {}", stopWatch.toString());
    }

    // get data

    this.logger.debug("Loading data points.");

    stopWatch.start("loading data points");

    Iterator<TPoint> externalData = this.pointsource.getPoints(projectedTileCoordinates, this.filter);

    stopWatch.stop();
    this.logger.debug("Done loading data points: {}", stopWatch.toString());

    // return null if no data was found
    if (externalData == null || !externalData.hasNext()) {

        this.logger.debug("No external data found for this tile: {}", tileCoordinates);

        if (tile == null) {

            this.logger.debug("No data seed available for his tile: returnung null.");
            return null;

        } else if (!this.returnSeedTilesWithNoExternalData) {

            this.logger.debug("Data seed available, but no external data found: returning null.");
            return null;
        }

    }

    // initializing tile if no seed is available
    if (tile == null) {
        this.logger.debug("No data seed available; initializing empty tile.");
        tile = this.tileFactory.newInstance(this.settings.getTileSize(), projectedTileCoordinates);
    }

    // add external data to tile

    this.logger.debug("Adding data points to tile: {}", tileCoordinates);

    stopWatch.start("adding data points to tile");

    int externalDataPointCount = 0;
    while (externalData.hasNext()) {
        TPoint externalDataPoint = externalData.next();
        this.filter.filter(externalDataPoint, tile, this.settings.getTileSize(), tileCoordinates);
        externalDataPointCount++;
    }

    stopWatch.stop();
    this.logger.debug("Done adding {} data points to tile: {}", externalDataPointCount, stopWatch.toString());

    return tile;
}

From source file:org.sventon.cache.direntrycache.DirEntryCacheUpdater.java

/**
 * Updates the cache with the given revisions.
 *
 * @param revisionUpdate The updated revisions.
 *///from  www .j  a v  a2  s .co  m
public void update(final RevisionUpdate revisionUpdate) {
    final RepositoryName repositoryName = revisionUpdate.getRepositoryName();

    LOGGER.info("Listener got [" + revisionUpdate.getRevisions().size()
            + "] updated revision(s) for repository: " + repositoryName);

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

    SVNConnection connection = null;

    try {
        final DirEntryCache entryCache = cacheManager.getCache(repositoryName);
        final RepositoryConfiguration configuration = application.getConfiguration(repositoryName);
        connection = connectionFactory.createConnection(repositoryName, configuration.getSVNURL(),
                configuration.getCacheCredentials());
        updateInternal(entryCache, connection, revisionUpdate);
    } catch (final Exception ex) {
        LOGGER.warn("Could not update cache instance [" + repositoryName + "]", ex);
    } finally {
        if (connection != null) {
            connection.closeSession();
        }
    }

    stopWatch.stop();
    LOGGER.info("Update completed in [" + stopWatch.getTotalTimeSeconds() + "] seconds");
}

From source file:com.persistent.cloudninja.scheduler.TenantDBBandwidthProcessor.java

@Override
public boolean execute() {
    boolean retVal = true;
    int tenantDBBWsCount = 0;
    try {/*from ww  w.j  av a 2  s  .c  om*/
        LOGGER.debug("In Processor");
        TenantDBBandwidthQueue queue = (TenantDBBandwidthQueue) getWorkQueue();
        String message = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout);
        if (message == null) {
            retVal = false;
            LOGGER.debug("Processor : msg is null");
        } else {
            StopWatch watch = new StopWatch();
            watch.start();
            LOGGER.debug("Processor : msg is " + message);
            List<DBBandwidthUsageEntity> listDbBandwidthUsageEntities = partitionStatsAndBWUsageDao
                    .getBandwidthUsage();
            tenantDBBWsCount = listDbBandwidthUsageEntities.size();
            Map<String, MeteringEntity> map = new HashMap<String, MeteringEntity>();
            MeteringEntity meteringEntity = null;
            String dbName = null;
            String tenantId = null;

            for (DBBandwidthUsageEntity dbBandwidthUsageEntity : listDbBandwidthUsageEntities) {
                dbName = dbBandwidthUsageEntity.getDatabaseName();

                if (dbName.startsWith("tnt_")) {
                    tenantId = dbName.substring(4);
                    if (map.containsKey(tenantId)) {
                        meteringEntity = map.get(tenantId);
                        setDatabaseBandwidth(dbBandwidthUsageEntity, meteringEntity);
                    } else {
                        meteringEntity = new MeteringEntity();
                        meteringEntity.setTenantId(tenantId);
                        setDatabaseBandwidth(dbBandwidthUsageEntity, meteringEntity);
                        map.put(tenantId, meteringEntity);
                    }
                }
            }

            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String date = dateFormat.format(calendar.getTime());

            for (Iterator<MeteringEntity> iterator = map.values().iterator(); iterator.hasNext();) {
                meteringEntity = (MeteringEntity) iterator.next();
                meteringEntity.setSnapshotTime(dateFormat.parse(date));
                meteringDao.add(meteringEntity);
            }
            LOGGER.info("Processor : DB bandwidth calculated.");
            watch.stop();
            taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                    "ProcessMeteringTenantDBBandwidthUse",
                    "Measured the database bandwith use for " + tenantDBBWsCount + " tenants.");
        }
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    } catch (ParseException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:ch.silviowangler.dox.LoadIntegrationTest.java

@Test
@Ignore("Needs rework since it produces unreliable results")
public void testQuery() throws Exception {

    StopWatch stopWatch = new StopWatch();

    Map<TranslatableKey, DescriptiveIndex> indices = new HashMap<>();

    TranslatableKey company = new TranslatableKey("company");
    indices.put(company, new DescriptiveIndex("3?"));

    stopWatch.start();/*from   w ww. j  ava  2s  . com*/
    Set<DocumentReference> invoices = documentService.findDocumentReferences(indices, "INVOICE");
    stopWatch.stop();

    final long totalTimeMillis = stopWatch.getTotalTimeMillis();
    assertTrue("This test may take only " + TOTAL_AMOUNT_OF_TIME_IN_MILLIS + " ms but took this time "
            + totalTimeMillis + " ms", totalTimeMillis <= TOTAL_AMOUNT_OF_TIME_IN_MILLIS);

    for (DocumentReference documentReference : invoices) {
        String value = documentReference.getIndices().get(company).toString();
        assertTrue("Value is wrong: " + value, value.matches("(3|3\\d)"));
    }
    assertThat(invoices.size(), is(11));
}

From source file:io.github.jhipster.config.liquibase.AsyncSpringLiquibase.java

protected void initDb() throws LiquibaseException {
    StopWatch watch = new StopWatch();
    watch.start();//w w w.j  a  va2  s .c  o  m
    super.afterPropertiesSet();
    watch.stop();
    logger.debug("Liquibase has updated your database in {} ms", watch.getTotalTimeMillis());
    if (watch.getTotalTimeMillis() > 5_000) {
        logger.warn("Warning, Liquibase took more than 5 seconds to start up!");
    }
}

From source file:com.persistent.cloudninja.scheduler.DeploymentMonitor.java

@Override
public boolean execute() {
    boolean retVal = true;
    try {/*from  w  ww  .  ja  va  2  s  .  co m*/
        StopWatch watch = new StopWatch();
        watch.start();
        StringBuffer roleInfo = getRoleInfoForDeployment();
        parseRoleInfo(roleInfo);
        watch.stop();
        taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                "ProcessMonitorInstanceCount", "");
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        retVal = false;
    }
    return retVal;
}

From source file:org.jason.mapmaker.repository.impl.HibernateGenericRepository.java

public void save(Collection<T> objects) {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//ww  w .ja v a 2  s  .co  m

    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    int i = 1;
    for (T obj : objects) {

        session.save(obj);
        //sessionFactory.getCurrentSession().save(obj);
        i++;
        if (i % 100 == 0) {
            session.flush();
            session.clear();
            //sessionFactory.getCurrentSession().flush();
        }
    }

    tx.commit();
    session.close();

    stopWatch.stop();
    log.debug("Persisted " + i + " objects in " + stopWatch.getTotalTimeSeconds() + " seconds");

}

From source file:org.olegz.uuid.TimeBasedUUIDGeneratorTests.java

@Test
public void performanceTestAsynch() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(100);
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from  w  w  w.  ja  va2  s  . c  om*/
    for (int i = 0; i < 1000000; i++) {
        executor.execute(new Runnable() {
            public void run() {
                TimeBasedUUIDGenerator.generateId();
            }
        });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (async) via TimeBasedUUIDGenerator.generateId(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");

    executor = Executors.newFixedThreadPool(100);
    stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 1000000; i++) {
        executor.execute(new Runnable() {
            public void run() {
                UUID.randomUUID();
            }
        });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (async) via UUID.randomUUID(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");
}