@Override public void registerCacheEntryListener( CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { requireNotClosed(); configuration.addCacheEntryListenerConfiguration(cacheEntryListenerConfiguration); dispatcher.register(cacheEntryListenerConfiguration); }
/** Adds the entry listeners settings. */ private void addListeners() { for (String path : merged.getStringList("listeners")) { Config listener = root.getConfig(path); Factory<? extends CacheEntryListener<? super K, ? super V>> listenerFactory = factoryCreator.factoryOf(listener.getString("class")); Factory<? extends CacheEntryEventFilter<? super K, ? super V>> filterFactory = null; if (listener.hasPath("filter")) { filterFactory = factoryCreator.factoryOf(listener.getString("filter")); } boolean oldValueRequired = listener.getBoolean("old-value-required"); boolean synchronous = listener.getBoolean("synchronous"); configuration.addCacheEntryListenerConfiguration( new MutableCacheEntryListenerConfiguration<>( listenerFactory, filterFactory, oldValueRequired, synchronous)); } }
@Override protected CaffeineConfiguration<Integer, Integer> getConfiguration() { CacheEntryRemovedListener<Integer, Integer> listener = events -> removed.incrementAndGet(); CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>(); configuration.setMaximumSize(OptionalLong.of(MAXIMUM)); CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, Integer>(() -> listener, /* filterFactory */ null, /* isOldValueRequired */ false, /* isSynchronous */ true); configuration.addCacheEntryListenerConfiguration(listenerConfiguration); configuration.setExecutorFactory(MoreExecutors::directExecutor); return configuration; }
@Override protected CaffeineConfiguration<Integer, Integer> getConfiguration() { CacheEntryRemovedListener<Integer, Integer> listener = events -> removedWeight.addAndGet(Iterables.getOnlyElement(events).getValue()); CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>(); configuration.setMaximumWeight(OptionalLong.of(MAXIMUM)); configuration.setWeigherFactory(Optional.of(() -> (key, value) -> value)); CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, Integer>(() -> listener, /* filterFactory */ null, /* isOldValueRequired */ true, /* isSynchronous */ true); configuration.addCacheEntryListenerConfiguration(listenerConfiguration); configuration.setExecutorFactory(MoreExecutors::directExecutor); return configuration; }
@Override protected CaffeineConfiguration<Integer, Integer> getConfiguration() { CacheEntryRemovedListener<Integer, Integer> listener = events -> removed.incrementAndGet(); CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>(); configuration.setMaximumSize(OptionalLong.of(MAXIMUM)); CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(() -> listener, /* filterFactory */ null, /* isOldValueRequired */ false, /* isSynchronous */ true); configuration.addCacheEntryListenerConfiguration(listenerConfiguration); configuration.setExecutorFactory(MoreExecutors::directExecutor); configuration.setExpiryFactory(Optional.of(() -> expiry)); configuration.setTickerFactory(() -> ticker::read); return configuration; }
@Override public void registerCacheEntryListener( CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) { requireNotClosed(); configuration.addCacheEntryListenerConfiguration(cacheEntryListenerConfiguration); dispatcher.register(cacheEntryListenerConfiguration); }
/** Adds the entry listeners settings. */ private void addListeners() { for (String path : merged.getStringList("listeners")) { Config listener = root.getConfig(path); Factory<? extends CacheEntryListener<? super K, ? super V>> listenerFactory = factoryCreator.factoryOf(listener.getString("class")); Factory<? extends CacheEntryEventFilter<? super K, ? super V>> filterFactory = null; if (listener.hasPath("filter")) { filterFactory = factoryCreator.factoryOf(listener.getString("filter")); } boolean oldValueRequired = listener.getBoolean("old-value-required"); boolean synchronous = listener.getBoolean("synchronous"); configuration.addCacheEntryListenerConfiguration( new MutableCacheEntryListenerConfiguration<>( listenerFactory, filterFactory, oldValueRequired, synchronous)); } }