Java 类org.springframework.boot.actuate.cache.CacheStatistics 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CachePublicMetrics.java   
private void addMetrics(Collection<Metric<?>> metrics, String cacheName,
        List<CacheManagerBean> cacheManagerBeans) {
    for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
        CacheManager cacheManager = cacheManagerBean.getCacheManager();
        Cache cache = cacheManager.getCache(cacheName);
        CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
        if (statistics != null) {
            String prefix = cacheName;
            if (cacheManagerBeans.size() > 1) {
                prefix = cacheManagerBean.getBeanName() + "_" + prefix;
            }
            prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
            metrics.addAll(statistics.toMetrics(prefix));
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CachePublicMetrics.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
private CacheStatistics getCacheStatistics(Cache cache, CacheManager cacheManager) {
    if (this.statisticsProviders != null) {
        for (CacheStatisticsProvider provider : this.statisticsProviders) {
            Class<?> cacheType = ResolvableType
                    .forClass(CacheStatisticsProvider.class, provider.getClass())
                    .resolveGeneric();
            if (cacheType.isInstance(cache)) {
                CacheStatistics statistics = provider.getCacheStatistics(cacheManager,
                        cache);
                if (statistics != null) {
                    return statistics;
                }
            }
        }
    }
    return null;
}
项目:spring-boot-concourse    文件:CachePublicMetrics.java   
private void addMetrics(Collection<Metric<?>> metrics, String cacheName,
        List<CacheManagerBean> cacheManagerBeans) {
    for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
        CacheManager cacheManager = cacheManagerBean.getCacheManager();
        Cache cache = cacheManager.getCache(cacheName);
        CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
        if (statistics != null) {
            String prefix = cacheName;
            if (cacheManagerBeans.size() > 1) {
                prefix = cacheManagerBean.getBeanName() + "_" + prefix;
            }
            prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
            metrics.addAll(statistics.toMetrics(prefix));
        }
    }
}
项目:spring-boot-concourse    文件:CachePublicMetrics.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
private CacheStatistics getCacheStatistics(Cache cache, CacheManager cacheManager) {
    if (this.statisticsProviders != null) {
        for (CacheStatisticsProvider provider : this.statisticsProviders) {
            Class<?> cacheType = ResolvableType
                    .forClass(CacheStatisticsProvider.class, provider.getClass())
                    .resolveGeneric();
            if (cacheType.isInstance(cache)) {
                CacheStatistics statistics = provider.getCacheStatistics(cacheManager,
                        cache);
                if (statistics != null) {
                    return statistics;
                }
            }
        }
    }
    return null;
}
项目:contestparser    文件:CachePublicMetrics.java   
private void addMetrics(Collection<Metric<?>> metrics, String cacheName,
        List<CacheManagerBean> cacheManagerBeans) {
    for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
        CacheManager cacheManager = cacheManagerBean.getCacheManager();
        Cache cache = cacheManager.getCache(cacheName);
        CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
        if (statistics != null) {
            String prefix = cacheName;
            if (cacheManagerBeans.size() > 1) {
                prefix = cacheManagerBean.getBeanName() + "_" + prefix;
            }
            prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
            metrics.addAll(statistics.toMetrics(prefix));
        }
    }
}
项目:contestparser    文件:CachePublicMetrics.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
private CacheStatistics getCacheStatistics(Cache cache, CacheManager cacheManager) {
    if (this.statisticsProviders != null) {
        for (CacheStatisticsProvider provider : this.statisticsProviders) {
            Class<?> cacheType = ResolvableType
                    .forClass(CacheStatisticsProvider.class, provider.getClass())
                    .resolveGeneric();
            if (cacheType.isInstance(cache)) {
                CacheStatistics statistics = provider.getCacheStatistics(cacheManager,
                        cache);
                if (statistics != null) {
                    return statistics;
                }
            }
        }
    }
    return null;
}
项目:JRediClients    文件:RedissonCacheStatisticsProvider.java   
@Override
public CacheStatistics getCacheStatistics(final CacheManager cacheManager, final RedissonCache cache) {
    final DefaultCacheStatistics defaultCacheStatistics = new DefaultCacheStatistics();
    defaultCacheStatistics.setSize((long) cache.getNativeCache().size());
    defaultCacheStatistics.setGetCacheCounts(cache.getCacheHits(), cache.getCacheMisses());
    return defaultCacheStatistics;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CacheStatisticsAutoConfiguration.java   
@Bean
public CacheStatisticsProvider<Cache> noOpCacheStatisticsProvider() {
    return new CacheStatisticsProvider<Cache>() {
        @Override
        public CacheStatistics getCacheStatistics(CacheManager cacheManager,
                Cache cache) {
            if (cacheManager instanceof NoOpCacheManager) {
                return NO_OP_STATS;
            }
            return null;
        }
    };
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CacheStatisticsAutoConfigurationTests.java   
@Test
public void concurrentMapCacheStatistics() {
    load(ConcurrentMapConfig.class);
    CacheStatisticsProvider provider = this.context.getBean(
            "concurrentMapCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, 0L, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, 2L, null, null);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CacheStatisticsAutoConfigurationTests.java   
@Test
public void noOpCacheStatistics() {
    load(NoOpCacheConfig.class);
    CacheStatisticsProvider provider = this.context
            .getBean("noOpCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, null, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, null, null, null);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CacheStatisticsAutoConfigurationTests.java   
private void doTestCoreStatistics(CacheStatisticsProvider provider,
        boolean supportSize) {
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, (supportSize ? 0L : null), null, null);
    getOrCreate(books, "a", "b", "b", "a", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, (supportSize ? 2L : null), 0.66D,
            0.33D);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:CacheStatisticsAutoConfigurationTests.java   
private void assertCoreStatistics(CacheStatistics metrics, Long size, Double hitRatio,
        Double missRatio) {
    assertThat(metrics).isNotNull();
    assertThat(metrics.getSize()).isEqualTo(size);
    checkRatio("Wrong hit ratio for metrics " + metrics, hitRatio,
            metrics.getHitRatio());
    checkRatio("Wrong miss ratio for metrics " + metrics, missRatio,
            metrics.getMissRatio());
}
项目:spring-boot-concourse    文件:CacheStatisticsAutoConfiguration.java   
@Bean
public CacheStatisticsProvider<Cache> noOpCacheStatisticsProvider() {
    return new CacheStatisticsProvider<Cache>() {
        @Override
        public CacheStatistics getCacheStatistics(CacheManager cacheManager,
                Cache cache) {
            if (cacheManager instanceof NoOpCacheManager) {
                return NO_OP_STATS;
            }
            return null;
        }
    };
}
项目:spring-boot-concourse    文件:CacheStatisticsAutoConfigurationTests.java   
@Test
public void concurrentMapCacheStatistics() {
    load(ConcurrentMapConfig.class);
    CacheStatisticsProvider provider = this.context.getBean(
            "concurrentMapCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, 0L, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, 2L, null, null);
}
项目:spring-boot-concourse    文件:CacheStatisticsAutoConfigurationTests.java   
@Test
public void noOpCacheStatistics() {
    load(NoOpCacheConfig.class);
    CacheStatisticsProvider provider = this.context
            .getBean("noOpCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, null, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, null, null, null);
}
项目:spring-boot-concourse    文件:CacheStatisticsAutoConfigurationTests.java   
private void doTestCoreStatistics(CacheStatisticsProvider provider,
        boolean supportSize) {
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, (supportSize ? 0L : null), null, null);
    getOrCreate(books, "a", "b", "b", "a", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, (supportSize ? 2L : null), 0.66D,
            0.33D);
}
项目:spring-boot-concourse    文件:CacheStatisticsAutoConfigurationTests.java   
private void assertCoreStatistics(CacheStatistics metrics, Long size, Double hitRatio,
        Double missRatio) {
    assertThat(metrics).isNotNull();
    assertThat(metrics.getSize()).isEqualTo(size);
    checkRatio("Wrong hit ratio for metrics " + metrics, hitRatio,
            metrics.getHitRatio());
    checkRatio("Wrong miss ratio for metrics " + metrics, missRatio,
            metrics.getMissRatio());
}
项目:xlator    文件:RedisCacheStatisticsProvider.java   
@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, RedisCache cache) {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    // @see http://redis.io/commands/INFO
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        Properties props = connection.info();
        Long hitCount = Long.parseLong(props.getProperty("keyspace_hits"));
        Long missCount = Long.parseLong(props.getProperty("keyspace_misses"));
        statistics.setGetCacheCounts(hitCount, missCount);
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
    return statistics;
}
项目:contestparser    文件:CacheStatisticsAutoConfiguration.java   
@Bean
public CacheStatisticsProvider<Cache> noOpCacheStatisticsProvider() {
    return new CacheStatisticsProvider<Cache>() {
        @Override
        public CacheStatistics getCacheStatistics(CacheManager cacheManager,
                Cache cache) {
            if (cacheManager instanceof NoOpCacheManager) {
                return NO_OP_STATS;
            }
            return null;
        }
    };
}
项目:contestparser    文件:CacheStatisticsAutoConfigurationTests.java   
@Test
public void concurrentMapCacheStatistics() {
    load(ConcurrentMapConfig.class);
    CacheStatisticsProvider provider = this.context.getBean(
            "concurrentMapCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, 0L, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, 2L, null, null);
}
项目:contestparser    文件:CacheStatisticsAutoConfigurationTests.java   
@Test
public void noOpCacheStatistics() {
    load(NoOpCacheConfig.class);
    CacheStatisticsProvider provider = this.context
            .getBean("noOpCacheStatisticsProvider", CacheStatisticsProvider.class);
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, null, null, null);
    getOrCreate(books, "a", "b", "b", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, null, null, null);
}
项目:contestparser    文件:CacheStatisticsAutoConfigurationTests.java   
private void doTestCoreStatistics(CacheStatisticsProvider provider,
        boolean supportSize) {
    Cache books = getCache("books");
    CacheStatistics cacheStatistics = provider.getCacheStatistics(this.cacheManager,
            books);
    assertCoreStatistics(cacheStatistics, (supportSize ? 0L : null), null, null);
    getOrCreate(books, "a", "b", "b", "a", "a", "a");
    CacheStatistics updatedCacheStatistics = provider
            .getCacheStatistics(this.cacheManager, books);
    assertCoreStatistics(updatedCacheStatistics, (supportSize ? 2L : null), 0.66D,
            0.33D);
}
项目:contestparser    文件:CacheStatisticsAutoConfigurationTests.java   
private void assertCoreStatistics(CacheStatistics metrics, Long size, Double hitRatio,
        Double missRatio) {
    assertNotNull("Cache metrics must not be null", metrics);
    assertEquals("Wrong size for metrics " + metrics, size, metrics.getSize());
    checkRatio("Wrong hit ratio for metrics " + metrics, hitRatio,
            metrics.getHitRatio());
    checkRatio("Wrong miss ratio for metrics " + metrics, missRatio,
            metrics.getMissRatio());
}