-
1. Re: L1 Cache & Cache EventListeners
vblagojevic Dec 29, 2010 3:10 PM (in response to canokar)Hi Cano,
I believe that even though an entry is in L1 you should get notified about its eviction. However, you would have to listen for either CacheEntryEvicted and CacheEntryRemoved events. How are you attaching these listeners? Post your code snippet.
Regards,
Vladimir
-
2. Re: L1 Cache & Cache EventListeners
canokar Jan 3, 2011 9:07 AM (in response to vblagojevic)Hi Vladimir,
here is my test code. On the opposite i create a Cache and load the content of the cache via FileStoreConfig.
Currently there are only one element inside the cache (Key=key and Value=value) for testing purpose.
The JUnit Test successfully connects to the "Server" Cache and gets the correct value for Key=key.
import org.infinispan.Cache;
import org.infinispan.config.CacheLoaderManagerConfig;
import org.infinispan.config.Configuration;
import org.infinispan.config.GlobalConfiguration;
import org.infinispan.config.Configuration.CacheMode;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.loaders.CacheStoreConfig;
import org.infinispan.loaders.file.FileCacheStoreConfig;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
import org.junit.Before;
import org.junit.Test;public class CacheTest {
@Before
public void setUp() throws Exception {
}@Test
public void accessCache() {
EmbeddedCacheManager manager = getCacheManager();
Cache<String, String> cache = manager.getCache("CacheStore");
cache.addListener(new DummyListener());System.out.println("Cache value for \"key\" = " + cache.get("key"));
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Cache value for \"key\" = " + cache.get("key"));
try {
Thread.sleep(1200);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Cache value for \"key\" = " + cache.get("key"));cache.stop();
manager.stop();
}private EmbeddedCacheManager getCacheManager() {
GlobalConfiguration globalConf = GlobalConfiguration.getClusteredDefault();
Configuration config = new Configuration();
config.setEvictionStrategy(EvictionStrategy.NONE);
config.setCacheLoaderManagerConfig(new CacheLoaderManagerConfig());
config.setCacheMode(CacheMode.DIST_SYNC);
config.setL1Lifespan(500);
return new DefaultCacheManager(globalConf, config);
}
@Listener
public class DummyListener {
@CacheEntryCreated
public void print(CacheEntryCreatedEvent<String, String> event) {
System.out.println("New entry " + event.getKey() + " created in the cache");
}
@CacheEntryRemoved
public void print(CacheEntryRemovedEvent<String, String> event) {
System.out.println("Entry " + event.getKey() + " removed in the cache");
}
}
} -
3. Re: L1 Cache & Cache EventListeners
vblagojevic Jan 3, 2011 9:58 AM (in response to canokar)The key/value pair was either transfered during state transfer or there was a remote get. That is why you are not seeing listeners invoked. Do a put or remove in this test code and observe if the listener is getting invoked.
Regards,
Vladimir