Package net.sf.ehcache

Examples of net.sf.ehcache.Statistics


    protected static String generateCacheStats(Ehcache cache) {
        StringBuilder sb = new StringBuilder();
        sb.append(cache.getName()).append(":");
        // this will make this costly but it is important to get accurate settings
        cache.setStatisticsAccuracy(Statistics.STATISTICS_ACCURACY_GUARANTEED);
        Statistics stats = cache.getStatistics();
        final long memSize = cache.getMemoryStoreSize();
        final long diskSize = cache.getDiskStoreSize();
        final long size = memSize + diskSize;
        final long hits = stats.getCacheHits();
        final long misses = stats.getCacheMisses();
        final String hitPercentage = ((hits+misses) > 0) ? ((100l * hits) / (hits + misses)) + "%" : "N/A";
        final String missPercentage = ((hits+misses) > 0) ? ((100l * misses) / (hits + misses)) + "%" : "N/A";
        sb.append("  Size: ").append(size).append(" [memory:").append(memSize).append(", disk:").append(diskSize).append("]");
        sb.append(",  Hits: ").append(hits).append(" [memory:").append(stats.getInMemoryHits()).append(", disk:").append(stats.getOnDiskHits()).append("] (").append(hitPercentage).append(")");
        sb.append(",  Misses: ").append(misses).append(" (").append(missPercentage).append(")");
        return sb.toString();
    }
View Full Code Here


  public void setCache(Cache cache) {
    _cache = cache;
  }

  public long getNumberOfActiveUsers() {
    Statistics stats = _cache.getStatistics();
    return stats.getObjectCount();
  }
View Full Code Here

   
    protected CacheMonitorState snapshotAndCalculateStatistics(String name, boolean calculate)
    {
        Cache cache = cacheManager.getCache(name);       
        CacheMonitorStateImpl state = new CacheMonitorStateImpl(name);
        Statistics statistics = cache.getStatistics();       
        state.setMemoryStoreSize(cache.getMemoryStoreSize());
        if (calculate)
        {
            state.setInMemorySize(cache.calculateInMemorySize());
            if (calculateObjectCount)
            {
                state.setObjectCount(statistics.getObjectCount());
            }
            else
            {
                state.setObjectCount(0);
            }
            calculatedStates.put(name, new CalculatedState(state.getInMemorySize(), state.getObjectCount()));
        }
        else
        {
            CalculatedState cs = calculatedStates.get(name);
            if (cs == null)
            {
                state.setInMemorySize(0);               
                state.setObjectCount(0);
            }
            else
            {
                state.setInMemorySize(cs.inMemorySize);
                state.setObjectCount(cs.objectCount);
            }           
        }
        state.setSize(cache.getSize());
        state.setDiskStoreSize(cache.getDiskStoreSize());
        state.setAverageGetTime(statistics.getAverageGetTime());
        state.setCacheHits(statistics.getCacheHits());
        state.setCacheMisses(statistics.getCacheMisses());
        state.setEvictionCount(statistics.getEvictionCount());
        state.setInMemoryHits(statistics.getInMemoryHits());
        state.setOnDiskHits(statistics.getOnDiskHits());
        state.setMaxElementsInMemory(cache.getCacheConfiguration().getMaxElementsInMemory());
        state.setMaxElementsOnDisk(cache.getCacheConfiguration().getMaxElementsOnDisk());           
        state.setTimeToIdle(cache.getCacheConfiguration().getTimeToIdleSeconds());
        state.setTimeToLive(cache.getCacheConfiguration().getTimeToLiveSeconds());
        return state;
View Full Code Here

    statsThread.start();
    return stats;
  }

  private void report(final Cache cache) {
    final Statistics stats = cache.getStatistics();
    final long hits = stats.getCacheHits();
    final long misses = stats.getCacheMisses();
    final double ratio = (misses != 0) ? (double) hits / (double) misses : 0d;
    _logger.info("Cache {} hits = {}, misses = {}, ratio = {}", new Object[] {cache.getName(), hits, misses, ratio});
  }
View Full Code Here

TOP

Related Classes of net.sf.ehcache.Statistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.