@SuppressWarnings("unchecked") @Test public void cacheEventListenerFactory() { Config config = ConfigFactory .empty() .withValue("cacheEventListenerFactory.class", fromAnyRef("my.Listener")) .withValue("cacheEventListenerFactory.listenFor", fromAnyRef("local")); CacheConfigurationBuilder builder = new CacheConfigurationBuilder("c1"); CacheConfiguration cache = builder.build(config); List<CacheEventListenerFactoryConfiguration> listeners = cache .getCacheEventListenerConfigurations(); assertEquals(1, listeners.size()); assertEquals("my.Listener", listeners.get(0).getFullyQualifiedClassPath()); assertEquals(NotificationScope.LOCAL, listeners.get(0).getListenFor()); }
@SuppressWarnings("unchecked") @Test public void cacheEventListenerFactories() { Config config = ConfigFactory .empty() .withValue("cacheEventListenerFactory.l1.class", fromAnyRef("my.Listener")) .withValue("cacheEventListenerFactory.l1.listenFor", fromAnyRef("local")); CacheConfigurationBuilder builder = new CacheConfigurationBuilder("c1"); CacheConfiguration cache = builder.build(config); List<CacheEventListenerFactoryConfiguration> listeners = cache .getCacheEventListenerConfigurations(); assertEquals(1, listeners.size()); assertEquals("my.Listener", listeners.get(0).getFullyQualifiedClassPath()); assertEquals(NotificationScope.LOCAL, listeners.get(0).getListenFor()); }
private void initCacheListener() { if (cache!=null) { if (cache instanceof EhcacheImpl) { Ehcache ehC= ((EhcacheImpl)cache).getEHcache(); ehC.getCacheEventNotificationService().registerListener(new LoggingEventListener(), NotificationScope.ALL); } } }
@Override public synchronized boolean addListener(final CacheListener listener) { EhCacheListenerAdapter ehCacheListener = new EhCacheListenerAdapter(listener); return ehcache.getCacheEventNotificationService().registerListener(ehCacheListener, NotificationScope.ALL); }