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()); } }
/** * Constructs a {@link MutableConfiguration} based on another * {@link CompleteConfiguration}. * * @param configuration the {@link CompleteConfiguration} */ public MutableConfiguration(CompleteConfiguration<K, V> configuration) { this.keyType = configuration.getKeyType(); this.valueType = configuration.getValueType(); listenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K, V>>(); for (CacheEntryListenerConfiguration<K, V> definition : configuration .getCacheEntryListenerConfigurations()) { addCacheEntryListenerConfiguration(definition); } this.cacheLoaderFactory = configuration.getCacheLoaderFactory(); this.cacheWriterFactory = configuration.getCacheWriterFactory(); if (configuration.getExpiryPolicyFactory() == null) { this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); } else { this.expiryPolicyFactory = configuration.getExpiryPolicyFactory(); } this.isReadThrough = configuration.isReadThrough(); this.isWriteThrough = configuration.isWriteThrough(); this.isStatisticsEnabled = configuration.isStatisticsEnabled(); this.isStoreByValue = configuration.isStoreByValue(); this.isManagementEnabled = configuration.isManagementEnabled(); }
/** Copies the configuration and overlays it on top of the default settings. */ @SuppressWarnings("PMD.AccessorMethodGeneration") private <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; }
} else { this.cacheLoaderFactory = completeConfig.getCacheLoaderFactory(); this.cacheWriterFactory = completeConfig.getCacheWriterFactory();
@Override public Factory<CacheWriter<? super K, ? super T>> getCacheWriterFactory() { return cc.getCacheWriterFactory(); }
@Override protected void configure() { for (Map.Entry<String, Cache> cacheEntry : this.caches.entrySet()) { bind(Cache.class).annotatedWith(Names.named(cacheEntry.getKey())).toInstance(cacheEntry.getValue()); Factory expiryPolicyFactory = ((CompleteConfiguration)cacheEntry.getValue().getConfiguration(CompleteConfiguration.class)).getExpiryPolicyFactory(); if (expiryPolicyFactory != null) { requestInjection(expiryPolicyFactory); } Factory cacheLoaderFactory = ((CompleteConfiguration)cacheEntry.getValue().getConfiguration(CompleteConfiguration.class)).getCacheLoaderFactory(); if (cacheLoaderFactory != null) { requestInjection(cacheLoaderFactory); } Factory cacheWriterFactory = ((CompleteConfiguration)cacheEntry.getValue().getConfiguration(CompleteConfiguration.class)).getCacheWriterFactory(); if (cacheWriterFactory != null) { requestInjection(cacheWriterFactory); } } install(new CacheAnnotationsModule()); } }
managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); cacheEntryListenerConfigurations = new HashSet<>();
managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); cacheEntryListenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K, V>>();
managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); cacheEntryListenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K, V>>();
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()); } }
if (config.getCacheWriterFactory() != null) { final javax.cache.integration.CacheWriter<? super K, ? super V> cw = config.getCacheWriterFactory().create(); cache2kConfiguration.setWriter(new CustomizationReferenceSupplier<CacheWriter<K, V>>(new CloseableWriter() { @Override
managementEnabled = cConfiguration.isManagementEnabled(); cacheLoaderFactory = cConfiguration.getCacheLoaderFactory(); cacheWristerFactory = cConfiguration.getCacheWriterFactory(); this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory(); final HashSet<CacheEntryListenerConfiguration<K, V>> set = new HashSet<CacheEntryListenerConfiguration<K, V>>();
public MutableConfiguration(CompleteConfiguration<K, V> configuration) { this.keyType = configuration.getKeyType(); this.valueType = configuration.getValueType(); listenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K, V>>(); for (final CacheEntryListenerConfiguration<K, V> definition : configuration.getCacheEntryListenerConfigurations()) { addCacheEntryListenerConfiguration(definition); } this.cacheLoaderFactory = configuration.getCacheLoaderFactory(); this.cacheWriterFactory = configuration.getCacheWriterFactory(); if (configuration.getExpiryPolicyFactory() == null) { this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); } else { this.expiryPolicyFactory = configuration.getExpiryPolicyFactory(); } this.isReadThrough = configuration.isReadThrough(); this.isWriteThrough = configuration.isWriteThrough(); this.isStatisticsEnabled = configuration.isStatisticsEnabled(); this.isStoreByValue = configuration.isStoreByValue(); this.isManagementEnabled = configuration.isManagementEnabled(); }
/** * Constructs a {@link MutableConfiguration} based on another * {@link CompleteConfiguration}. * * @param configuration the {@link CompleteConfiguration} */ public MutableConfiguration(CompleteConfiguration<K, V> configuration) { this.keyType = configuration.getKeyType(); this.valueType = configuration.getValueType(); listenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K, V>>(); for (CacheEntryListenerConfiguration<K, V> definition : configuration .getCacheEntryListenerConfigurations()) { addCacheEntryListenerConfiguration(definition); } this.cacheLoaderFactory = configuration.getCacheLoaderFactory(); this.cacheWriterFactory = configuration.getCacheWriterFactory(); if (configuration.getExpiryPolicyFactory() == null) { this.expiryPolicyFactory = EternalExpiryPolicy.factoryOf(); } else { this.expiryPolicyFactory = configuration.getExpiryPolicyFactory(); } this.isReadThrough = configuration.isReadThrough(); this.isWriteThrough = configuration.isWriteThrough(); this.isStatisticsEnabled = configuration.isStatisticsEnabled(); this.isStoreByValue = configuration.isStoreByValue(); this.isManagementEnabled = configuration.isManagementEnabled(); }
public AbstractCacheConfig(CompleteConfiguration<K, V> configuration) { setKeyType(configuration.getKeyType()); setValueType(configuration.getValueType()); this.listenerConfigurations = createConcurrentSet(); for (CacheEntryListenerConfiguration<K, V> listenerConf : configuration.getCacheEntryListenerConfigurations()) { listenerConfigurations.add(DeferredValue.withValue(listenerConf)); } this.cacheLoaderFactory = DeferredValue.withValue(configuration.getCacheLoaderFactory()); this.cacheWriterFactory = DeferredValue.withValue(configuration.getCacheWriterFactory()); Factory<ExpiryPolicy> factory = configuration.getExpiryPolicyFactory(); factory = (factory == null) ? EternalExpiryPolicy.factoryOf() : factory; this.expiryPolicyFactory = DeferredValue.withValue(factory); this.isReadThrough = configuration.isReadThrough(); this.isWriteThrough = configuration.isWriteThrough(); this.isStatisticsEnabled = configuration.isStatisticsEnabled(); this.isStoreByValue = configuration.isStoreByValue(); this.isManagementEnabled = configuration.isManagementEnabled(); }
} else { this.cacheLoaderFactory = completeConfig.getCacheLoaderFactory(); this.cacheWriterFactory = completeConfig.getCacheWriterFactory();
public AbstractCacheConfig(CompleteConfiguration<K, V> configuration) { setKeyType(configuration.getKeyType()); setValueType(configuration.getValueType()); this.listenerConfigurations = createConcurrentSet(); for (CacheEntryListenerConfiguration<K, V> listenerConf : configuration.getCacheEntryListenerConfigurations()) { listenerConfigurations.add(DeferredValue.withValue(listenerConf)); } this.cacheLoaderFactory = DeferredValue.withValue(configuration.getCacheLoaderFactory()); this.cacheWriterFactory = DeferredValue.withValue(configuration.getCacheWriterFactory()); Factory<ExpiryPolicy> factory = configuration.getExpiryPolicyFactory(); factory = (factory == null) ? EternalExpiryPolicy.factoryOf() : factory; this.expiryPolicyFactory = DeferredValue.withValue(factory); this.isReadThrough = configuration.isReadThrough(); this.isWriteThrough = configuration.isWriteThrough(); this.isStatisticsEnabled = configuration.isStatisticsEnabled(); this.isStoreByValue = configuration.isStoreByValue(); this.isManagementEnabled = configuration.isManagementEnabled(); }
/** Copies the configuration and overlays it on top of the default settings. */ @SuppressWarnings("PMD.AccessorMethodGeneration") private <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; }
/** * Ensure that a {@link MutableConfiguration} correctly uses the defaults. * @param config */ private void validateDefaults(CompleteConfiguration<?, ?> config) { assertEquals(Object.class, config.getKeyType()); assertEquals(Object.class, config.getValueType()); assertFalse(config.isReadThrough()); assertFalse(config.isWriteThrough()); assertTrue(config.isStoreByValue()); assertFalse(config.isStatisticsEnabled()); assertFalse(config.isManagementEnabled()); assertTrue(getConfigurationCacheEntryListenerConfigurationSize(config) == 0); assertNull(config.getCacheLoaderFactory()); assertNull(config.getCacheWriterFactory()); // code coverage config.hashCode(); //expiry policies ExpiryPolicy expiryPolicy = config.getExpiryPolicyFactory().create(); assertTrue(expiryPolicy instanceof EternalExpiryPolicy); assertThat(Duration.ETERNAL, equalTo(expiryPolicy.getExpiryForCreation())); assertThat(expiryPolicy.getExpiryForAccess(), is(nullValue())); assertThat(expiryPolicy.getExpiryForUpdate(), is(nullValue())); }
/** * Ensure that a {@link javax.cache.configuration.MutableConfiguration} correctly * uses the defaults. * * @param config */ private void validateDefaults(CompleteConfiguration<?, ?> config) { assertEquals(Object.class, config.getKeyType()); assertEquals(Object.class, config.getValueType()); assertFalse(config.isReadThrough()); assertFalse(config.isWriteThrough()); assertTrue(config.isStoreByValue()); assertFalse(config.isStatisticsEnabled()); assertFalse(config.isManagementEnabled()); assertTrue(getConfigurationCacheEntryListenerConfigurationSize(config) == 0); assertNull(config.getCacheLoaderFactory()); assertNull(config.getCacheWriterFactory()); //expiry policies ExpiryPolicy expiryPolicy = config.getExpiryPolicyFactory().create(); assertTrue(expiryPolicy instanceof EternalExpiryPolicy); assertThat(Duration.ETERNAL, equalTo(expiryPolicy.getExpiryForCreation())); assertThat(expiryPolicy.getExpiryForAccess(), is(nullValue())); assertThat(expiryPolicy.getExpiryForUpdate(), is(nullValue())); }