@Override public <K, V> CacheEventDispatcher<K, V> createCacheEventDispatcher(Store<K, V> store, ServiceConfiguration<?>... serviceConfigs) { String threadPoolAlias = defaultThreadPoolAlias; DefaultCacheEventDispatcherConfiguration config = findSingletonAmongst(DefaultCacheEventDispatcherConfiguration.class, (Object[]) serviceConfigs); if (config != null) { threadPoolAlias = config.getThreadPoolAlias(); } ExecutorService orderedExecutor = executionService.getOrderedExecutor(threadPoolAlias, new LinkedBlockingQueue<>()); ExecutorService unOrderedExecutor = executionService.getUnorderedExecutor(threadPoolAlias, new LinkedBlockingQueue<>()); return new CacheEventDispatcherImpl<>(unOrderedExecutor, orderedExecutor); }
public DefaultCacheEventDispatcherConfigurationParser() { super(DefaultCacheEventDispatcherConfiguration.class, CacheTemplate::listenersConfig, config -> ofNullable(config.threadPool()).map(DefaultCacheEventDispatcherConfiguration::new).orElse(null), CacheType::getListeners, CacheType::setListeners, config -> new ListenersType().withDispatcherThreadPool(config.getThreadPoolAlias()), (initial, additional) -> initial.withDispatcherThreadPool(additional.getDispatcherThreadPool())); } }
@Test public void parseServiceConfiguration() throws Exception { CacheConfiguration<?, ?> cacheConfiguration = new XmlConfiguration(getClass().getResource("/configs/ehcache-cacheEventListener.xml")).getCacheConfigurations().get("template1"); DefaultCacheEventDispatcherConfiguration eventDispatcherConfig = findSingletonAmongst(DefaultCacheEventDispatcherConfiguration.class, cacheConfiguration.getServiceConfigurations()); assertThat(eventDispatcherConfig).isNotNull(); assertThat(eventDispatcherConfig.getThreadPoolAlias()).isEqualTo("listeners-pool"); }
@Test public void testCacheEventListenerThreadPoolName() throws Exception { Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-cacheEventListener.xml")); CacheConfiguration<?, ?> template1 = configuration.getCacheConfigurations().get("template1"); DefaultCacheEventDispatcherConfiguration eventDispatcherConfig = null; for (ServiceConfiguration<?> serviceConfiguration : template1.getServiceConfigurations()) { if (serviceConfiguration instanceof DefaultCacheEventDispatcherConfiguration) { eventDispatcherConfig = (DefaultCacheEventDispatcherConfiguration) serviceConfiguration; } } assertThat(eventDispatcherConfig.getThreadPoolAlias(), is("listeners-pool")); }
@Test public void testConfigurationOfThreadPoolAlias() { @SuppressWarnings("unchecked") ServiceProvider<Service> serviceProvider = mock(ServiceProvider.class); when(serviceProvider.getService(ExecutionService.class)).thenReturn(mock(ExecutionService.class)); CacheEventDispatcherFactoryImpl factory = new CacheEventDispatcherFactoryImpl(); factory.start(serviceProvider); DefaultCacheEventDispatcherConfiguration config = spy(new DefaultCacheEventDispatcherConfiguration("aName")); @SuppressWarnings("unchecked") Store<Object, Object> store = mock(Store.class); factory.createCacheEventDispatcher(store, config); verify(config).getThreadPoolAlias(); }
public DefaultCacheEventDispatcherConfigurationParser() { super(DefaultCacheEventDispatcherConfiguration.class, CacheTemplate::listenersConfig, config -> ofNullable(config.threadPool()).map(DefaultCacheEventDispatcherConfiguration::new).orElse(null), CacheType::getListeners, CacheType::setListeners, config -> new ListenersType().withDispatcherThreadPool(config.getThreadPoolAlias()), (initial, additional) -> initial.withDispatcherThreadPool(additional.getDispatcherThreadPool())); } }
@Override public <K, V> CacheEventDispatcher<K, V> createCacheEventDispatcher(Store<K, V> store, ServiceConfiguration<?>... serviceConfigs) { String threadPoolAlias = defaultThreadPoolAlias; DefaultCacheEventDispatcherConfiguration config = findSingletonAmongst(DefaultCacheEventDispatcherConfiguration.class, (Object[]) serviceConfigs); if (config != null) { threadPoolAlias = config.getThreadPoolAlias(); } ExecutorService orderedExecutor = executionService.getOrderedExecutor(threadPoolAlias, new LinkedBlockingQueue<>()); ExecutorService unOrderedExecutor = executionService.getUnorderedExecutor(threadPoolAlias, new LinkedBlockingQueue<>()); return new CacheEventDispatcherImpl<>(unOrderedExecutor, orderedExecutor); }