[infinispan-dev] Infinispan listener events not very intuitive

Galder Zamarreño galder.zamarreno at redhat.com
Fri Feb 24 09:22:59 EST 2012

Hi all,

When are we gonna switch to JSR-107 listeners?

As I mention in https://community.jboss.org/message/719245#719245, cache entry created and modified notifications are not very intuitive if you want to do something on cache entry created that you don't wanna do on cache modified, and viceversa, and you want to do such thing when isPre=false (the majority of times tbh). 

To give you an real example, Hot Rod remote notifications. I want to send a different notification when a cache entry is created (=insert) as opposed to when cache entry is modified (=update), and of course, I wanna do so *after* the event. How do I code this?

Option 1:
- Implement @CacheEntryCreated and in it send a notification for cache entry created when isPre=false.
- Implement @CacheEntryModified and in it send a notification for cache entry modified when isPre=false.
Problem? If the entry is created, this will generate two notifications (one for created, and one for modified) and @CacheEntryModified can only differentiate between cache entry created vs modified with isPre=true.

Option 2:
- Implement @CacheEntryModified and in it, check whether value is null. If null, entry was created, if not null, entry was modified.
Problem? Only works with isPre=true and this is not good cos you're sending the remote notification before the actual event.

Any other solution requires the listener to keep some state which is ugly to say the least.

If you have any simpler ideas I might have missed, I'm all ears.

Btw, a similar problems happen with cache entry removed and cache entry modified. How do you differentiate between them two when isPre=false?

I haven't checked the JSR-107 listeners yet, but I hope they're more sane in this area. 

Galder Zamarreño
Sr. Software Engineer
Infinispan, JBoss Cache

More information about the infinispan-dev mailing list