Package net.sf.ehcache

Examples of net.sf.ehcache.Statistics


    if (cache != null) {
      System.out.printf(" cache= %s%n", cache.toString());
      System.out.printf(" cache.size= %d%n", cache.getSize());
      System.out.printf(" cache.memorySize= %d%n", cache.getMemoryStoreSize());
      Statistics stats = cache.getStatistics();
      System.out.printf(" stats= %s%n", stats.toString());
    }
  }
View Full Code Here


      for (final String cacheName : this.cacheManager.getCacheNames()) {
          final Cache cache = this.cacheManager.getCache(cacheName);
         
          if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
              final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
              final Statistics statistics = cache.getStatistics();
             
              final CacheStatistics cacheStatistics = new CacheStatistics();
             
              cacheStatistics.hits = statistics.getCacheHits();
              cacheStatistics.misses = statistics.getCacheMisses();
              cacheStatistics.size = statistics.getObjectCount();
              cacheStatistics.maxSize = cacheConfiguration.getMaxElementsInMemory() + cacheConfiguration.getMaxElementsOnDisk();
             
              allCacheStatistics.put(cacheName, cacheStatistics);
          }
      }
View Full Code Here

   * @return the {@link Statistics} for the specified cache; returns null of cache is not alive or doesn't exist
   */
  public Statistics getCacheStatistics(String cacheName) {
    Cache cache = this.cacheManager.getCache(cacheName);
    if(null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
      Statistics result = cache.getStatistics();
      return result;
    }

    return null;
  }
View Full Code Here

                java.util.Arrays.sort(ehcacheNames);
                for (String ehcacheName : ehcacheNames) {
                    net.sf.ehcache.Cache ehcache = ehcacheManager.getCache(ehcacheName);
                    strOut.append(ehcacheName).append(": ");
                    if (ehcache.isStatisticsEnabled()) {
                        Statistics ehcacheStats = ehcache.getStatistics();
                        String efficiencyStr = "0";
                        if (ehcacheStats.getCacheHits() + ehcacheStats.getCacheMisses() > 0) {
                            efficiencyStr = percentFormat.format(ehcacheStats.getCacheHits() * 100f / (ehcacheStats.getCacheHits() + ehcacheStats.getCacheMisses()));
                        }
                        strOut.append("size=" + ehcacheStats.getObjectCount()
                                + ", successful hits=" + ehcacheStats.getCacheHits()
                                + ", total hits="
                                + (ehcacheStats.getCacheHits() + ehcacheStats.getCacheMisses())
                                + ", efficiency=" + efficiencyStr + "%");
                    } else {
                        strOut.append("statistics disabled");
                    }
                    strOut.println();
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 = (CalculatedState)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

    return removeWithChildren(RepositoryItemUid.PATH_ROOT);
  }

  @Override
  public CacheStatistics getStatistics() {
    Statistics stats = getEHCache().getStatistics();

    return new CacheStatistics(stats.getObjectCount(), stats.getCacheMisses(), stats.getCacheHits());
  }
View Full Code Here

        LinkedHashMap<String,String> result = new LinkedHashMap<String, String>();
        for(String cacheName : cachingService.getCacheNames()) {
            Ehcache cache = cachingService.getCacheByName(cacheName);
            if(cache != null) {
                Statistics stat = cache.getStatistics();

                result.put(cacheName + " hits",""+stat.getCacheHits());
                result.put(cacheName + " misses",""+stat.getCacheMisses());
                result.put(cacheName + " size",""+stat.getObjectCount());
            } else {
                log.warn("cache with name {} does not exist",cacheName);
            }
        }
        return result;
View Full Code Here

      for (final String cacheName : this.cacheManager.getCacheNames()) {
          final Cache cache = this.cacheManager.getCache(cacheName);
         
          if (null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
              final CacheConfiguration cacheConfiguration = cache.getCacheConfiguration();
              final Statistics statistics = cache.getStatistics();
             
              final CacheStatistics cacheStatistics = new CacheStatistics();
             
              cacheStatistics.hits = statistics.getCacheHits();
              cacheStatistics.misses = statistics.getCacheMisses();
              cacheStatistics.size = statistics.getObjectCount();
              cacheStatistics.maxSize = cacheConfiguration.getMaxElementsInMemory() + cacheConfiguration.getMaxElementsOnDisk();
             
              allCacheStatistics.put(cacheName, cacheStatistics);
          }
      }
View Full Code Here

   * @return the {@link Statistics} for the specified cache; returns null of cache is not alive or doesn't exist
   */
  public Statistics getCacheStatistics(String cacheName) {
    Cache cache = this.cacheManager.getCache(cacheName);
    if(null != cache && Status.STATUS_ALIVE.equals(cache.getStatus())) {
      Statistics result = cache.getStatistics();
      return result;
    }

    return null;
  }
View Full Code Here

  /**
   * Returns the Cache statistics.
   */
  public Properties getStatistics() {
    Properties props = new Properties();
    Statistics stats = delegate.getStatistics();
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_AverageGetTime, stats.getAverageGetTime() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_AverageSearchTime, stats.getAverageSearchTime() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_CacheHits, stats.getCacheHits() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_CacheMisses, stats.getCacheMisses() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_DiskStoreObjectCount, stats.getDiskStoreObjectCount() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_EvictionCount, stats.getEvictionCount() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_InMemoryHits, stats.getInMemoryHits() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_InMemoryMisses, stats.getInMemoryMisses() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_MemoryStoreObjectCount, stats.getMemoryStoreObjectCount() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_ObjectCount, stats.getObjectCount() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_OffHeapHits, stats.getOffHeapHits() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_OffHeapMisses, stats.getOffHeapMisses() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_OffHeapStoreObjectCount, stats.getOffHeapStoreObjectCount() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_OnDiskHits, stats.getOnDiskHits() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_OnDiskMisses, stats.getOnDiskMisses() + "");
    props.setProperty(CacheStatisticsConstats.KEY_CACHE_STATS_SearchesPerSecond, stats.getSearchesPerSecond() + "");
    return props;
  }
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.