public void setManagementEnabled(boolean enabled) { delegate.setManagementEnabled(enabled); }
public void setManagementEnabled(boolean enabled) { delegate.setManagementEnabled(enabled); }
/** See {@link MutableConfiguration#setManagementEnabled}. */ public void setManagementEnabled(boolean enabled) { delegate.setManagementEnabled(enabled); }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setManagementEnabled(boolean enabled) { super.setManagementEnabled(enabled); return this; }
private MutableConfiguration<Object, Object> config() { return new MutableConfiguration<>().setStoreByValue(false) .setManagementEnabled(true).setStatisticsEnabled(true); }
@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)); }
@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)); }
@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<Long, String> 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)); } }
public JCache(URL url) { String method = url.getParameter(Constants.METHOD_KEY, ""); String key = url.getAddress() + "." + url.getServiceKey() + "." + method; // jcache parameter is the full-qualified class name of SPI implementation String type = url.getParameter("jcache"); CachingProvider provider = StringUtils.isEmpty(type) ? Caching.getCachingProvider() : Caching.getCachingProvider(type); CacheManager cacheManager = provider.getCacheManager(); Cache<Object, Object> cache = cacheManager.getCache(key); if (cache == null) { try { //configure the cache MutableConfiguration config = new MutableConfiguration<Object, Object>() .setTypes(Object.class, Object.class) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000)))) .setStoreByValue(false) .setManagementEnabled(true) .setStatisticsEnabled(true); cache = cacheManager.createCache(key, config); } catch (CacheException e) { // concurrent cache initialization cache = cacheManager.getCache(key); } } this.store = cache; }
public JCache(URL url) { String method = url.getParameter(Constants.METHOD_KEY, ""); String key = url.getAddress() + "." + url.getServiceKey() + "." + method; // jcache parameter is the full-qualified class name of SPI implementation String type = url.getParameter("jcache"); CachingProvider provider = StringUtils.isEmpty(type) ? Caching.getCachingProvider() : Caching.getCachingProvider(type); CacheManager cacheManager = provider.getCacheManager(); Cache<Object, Object> cache = cacheManager.getCache(key); if (cache == null) { try { //configure the cache MutableConfiguration config = new MutableConfiguration<Object, Object>() .setTypes(Object.class, Object.class) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000)))) .setStoreByValue(false) .setManagementEnabled(true) .setStatisticsEnabled(true); cache = cacheManager.createCache(key, config); } catch (CacheException e) { // concurrent cache initialization cache = cacheManager.getCache(key); } } this.store = cache; }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setManagementEnabled(boolean enabled) { super.setManagementEnabled(enabled); return this; }
/** See {@link MutableConfiguration#setManagementEnabled}. */ public void setManagementEnabled(boolean enabled) { delegate.setManagementEnabled(enabled); }
public void setManagementEnabled(boolean enabled) { delegate.setManagementEnabled(enabled); }
private CacheResolver doGetCacheResolver(final CacheMethodDetails<? extends Annotation> cacheMethodDetails, final String cacheName, final String repoName) { if ((tribestream.isUseJcacheOnRepositories() && ("*".equals(tribestream.getCachedRepositories()) || Stream.of(tribestream.getCachedRepositories().split(",")) .map(s -> s.toLowerCase(ENGLISH)) .anyMatch(n -> repoName.toLowerCase(ENGLISH).startsWith(n)))) || !Repository.class.isAssignableFrom(cacheMethodDetails.getMethod().getDeclaringClass())) { return findCacheResolver(cacheName, cacheMethodDetails); } // cache not caching cache => always read final ClassLoader classLoader = ConfigurableCacheResolverFactory.class.getClassLoader(); final Cache<?, ?> cache = Cache.class.cast(Proxy.newProxyInstance( classLoader, cacheApi, new EmptyCacheHandler(cacheName, new MutableConfiguration() .setStoreByValue(false) .setManagementEnabled(false) .setStatisticsEnabled(false)))); return new CacheResolver() { @Override public <K, V> Cache<K, V> resolveCache(final CacheInvocationContext<? extends Annotation> cacheInvocationContext) { return (Cache<K, V>) cache; } }; }
public static <K, V> MutableConfiguration<K, V> createCacheConfig( @Nullable final Class<K> keyType, @Nullable final Class<V> valueType, final Factory<? extends ExpiryPolicy> expiryPolicyFactory) { MutableConfiguration<K, V> config = new MutableConfiguration<K, V>() .setStoreByValue(false) .setExpiryPolicyFactory(expiryPolicyFactory) .setManagementEnabled(true) .setStatisticsEnabled(true); if (keyType != null && valueType != null) { config.setTypes(keyType, valueType); } return config; }
private <T> MutableConfiguration<String, T> configure(final MutableConfiguration<String, T> configuration, final OAuth2Options opts) { ofNullable(opts.getJcacheLoader()) .map(n -> lookup(CacheLoader.class, n)) .ifPresent(l -> configuration.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<CacheLoader<String, T>>(l))); ofNullable(opts.getJcacheWriter()) .map(n -> lookup(CacheWriter.class, n)) .ifPresent(w -> configuration.setCacheWriterFactory(new FactoryBuilder.SingletonFactory<CacheWriter<String, T>>(w))); return configuration .setStoreByValue(opts.isJcacheStoreValue()) .setStatisticsEnabled(opts.isJcacheStatistics()) .setManagementEnabled(opts.isJcacheJmx()); }
@Test public void testCacheManagementOffThenOnThenOff() throws Exception { MutableConfiguration configuration = new MutableConfiguration(); configuration.setManagementEnabled(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.setManagementEnabled(true); cacheManager.createCache("cache3", configuration); cacheManager.createCache("cache4", configuration); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2)); cacheManager.enableManagement("cache3", false); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(1)); cacheManager.enableManagement("cache3", true); assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2)); } }
<K, T> Configuration<K, T> createConfiguration(final CacheSizeManager<K, T> listener) { return new MutableConfiguration<K, T>() .setStoreByValue(false) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(SECONDS, cacheExpiry))) .setManagementEnabled(cacheManagement) .setStatisticsEnabled(cacheStatistics) .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<>( new FactoryBuilder.SingletonFactory<>(listener), null, false, false)); }
public JCache(URL url) { String method = url.getParameter(Constants.METHOD_KEY, ""); String key = url.getAddress() + "." + url.getServiceKey() + "." + method; // jcache parameter is the full-qualified class name of SPI implementation String type = url.getParameter("jcache"); CachingProvider provider = type == null || type.length() == 0 ? Caching.getCachingProvider() : Caching.getCachingProvider(type); CacheManager cacheManager = provider.getCacheManager(); Cache<Object, Object> cache = cacheManager.getCache(key); if (cache == null) { try { //configure the cache MutableConfiguration config = new MutableConfiguration<Object, Object>() .setTypes(Object.class, Object.class) .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000)))) .setStoreByValue(false) .setManagementEnabled(true) .setStatisticsEnabled(true); cache = cacheManager.createCache(key, config); } catch (CacheException e) { // concurrent cache initialization cache = cacheManager.getCache(key); } } this.store = cache; }
private 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()); mutableConfiguration.setWriteThrough(configuration.isWriteThrough()); return mutableConfiguration; } }