static void checkListener(CaffeineConfiguration<?, ?> config) { CacheEntryListenerConfiguration<?, ?> listener = Iterables.getOnlyElement( config.getCacheEntryListenerConfigurations()); assertThat(listener.getCacheEntryListenerFactory().create(), instanceOf(TestCacheEntryListener.class)); assertThat(listener.getCacheEntryEventFilterFactory().create(), instanceOf(TestCacheEntryEventFilter.class)); assertThat(listener.isSynchronous(), is(true)); assertThat(listener.isOldValueRequired(), is(true)); }
Builder(String cacheName, CaffeineConfiguration<K, V> config) { this.config = config; this.cacheName = cacheName; this.caffeine = Caffeine.newBuilder(); this.statistics = new JCacheStatisticsMXBean(); this.ticker = config.getTickerFactory().create(); this.executor = config.getExecutorFactory().create(); this.expiryPolicy = config.getExpiryPolicyFactory().create(); this.dispatcher = new EventDispatcher<>(executor); caffeine.executor(executor); config.getCacheEntryListenerConfigurations().forEach(dispatcher::register); }
/** 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; }
Builder(String cacheName, CaffeineConfiguration<K, V> config) { this.config = config; this.cacheName = cacheName; this.caffeine = Caffeine.newBuilder(); this.statistics = new JCacheStatisticsMXBean(); this.ticker = config.getTickerFactory().create(); this.executor = config.getExecutorFactory().create(); this.expiryPolicy = config.getExpiryPolicyFactory().create(); this.dispatcher = new EventDispatcher<>(executor); caffeine.executor(executor); config.getCacheEntryListenerConfigurations().forEach(dispatcher::register); }
/** 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; }