Hi,
Registered a Listener and capturing @CacheEntryCreated events for a Cache. This application is deployed into 3 nodes which form a cluster.
Added a log statement to know the key that has been added to cache. Now when an entry is added to cache, there are 3 messages printed to console for the same key on the node that inserted into cache. Below is part of log message on node3
2011-06-02 14:45:18,340 INFO [STDOUT] (ajp-10.2.84.60-8209-11) INFO : com.infinispan.test.InfinispanTestServlet - Node : node3 PUT 20:hello20
2011-06-02 14:45:18,345 INFO [STDOUT] (notification-thread-0) Node :: node3 Entry added with key --> 20
2011-06-02 14:45:18,346 INFO [STDOUT] (notification-thread-0) Node :: node3 Entry added with key --> 20
2011-06-02 14:45:18,348 INFO [STDOUT] (notification-thread-0) Node :: node3 Entry added with key --> 20
2011-06-02 14:45:18,399 INFO [STDOUT] (ajp-10.2.84.60-8209-11) INFO : com.infinispan.test.InfinispanTestServlet - Node : node3 PUT 23:hello23
2011-06-02 14:45:18,402 INFO [STDOUT] (notification-thread-0) Node :: node3 Entry added with key --> 23
2011-06-02 14:45:18,403 INFO [STDOUT] (notification-thread-0) Node :: node3 Entry added with key --> 23
2011-06-02 14:45:18,404 INFO [STDOUT] (notification-thread-0) Node :: node3 Entry added with key --> 23
This is how the Listener is configured
@Listener(sync = false)
public class CacheListener {
@CacheEntryCreated
public void entryAdded(CacheEntryCreatedEvent<String,String> event) {
if(!event.isPre())
System.out.println("Node :: "+System.getProperty("server.name")+" Entry added with key --> "+event.getKey());
}
}
this.cacheContainer = cacheContainer;
numbersCache = cacheContainer.getCache("numbersCache");
numbersCache.addListener(new CacheListener());
What could be wrong ? Or is this the expected behaviour ? If so, is there a way to enforce that the listener gets called only on the node which has inserted entry into cache and only once.
Thanks,
Madan Narra