Java Code Examples for org.ehcache.core.spi.service.StatisticsService

Following code examples demonstrate how to use org.ehcache.core.spi.service.StatisticsService from ehcache. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.ehcache.core.spi.service.StatisticsService and various code implementation of this class.
Example 1
Project : ehcache Source File : DefaultStatisticsServiceFactory.java View Source Code on GitHub

  public StatisticsService create(ServiceCreationConfiguration<StatisticsService> configuration) {
    if (configuration != null && !(configuration instanceof StatisticsServiceConfiguration)) {
      throw new IllegalArgumentException("Expected a configuration of type StatisticsServiceConfiguration but got " + configuration.getClass().getSimpleName());
    }
    if (configuration == null) {
      configuration = new DefaultStatisticsServiceConfiguration();
    }
    return new DefaultStatisticsService((StatisticsServiceConfiguration) configuration);
  }
			
Example 2
Project : ehcache Source File : StandardEhcacheStatistics.java View Source Code on GitHub

  StandardEhcacheStatistics(ManagementRegistryServiceConfiguration registryConfiguration, CacheBinding cacheBinding, StatisticsService statisticsService, TimeSource timeSource) {
    super(registryConfiguration, cacheBinding);
    this.statisticRegistry = new StatisticRegistry(cacheBinding.getCache(), timeSource::getTimeMillis);

    String cacheName = cacheBinding.getAlias();
    CacheStatistics cacheStatistics = statisticsService.getCacheStatistics(cacheName);
    cacheStatistics.getKnownStatistics().forEach(statisticRegistry::registerStatistic);
  }
			
Example 3
Project : ehcache Source File : DiskStatTest.java View Source Code on GitHub

    public void test() throws IOException {
      StatisticsService statisticsService = new DefaultStatisticsService();

      try(PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
        .with(CacheManagerBuilder.persistence("myData"))
        .using(statisticsService)
        .withCache("threeTieredCache",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
              .heap(10, EntryUnit.ENTRIES)
              .offheap(1, MemoryUnit.MB)
              .disk(20, MemoryUnit.MB, true)
          )
        ).build(true)) {

        Cache<Long, String> cache = persistentCacheManager.getCache("threeTieredCache", Long.class, String.class);
        for(long i = 0; i < 1000; i++) {
          cache.put(i, "test");
        }
        System.out.println("Length: " + getFolderSize("mydata"));
        TierStatistics tierStatistics = statisticsService
          .getCacheStatistics("threeTieredCache")
          .getTierStatistics()
          .get("Disk");
        System.out.println("Occupied: " + tierStatistics.getOccupiedByteSize());
        System.out.println("Allocated: " + tierStatistics.getAllocatedByteSize());
      }
    }
			
Example 4
Project : ehcache Source File : EhCacheFacade.java View Source Code on GitHub

    public EhCacheFacade(Class<K> keyClass, Class<V> valueClass, int maxSize) {
        statisticsService = new DefaultStatisticsService();

        CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
                .using(statisticsService)
                .build();
        cacheManager.init();

        this.cache = cacheManager.createCache(
                "VCache",
                CacheConfigurationBuilder.newCacheConfigurationBuilder(keyClass, valueClass, ResourcePoolsBuilder.heap(maxSize))
        );

    }
			
Example 5
Project : ehcache Source File : OnHeapMain.java View Source Code on GitHub

    public static void main(String[] args) {
        StatisticsService statisticsService = new DefaultStatisticsService();
        CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
                .withCache("preConfigured",
                        CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class,
                                String.class, ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES)))
                .using(statisticsService).build(true);

        Cache<Long, String> aCache = cacheManager.getCache("preConfigured", Long.class, String.class);
        aCache.put(1L, "one");
        aCache.put(0L, "zero");
        aCache.get(1L);
        aCache.get(0L);
        aCache.get(0L);
        aCache.get(0L);
        aCache.get(7L);


        CacheStatistics ehCacheStat = statisticsService.getCacheStatistics("preConfigured");
        System.out.println(ehCacheStat.getCacheHitPercentage());
        System.out.println(ehCacheStat.getCacheGets());

    }