本文整理汇总了Java中javax.cache.configuration.MutableConfiguration.setStatisticsEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java MutableConfiguration.setStatisticsEnabled方法的具体用法?Java MutableConfiguration.setStatisticsEnabled怎么用?Java MutableConfiguration.setStatisticsEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.cache.configuration.MutableConfiguration
的用法示例。
在下文中一共展示了MutableConfiguration.setStatisticsEnabled方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrCreateCacheConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
Configuration getOrCreateCacheConfiguration() {
if (configuration.getCacheConfiguration() != null) {
return configuration.getCacheConfiguration();
}
MutableConfiguration mutableConfiguration = new MutableConfiguration();
if (configuration.getCacheLoaderFactory() != null) {
mutableConfiguration.setCacheLoaderFactory(configuration.getCacheLoaderFactory());
}
if (configuration.getCacheWriterFactory() != null) {
mutableConfiguration.setCacheWriterFactory(configuration.getCacheWriterFactory());
}
if (configuration.getExpiryPolicyFactory() != null) {
mutableConfiguration.setExpiryPolicyFactory(configuration.getExpiryPolicyFactory());
}
mutableConfiguration.setManagementEnabled(configuration.isManagementEnabled());
mutableConfiguration.setStatisticsEnabled(configuration.isStatisticsEnabled());
mutableConfiguration.setReadThrough(configuration.isReadThrough());
mutableConfiguration.setStoreByValue(configuration.isStoreByValue());
return mutableConfiguration;
}
示例2: testManagementDisabledOverriddenFromTemplate
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testManagementDisabledOverriddenFromTemplate() throws Exception {
CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-template-config.xml")
.toURI(),
provider.getDefaultClassLoader());
MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
configuration.setTypes(Long.class, String.class);
configuration.setManagementEnabled(false);
configuration.setStatisticsEnabled(false);
Cache<Long, String> cache = cacheManager.createCache("enables-mbeans", configuration);
@SuppressWarnings("unchecked")
Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);
assertThat(eh107Configuration.isManagementEnabled(), is(true));
assertThat(eh107Configuration.isStatisticsEnabled(), is(true));
assertThat(isMbeanRegistered("enables-mbeans", MBEAN_MANAGEMENT_TYPE), is(true));
assertThat(isMbeanRegistered("enables-mbeans", MBEAN_STATISTICS_TYPE), is(true));
}
示例3: testManagementEnabledOverriddenFromTemplate
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testManagementEnabledOverriddenFromTemplate() throws Exception {
CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-template-config.xml")
.toURI(),
provider.getDefaultClassLoader());
MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
configuration.setTypes(Long.class, String.class);
configuration.setManagementEnabled(true);
configuration.setStatisticsEnabled(true);
Cache<Long, String> cache = cacheManager.createCache("disables-mbeans", configuration);
@SuppressWarnings("unchecked")
Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);
assertThat(eh107Configuration.isManagementEnabled(), is(false));
assertThat(eh107Configuration.isStatisticsEnabled(), is(false));
assertThat(isMbeanRegistered("disables-mbeans", MBEAN_MANAGEMENT_TYPE), is(false));
assertThat(isMbeanRegistered("disables-mbeans", MBEAN_STATISTICS_TYPE), is(false));
}
示例4: basicJsr107StillWorks
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void basicJsr107StillWorks() throws Exception {
CacheManager cacheManager = provider.getCacheManager();
MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
configuration.setTypes(Long.class, String.class);
configuration.setManagementEnabled(true);
configuration.setStatisticsEnabled(true);
Cache<Long, String> cache = cacheManager.createCache("cache", configuration);
@SuppressWarnings("unchecked")
Eh107Configuration eh107Configuration = cache.getConfiguration(Eh107Configuration.class);
assertThat(eh107Configuration.isManagementEnabled(), is(true));
assertThat(eh107Configuration.isStatisticsEnabled(), is(true));
assertThat(isMbeanRegistered("cache", MBEAN_MANAGEMENT_TYPE), is(true));
assertThat(isMbeanRegistered("cache", MBEAN_STATISTICS_TYPE), is(true));
}
示例5: produces
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Produces
@CustomCache
public Cache<Integer, Person> produces() {
CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<Integer, Person> cache = manager.getCache(CACHE_NAME, Integer.class, Person.class);
if(cache == null) {
MutableConfiguration<Integer, Person> configuration = new MutableConfiguration<>();
configuration.setTypes(Integer.class, Person.class);
configuration.setStatisticsEnabled(true);
cache = manager.createCache(CACHE_NAME, configuration);
CacheEntryListenerConfiguration<Integer, Person> listenersConfiguration
= new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(CacheModificationListener.class), null, false, true);
cache.registerCacheEntryListener(listenersConfiguration);
}
return cache;
}
示例6: testCacheStatisticsOffThenOnThenOff
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testCacheStatisticsOffThenOnThenOff() throws Exception {
MutableConfiguration configuration = new MutableConfiguration();
configuration.setStatisticsEnabled(false);
cacheManager.createCache("cache1", configuration);
cacheManager.createCache("cache2", configuration);
Set<? extends ObjectName> names = mBeanServer.queryNames(new ObjectName("javax.cache:*"), null);
Assert.assertTrue(names.size() == 0);
configuration.setStatisticsEnabled(true);
cacheManager.createCache("cache3", configuration);
cacheManager.createCache("cache4", configuration);
assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
cacheManager.enableStatistics("cache3", false);
assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(1));
cacheManager.enableStatistics("cache3", true);
assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
}
示例7: testExpiryOnCreation
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
public void testExpiryOnCreation() throws Exception {
// close cache since need to configure cache with ExpireOnCreationPolicy
CacheManager mgr = cache.getCacheManager();
mgr.destroyCache(cache.getName());
MutableConfiguration<Long, String> config = new MutableConfiguration<Long, String>();
config.setStatisticsEnabled(true);
config.setTypes(Long.class, String.class);
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnCreationPolicy.class));
cache = mgr.createCache(getTestCacheName(), config);
cache.put(1L, "hello");
assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
Map<Long, String> map = new HashMap<Long, String>();
map.put(2L, "goodbye");
map.put(3L, "world");
cache.putAll(map);
assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
}
示例8: createCacheConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Prep cache configuration.
*
* @param expiryDuration the expiry duration
* @return the mutable configuration
*/
protected static MutableConfiguration<String, Map<String, Object>> createCacheConfiguration(final Duration expiryDuration) {
final MutableConfiguration<String, Map<String, Object>> config = new MutableConfiguration<>();
config.setStatisticsEnabled(true);
config.setManagementEnabled(true);
config.setStoreByValue(true);
config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(expiryDuration));
return config;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:CachingPrincipalAttributesRepository.java
示例9: jCacheCacheManager
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Bean
public javax.cache.CacheManager jCacheCacheManager() {
javax.cache.CacheManager cacheManager = Caching
.getCachingProvider(HazelcastCachingProvider.class.getName())
.getCacheManager();
MutableConfiguration<Object, Object> config = new MutableConfiguration<Object, Object>();
config.setStatisticsEnabled(true);
cacheManager.createCache("books", config);
cacheManager.createCache("speakers", config);
return cacheManager;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:CacheStatisticsAutoConfigurationTests.java
示例10: myCustomizer
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Bean
JCacheManagerCustomizer myCustomizer() {
return new JCacheManagerCustomizer() {
@Override
public void customize(javax.cache.CacheManager cacheManager) {
MutableConfiguration<?, ?> config = new MutableConfiguration<Object, Object>();
config.setExpiryPolicyFactory(
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
config.setStatisticsEnabled(true);
cacheManager.createCache("custom1", config);
cacheManager.destroyCache("bar");
}
};
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:CacheAutoConfigurationTests.java
示例11: getConfiguration
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <C extends Configuration<K, V>> C getConfiguration(Class<C> _class) {
if (CompleteConfiguration.class.isAssignableFrom(_class)) {
MutableConfiguration<K, V> cfg = new MutableConfiguration<K, V>();
cfg.setTypes(keyType, valueType);
cfg.setStatisticsEnabled(jmxStatisticsEnabled);
cfg.setManagementEnabled(jmxEnabled);
cfg.setStoreByValue(storeByValue);
Collection<CacheEntryListenerConfiguration<K,V>> _listenerConfigurations = eventHandling.getAllListenerConfigurations();
for (CacheEntryListenerConfiguration<K,V> _listenerConfig : _listenerConfigurations) {
cfg.addCacheEntryListenerConfiguration(_listenerConfig);
}
return (C) cfg;
}
return (C) new Configuration<K, V>() {
@Override
public Class<K> getKeyType() {
return keyType;
}
@Override
public Class<V> getValueType() {
return valueType;
}
@Override
public boolean isStoreByValue() {
return storeByValue;
}
};
}
示例12: testCacheStatisticsBean
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
@Test
@Repeat(times = 2)
public void testCacheStatisticsBean()
throws Exception
{
try (CachingProvider cachingProvider = Caching.getCachingProvider(GuavaCachingProvider.class.getName()))
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, Integer> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setTypes(String.class, Integer.class);
configuration.setStatisticsEnabled(true);
Cache<String, Integer> statisticsCache = cacheManager.createCache("statisticsCache", configuration);
statisticsCache.put("entry1", 1);
statisticsCache.put("entry2", 2);
statisticsCache.put("entry3", 3);
statisticsCache.get("entry1");
statisticsCache.get("entry2");
statisticsCache.get("entry3");
statisticsCache.get("entry4");
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
assertNotNull(beanServer);
ObjectName name = new ObjectName(GuavaCacheStatisticsMXBean.getObjectName(statisticsCache));
Object cacheHits = beanServer.getAttribute(name, "CacheHits");
Object cacheMisses = beanServer.getAttribute(name, "CacheMisses");
Object cacheHitPercentage = beanServer.getAttribute(name, "CacheHitPercentage");
Object cacheMissPercentage = beanServer.getAttribute(name, "CacheMissPercentage");
assertNotNull(cacheHits);
assertNotNull(cacheMisses);
assertNotNull(cacheHitPercentage);
assertNotNull(cacheMissPercentage);
assertEquals("cache hits", 3L, cacheHits);
assertEquals("cache misses", 1L, cacheMisses);
assertEquals("cache hit percentage", 0.75F, cacheHitPercentage);
assertEquals("cache miss percentage", 0.25F, cacheMissPercentage);
beanServer.invoke(name, "clear", null, null);
cacheHits = beanServer.getAttribute(name, "CacheHits");
cacheMisses = beanServer.getAttribute(name, "CacheMisses");
cacheHitPercentage = beanServer.getAttribute(name, "CacheHitPercentage");
cacheMissPercentage = beanServer.getAttribute(name, "CacheMissPercentage");
assertEquals("cache hits", 0L, cacheHits);
assertEquals("cache misses", 0L, cacheMisses);
assertEquals("cache hit percentage", 1F, cacheHitPercentage);
assertEquals("cache miss percentage", 0F, cacheMissPercentage);
}
}
示例13: expire_whenCreated
import javax.cache.configuration.MutableConfiguration; //导入方法依赖的package包/类
/**
* Ensure that a cache using a {@link javax.cache.expiry.ExpiryPolicy} configured to
* return a {@link Duration#ZERO} for newly created entries will immediately
* expire the entries.
*/
private void expire_whenCreated(Factory<? extends ExpiryPolicy> expiryPolicyFactory) {
MutableConfiguration<Integer, Integer> config = new MutableConfiguration<Integer, Integer>();
config.setTypes(Integer.class, Integer.class);
config.setExpiryPolicyFactory(expiryPolicyFactory);
config = extraSetup(config);
config.setStatisticsEnabled(true);
Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
cache.put(1, 1);
assertFalse(cache.containsKey(1));
assertNull(cache.get(1));
assertEquals(0, listener.getCreated());
cache.put(1, 1);
assertFalse(cache.remove(1));
cache.put(1, 1);
assertFalse(cache.remove(1, 1));
cache.getAndPut(1, 1);
assertEquals(0, listener.getCreated());
assertFalse(cache.containsKey(1));
assertNull(cache.get(1));
cache.putIfAbsent(1, 1);
assertEquals(0, listener.getCreated());
assertFalse(cache.containsKey(1));
assertNull(cache.get(1));
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(1, 1);
cache.putAll(map);
assertEquals(0, listener.getCreated());
assertFalse(cache.containsKey(1));
assertNull(cache.get(1));
cache.put(1, 1);
assertEquals(0, listener.getCreated());
assertFalse(cache.iterator().hasNext());
cache.getAndPut(1, 1);
assertEquals(0, listener.getCreated());
}