javax.cache.configuration.CompleteConfiguration Java Examples
The following examples show how to use
javax.cache.configuration.CompleteConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestJCache.java From jframe with Apache License 2.0 | 6 votes |
@Test public void configEhcache2Jsr107() { CachingProvider provider = Caching.getCachingProvider(); CacheManager cacheManager = provider.getCacheManager(); CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder .newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)).build(); Cache<Long, String> cache = cacheManager.createCache("myCache", Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration)); Eh107Configuration<Long, String> configuration = cache.getConfiguration(Eh107Configuration.class); configuration.unwrap(CacheConfiguration.class); configuration.unwrap(CacheRuntimeConfiguration.class); try { cache.getConfiguration(CompleteConfiguration.class); throw new AssertionError("IllegalArgumentException expected"); } catch (IllegalArgumentException iaex) { // Expected } }
Example #2
Source File: ConfigurationMerger.java From ehcache3 with Apache License 2.0 | 6 votes |
private <K, V> Jsr107CacheLoaderWriter<K, V> initCacheLoaderWriter(CompleteConfiguration<K, V> config) { Factory<CacheLoader<K, V>> cacheLoaderFactory = config.getCacheLoaderFactory(); @SuppressWarnings("unchecked") Factory<CacheWriter<K, V>> cacheWriterFactory = (Factory<CacheWriter<K, V>>) (Object) config.getCacheWriterFactory(); if (config.isReadThrough() && cacheLoaderFactory == null) { throw new IllegalArgumentException("read-through enabled without a CacheLoader factory provided"); } if (config.isWriteThrough() && cacheWriterFactory == null) { throw new IllegalArgumentException("write-through enabled without a CacheWriter factory provided"); } CacheLoader<K, V> cacheLoader = cacheLoaderFactory == null ? null : cacheLoaderFactory.create(); CacheWriter<K, V> cacheWriter; try { cacheWriter = cacheWriterFactory == null ? null : cacheWriterFactory.create(); } catch (Throwable t) { throw closeAllAfter(new CacheException(t), cacheLoader); } if (cacheLoader == null && cacheWriter == null) { return null; } else { return new Eh107CacheLoaderWriter<>(cacheLoader, config.isReadThrough(), cacheWriter, config.isWriteThrough()); } }
Example #3
Source File: EhCache107ConfigurationIntegrationDocTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testUsingEhcacheConfiguration() throws Exception { // tag::ehcacheBasedConfigurationExample[] CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)).build(); // <1> Cache<Long, String> cache = cacheManager.createCache("myCache", Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration)); // <2> Eh107Configuration<Long, String> configuration = cache.getConfiguration(Eh107Configuration.class); configuration.unwrap(CacheConfiguration.class); // <3> configuration.unwrap(CacheRuntimeConfiguration.class); // <4> try { cache.getConfiguration(CompleteConfiguration.class); // <5> throw new AssertionError("IllegalArgumentException expected"); } catch (IllegalArgumentException iaex) { // Expected } // end::ehcacheBasedConfigurationExample[] }
Example #4
Source File: CaffeineConfiguration.java From caffeine with Apache License 2.0 | 6 votes |
public CaffeineConfiguration(CompleteConfiguration<K, V> configuration) { delegate = new MutableConfiguration<>(configuration); if (configuration instanceof CaffeineConfiguration<?, ?>) { CaffeineConfiguration<K, V> config = (CaffeineConfiguration<K, V>) configuration; refreshAfterWriteNanos = config.refreshAfterWriteNanos; expireAfterAccessNanos = config.expireAfterAccessNanos; expireAfterWriteNanos = config.expireAfterWriteNanos; executorFactory = config.executorFactory; expiryFactory = config.expiryFactory; copierFactory = config.copierFactory; tickerFactory = config.tickerFactory; weigherFactory = config.weigherFactory; maximumWeight = config.maximumWeight; maximumSize = config.maximumSize; } else { tickerFactory = SYSTEM_TICKER; executorFactory = COMMON_POOL; copierFactory = JAVA_COPIER; } }
Example #5
Source File: JCacheManager.java From redisson with Apache License 2.0 | 6 votes |
@Override public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType) { checkNotClosed(); if (cacheName == null) { throw new NullPointerException(); } if (keyType == null) { throw new NullPointerException(); } if (valueType == null) { throw new NullPointerException(); } JCache<?, ?> cache = caches.get(cacheName); if (cache == null) { return null; } if (!keyType.isAssignableFrom(cache.getConfiguration(CompleteConfiguration.class).getKeyType())) { throw new ClassCastException("Wrong type of key for " + cacheName); } if (!valueType.isAssignableFrom(cache.getConfiguration(CompleteConfiguration.class).getValueType())) { throw new ClassCastException("Wrong type of value for " + cacheName); } return (Cache<K, V>) cache; }
Example #6
Source File: JCacheConfiguration.java From redisson with Apache License 2.0 | 6 votes |
public JCacheConfiguration(Configuration<K, V> configuration) { if (configuration != null) { if (configuration instanceof RedissonConfiguration) { configuration = ((RedissonConfiguration<K, V>) configuration).getJcacheConfig(); } if (configuration instanceof CompleteConfiguration) { delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration); } else { delegate = new MutableConfiguration<K, V>(); delegate.setStoreByValue(configuration.isStoreByValue()); delegate.setTypes(configuration.getKeyType(), configuration.getValueType()); } } else { delegate = new MutableConfiguration<K, V>(); } this.expiryPolicy = delegate.getExpiryPolicyFactory().create(); }
Example #7
Source File: TestJCache.java From jframe with Apache License 2.0 | 6 votes |
@Test public void cacheConfigTest() { CachingProvider provider = Caching.getCachingProvider(); CacheManager cacheManager = provider.getCacheManager(); MutableConfiguration<Long, String> configuration = new MutableConfiguration<Long, String>(); configuration.setTypes(Long.class, String.class); Cache<Long, String> cache = cacheManager.createCache("someCache", configuration); CompleteConfiguration<Long, String> completeConfiguration = cache.getConfiguration(CompleteConfiguration.class); Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class); CacheRuntimeConfiguration<Long, String> runtimeConfiguration = eh107Configuration .unwrap(CacheRuntimeConfiguration.class); }
Example #8
Source File: TCacheJSR107.java From triava with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public <C extends Configuration<K, V>> C getConfiguration(Class<C> clazz) { Builder<K, V> builder = tcache.builder; if (clazz.isAssignableFrom(javax.cache.configuration.Configuration.class)) { return (C)builder; } if (clazz.isAssignableFrom(CompleteConfiguration.class)) { return (C)builder; } throw new IllegalArgumentException("Unsupported configuration class: " + clazz.toString()); }
Example #9
Source File: RespositoryCacheManagerTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Before public void setUp() throws Exception { repositoryCacheManager = new RepositoryCacheManager(); repositoryConfiguration = new RepositoryConfiguration<>(String.class, String.class, REPO_ID); providerURI = new URI(RepositoryCachingProvider.class.getName()); providerProperties = new Properties(); providerClassLoader = RepositoryCachingProvider.class.getClassLoader(); MockitoAnnotations.initMocks(this); when(repositoryCachingProvider.getDefaultURI()).thenReturn(providerURI); when(repositoryCachingProvider.getDefaultProperties()).thenReturn(new Properties()); when(repositoryCachingProvider.getDefaultClassLoader()).thenReturn(providerClassLoader); when(cacheFactory.getValueType()).thenReturn(String.class); when(cacheFactory.createCache(any(RepositoryConfiguration.class), any(CacheManager.class), any(Repository.class))).thenReturn(repoCache); when(repoCache.getConfiguration(eq(CompleteConfiguration.class))).thenReturn(repositoryConfiguration); when(repositoryManager.getRepository(eq(REPO_ID))).thenReturn(Optional.of(repository)); repositoryCacheManager.setCachingProvider(repositoryCachingProvider); repositoryCacheManager.setRepositoryManager(repositoryManager); repositoryCacheManager.addCacheFactory(cacheFactory); }
Example #10
Source File: TempStateCacheView.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public V get(final K key) { if (ignoreKey(key)) { return null; } final V v = put.get(key); if (v != null) { return v; } // for an EntryProcessor we already incremented stats - to enhance // surely if (cache.getConfiguration(CompleteConfiguration.class).isStatisticsEnabled()) { final Statistics statistics = cache.getStatistics(); if (cache.containsKey(key)) { statistics.increaseHits(-1); } else { statistics.increaseMisses(-1); } } return cache.get(key); }
Example #11
Source File: JCSConfiguration.java From commons-jcs with Apache License 2.0 | 5 votes |
public JCSConfiguration(final Configuration<K, V> configuration, final Class<K> keyType, final Class<V> valueType) { this.keyType = keyType; this.valueType = valueType; if (configuration instanceof CompleteConfiguration) { final CompleteConfiguration<K, V> cConfiguration = (CompleteConfiguration<K, V>) configuration; storeByValue = configuration.isStoreByValue(); readThrough = cConfiguration.isReadThrough(); writeThrough = cConfiguration.isWriteThrough(); statisticsEnabled = cConfiguration.isStatisticsEnabled(); managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); cacheEntryListenerConfigurations = new HashSet<>(); final Iterable<CacheEntryListenerConfiguration<K, V>> entryListenerConfigurations = cConfiguration .getCacheEntryListenerConfigurations(); if (entryListenerConfigurations != null) { for (final CacheEntryListenerConfiguration<K, V> kvCacheEntryListenerConfiguration : entryListenerConfigurations) { cacheEntryListenerConfigurations.add(kvCacheEntryListenerConfiguration); } } } else { expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); storeByValue = true; readThrough = false; writeThrough = false; statisticsEnabled = false; managementEnabled = false; cacheLoaderFactory = null; cacheWristerFactory = null; cacheEntryListenerConfigurations = new HashSet<>(); } }
Example #12
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void getUntypedCache() { CacheManager cacheManager = getCacheManager(); //configure an un-typed Cache MutableConfiguration config = new MutableConfiguration(); cacheManager.createCache("untyped-cache", config); Cache cache = cacheManager.getCache("untyped-cache"); assertNotNull(cache); assertEquals(Object.class, cache.getConfiguration(CompleteConfiguration.class).getKeyType()); assertEquals(Object.class, cache.getConfiguration(CompleteConfiguration.class).getValueType()); }
Example #13
Source File: RateLimitingFilter.java From tutorials with MIT License | 5 votes |
public RateLimitingFilter(JHipsterProperties jHipsterProperties) { this.jHipsterProperties = jHipsterProperties; CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); CompleteConfiguration<String, GridBucketState> config = new MutableConfiguration<String, GridBucketState>() .setTypes(String.class, GridBucketState.class); this.cache = cacheManager.createCache(GATEWAY_RATE_LIMITING_CACHE_NAME, config); this.buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(cache); }
Example #14
Source File: RateLimitingFilter.java From cubeai with Apache License 2.0 | 5 votes |
public RateLimitingFilter(JHipsterProperties jHipsterProperties) { this.jHipsterProperties = jHipsterProperties; CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); CompleteConfiguration<String, GridBucketState> config = new MutableConfiguration<String, GridBucketState>() .setTypes(String.class, GridBucketState.class); this.cache = cacheManager.createCache(GATEWAY_RATE_LIMITING_CACHE_NAME, config); this.buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(cache); }
Example #15
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void getTypedCache() { CacheManager cacheManager = getCacheManager(); MutableConfiguration<String, Long> config = new MutableConfiguration<String, Long>().setTypes(String.class, Long.class); cacheManager.createCache("typed-cache", config); Cache<String, Long> cache = cacheManager.getCache("typed-cache", String.class, Long.class); assertNotNull(cache); assertEquals(String.class, cache.getConfiguration(CompleteConfiguration.class).getKeyType()); assertEquals(Long.class, cache.getConfiguration(CompleteConfiguration.class).getValueType()); }
Example #16
Source File: JCacheManager.java From redisson with Apache License 2.0 | 5 votes |
@Override public <K, V> Cache<K, V> getCache(String cacheName) { checkNotClosed(); Cache<K, V> cache = (Cache<K, V>) getCache(cacheName, Object.class, Object.class); if (cache != null) { if (cache.getConfiguration(CompleteConfiguration.class).getKeyType() != Object.class) { throw new IllegalArgumentException("Wrong type of key for " + cacheName); } if (cache.getConfiguration(CompleteConfiguration.class).getValueType() != Object.class) { throw new IllegalArgumentException("Wrong type of value for " + cacheName); } } return cache; }
Example #17
Source File: CacheListenerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void testDynamicRegistration() { assertEquals(1, getConfigurationCacheEntryListenerConfigurationSize(cache)); MyCacheEntryListener secondListener = new MyCacheEntryListener<Long, String>(); MutableCacheEntryListenerConfiguration<Long, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration(FactoryBuilder.factoryOf(secondListener), null, false, true); cache.registerCacheEntryListener(listenerConfiguration); assertEquals(2,getConfigurationCacheEntryListenerConfigurationSize(cache)); CompleteConfiguration<Long, String> cacheConfig = (CompleteConfiguration)cache.getConfiguration(CompleteConfiguration.class); for (CacheEntryListenerConfiguration<Long, String> config : cacheConfig.getCacheEntryListenerConfigurations()) { config.hashCode(); config.isOldValueRequired(); config.isSynchronous(); } //Can only register the same configuration once try { cache.registerCacheEntryListener(listenerConfiguration); fail(); } catch (IllegalArgumentException e) { //expected } }
Example #18
Source File: CacheManagerTest.java From caffeine with Apache License 2.0 | 5 votes |
private void checkConfigurationJmx(Supplier<Cache<?, ?>> cacheSupplier) throws Exception { Cache<?, ?> cache = cacheSupplier.get(); @SuppressWarnings("unchecked") CompleteConfiguration<?, ?> configuration = cache.getConfiguration(CompleteConfiguration.class); assertThat(configuration.isManagementEnabled(), is(true)); assertThat(configuration.isStatisticsEnabled(), is(true)); String name = "javax.cache:Cache=%s,CacheManager=%s,type=CacheStatistics"; ManagementFactory.getPlatformMBeanServer().getObjectInstance( new ObjectName(String.format(name, cache.getName(), PROVIDER_NAME))); }
Example #19
Source File: CacheListenerTest.java From cache2k with Apache License 2.0 | 5 votes |
private int getConfigurationCacheEntryListenerConfigurationSize(Cache cache) { int i = 0; CompleteConfiguration<Long, String> cacheConfig = (CompleteConfiguration)cache.getConfiguration(CompleteConfiguration.class); for (CacheEntryListenerConfiguration<Long, String> listenerConfig : cacheConfig.getCacheEntryListenerConfigurations()) { i++; } return i; }
Example #20
Source File: CacheFactory.java From caffeine with Apache License 2.0 | 5 votes |
/** Copies the configuration and overlays it on top of the default settings. */ @SuppressWarnings("PMD.AccessorMethodGeneration") private static <K, V> CaffeineConfiguration<K, V> resolveConfigurationFor( Configuration<K, V> configuration) { if (configuration instanceof CaffeineConfiguration<?, ?>) { return new CaffeineConfiguration<>((CaffeineConfiguration<K, V>) configuration); } CaffeineConfiguration<K, V> template = TypesafeConfigurator.defaults(rootConfig()); if (configuration instanceof CompleteConfiguration<?, ?>) { CompleteConfiguration<K, V> complete = (CompleteConfiguration<K, V>) configuration; template.setReadThrough(complete.isReadThrough()); template.setWriteThrough(complete.isWriteThrough()); template.setManagementEnabled(complete.isManagementEnabled()); template.setStatisticsEnabled(complete.isStatisticsEnabled()); template.getCacheEntryListenerConfigurations() .forEach(template::removeCacheEntryListenerConfiguration); complete.getCacheEntryListenerConfigurations() .forEach(template::addCacheEntryListenerConfiguration); template.setCacheLoaderFactory(complete.getCacheLoaderFactory()); template.setCacheWriterFactory(complete.getCacheWriterFactory()); template.setExpiryPolicyFactory(complete.getExpiryPolicyFactory()); } template.setTypes(configuration.getKeyType(), configuration.getValueType()); template.setStoreByValue(configuration.isStoreByValue()); return template; }
Example #21
Source File: Eh107XmlIntegrationTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void test107CacheCanReturnCompleteConfigurationWhenNonePassedIn() { CacheManager cacheManager = cachingProvider.getCacheManager(); Cache<Long, String> cache = cacheManager.createCache("cacheWithoutCompleteConfig", new Configuration<Long, String>() { private static final long serialVersionUID = 1L; @Override public Class<Long> getKeyType() { return Long.class; } @Override public Class<String> getValueType() { return String.class; } @Override public boolean isStoreByValue() { return true; } }); @SuppressWarnings("unchecked") CompleteConfiguration<Long, String> configuration = cache.getConfiguration(CompleteConfiguration.class); assertThat(configuration, notNullValue()); assertThat(configuration.isStoreByValue(), is(true)); // Respects defaults assertThat(configuration.getExpiryPolicyFactory(), equalTo(EternalExpiryPolicy.factoryOf())); }
Example #22
Source File: JCacheBuilder.java From cache2k with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void setConfiguration(Configuration<K,V> cfg) { if (cfg instanceof CompleteConfiguration) { config = (CompleteConfiguration<K,V>) cfg; if (cfg instanceof ExtendedConfiguration) { cache2kConfiguration = ((ExtendedConfiguration<K,V>) cfg).getCache2kConfiguration(); if (cache2kConfiguration != null) { if (cache2kConfiguration.getName() != null && !cache2kConfiguration.getName().equals(name)) { throw new IllegalArgumentException("cache name mismatch."); } cache2kConfigurationWasProvided = true; } } } else { MutableConfiguration<K, V> _cfgCopy = new MutableConfiguration<K, V>(); _cfgCopy.setTypes(cfg.getKeyType(), cfg.getValueType()); _cfgCopy.setStoreByValue(cfg.isStoreByValue()); config = _cfgCopy; } if (cache2kConfiguration == null) { cache2kConfiguration = CacheManagerImpl.PROVIDER.getDefaultConfiguration(manager.getCache2kManager()); if (cfg instanceof ExtendedMutableConfiguration) { ((ExtendedMutableConfiguration) cfg).setCache2kConfiguration(cache2kConfiguration); } } cache2kConfiguration.setName(name); Cache2kCoreProviderImpl.CACHE_CONFIGURATION_PROVIDER.augmentConfiguration(manager.getCache2kManager(), cache2kConfiguration); cache2kConfigurationWasProvided |= cache2kConfiguration.isExternalConfigurationPresent(); if (cache2kConfigurationWasProvided) { extraConfiguration = CACHE2K_DEFAULTS; JCacheConfiguration _extraConfigurationSpecified = cache2kConfiguration.getSections().getSection(JCacheConfiguration.class); if (_extraConfigurationSpecified != null) { extraConfiguration = _extraConfigurationSpecified; } } }
Example #23
Source File: EhCache107ConfigurationIntegrationDocTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testGettingToEhcacheConfiguration() { // tag::mutableConfigurationExample[] MutableConfiguration<Long, String> configuration = new MutableConfiguration<>(); configuration.setTypes(Long.class, String.class); Cache<Long, String> cache = cacheManager.createCache("someCache", configuration); // <1> CompleteConfiguration<Long, String> completeConfiguration = cache.getConfiguration(CompleteConfiguration.class); // <2> Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class); // <3> CacheRuntimeConfiguration<Long, String> runtimeConfiguration = eh107Configuration.unwrap(CacheRuntimeConfiguration.class); // <4> // end::mutableConfigurationExample[] assertThat(completeConfiguration, notNullValue()); assertThat(runtimeConfiguration, notNullValue()); // Check uses default JSR-107 expiry long nanoTime = System.nanoTime(); LOGGER.info("Seeding random with {}", nanoTime); Random random = new Random(nanoTime); assertThat(runtimeConfiguration.getExpiryPolicy().getExpiryForCreation(random.nextLong(), Long.toOctalString(random.nextLong())), equalTo(org.ehcache.expiry.ExpiryPolicy.INFINITE)); assertThat(runtimeConfiguration.getExpiryPolicy().getExpiryForAccess(random.nextLong(), () -> Long.toOctalString(random.nextLong())), nullValue()); assertThat(runtimeConfiguration.getExpiryPolicy().getExpiryForUpdate(random.nextLong(), () -> Long.toOctalString(random.nextLong()), Long.toOctalString(random.nextLong())), nullValue()); }
Example #24
Source File: JCacheAdapter.java From cache2k with Apache License 2.0 | 5 votes |
@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; } }; }
Example #25
Source File: ConfigurationMerger.java From ehcache3 with Apache License 2.0 | 5 votes |
private <K, V> Map<CacheEntryListenerConfiguration<K, V>, ListenerResources<K, V>> initCacheEventListeners(CompleteConfiguration<K, V> config) { Map<CacheEntryListenerConfiguration<K, V>, ListenerResources<K, V>> listenerResources = new ConcurrentHashMap<>(); for (CacheEntryListenerConfiguration<K, V> listenerConfig : config.getCacheEntryListenerConfigurations()) { listenerResources.put(listenerConfig, ListenerResources.createListenerResources(listenerConfig)); } return listenerResources; }
Example #26
Source File: RepositoryConfiguration.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
public RepositoryConfiguration(CompleteConfiguration<K, V> configuration) { delegate = new MutableConfiguration<>(configuration); if (configuration instanceof RepositoryConfiguration<?, ?>) { RepositoryConfiguration<K, V> config = (RepositoryConfiguration<K, V>) configuration; repoId = config.repoId; } }
Example #27
Source File: RespositoryCacheManagerTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test(expected = ClassCastException.class) public void getCacheWithCacheNameAndTypesConfigurationValueDoesNotMatchTest() { RepositoryConfiguration<String, Object> otherConfig = new RepositoryConfiguration<>(String.class, Object.class, REPO_ID); when(repoCache.getConfiguration(eq(CompleteConfiguration.class))).thenReturn(otherConfig); repositoryCacheManager.createCache(CACHE_NAME, repositoryConfiguration); Cache<String, String> cache = repositoryCacheManager.getCache(CACHE_NAME, String.class, String.class); }
Example #28
Source File: RespositoryCacheManagerTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test(expected = ClassCastException.class) public void getCacheWithCacheNameAndTypesConfigurationKeyDoesNotMatchTest() { RepositoryConfiguration<Object, String> otherConfig = new RepositoryConfiguration<>(Object.class, String.class, REPO_ID); when(repoCache.getConfiguration(eq(CompleteConfiguration.class))).thenReturn(otherConfig); repositoryCacheManager.createCache(CACHE_NAME, repositoryConfiguration); Cache<String, String> cache = repositoryCacheManager.getCache(CACHE_NAME, String.class, String.class); }
Example #29
Source File: RepositoryCacheManager.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType) { if (cacheName == null) { throw new IllegalArgumentException("CacheName must not be null"); } if (keyType == null) { throw new IllegalArgumentException("KeyType must not be null"); } if (valueType == null) { throw new IllegalArgumentException("KeyType must not be null"); } Cache<K, V> cache = getCache(cacheName); if (cache == null) { return null; } Configuration<?, ?> config = cache.getConfiguration(CompleteConfiguration.class); if (keyType != config.getKeyType()) { throw new ClassCastException("Incompatible cache key types specified, expected " + config.getKeyType() + " but " + keyType + " was specified"); } else if (valueType != config.getValueType()) { throw new ClassCastException("Incompatible cache value types specified, expected " + config.getValueType() + " but " + valueType + " was specified"); } return cache; }
Example #30
Source File: RateLimitingFilter.java From jhipster-microservices-example with Apache License 2.0 | 5 votes |
public RateLimitingFilter(JHipsterProperties jHipsterProperties) { this.jHipsterProperties = jHipsterProperties; CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); CompleteConfiguration<String, GridBucketState> config = new MutableConfiguration<String, GridBucketState>() .setTypes(String.class, GridBucketState.class); this.cache = cacheManager.createCache(GATEWAY_RATE_LIMITING_CACHE_NAME, config); this.buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(cache); }