Infinispan listener won't fire
simplex-software Dec 29, 2016 5:34 AMHello,
I have configured the following Infinispan cache container:
<cache-container name="ldap" default-cache="ldap-cache"> | |
<local-cache name="ldap-cache"/> | |
</cache-container> |
I have the following listener:
@Listener
public class InfinispanListener
{
private static final Logger log = LoggerFactory.getLogger(InfinispanListener.class);
@CacheEntryCreated
public void addKey(@Observes CacheEntryCreatedEvent<?, ?> event)
{
log.info("New entry " + event.getKey() + " created in the cache with value " + event.getValue());
}
@CacheEntryRemoved
public void removeKey(@Observes CacheEntryRemovedEvent<?,?> event)
{
log.info("Entry " + event.getKey() + " removed from the cache");
}
@CacheStarted
public void cacheStarted(@Observes CacheStartedEvent event)
{
log.info("Cache Started");
}
@CacheStopped
public void cacheStopped(@Observes CacheStoppedEvent event)
{
log.info("Cache Stopped");
}
}
In order to test it I do:
@Startup
@Singleton
public class InfinispanListenerManager
{
private static final Logger log = LoggerFactory.getLogger(InfinispanListener.class);
@Resource(lookup="java:jboss/infinispan/container/ldap")
private CacheContainer cacheContainer;
@PostConstruct
public void registerListener()
{
Cache<Object,Object> ldapCache = cacheContainer.getCache("ldap");
ldapCache.addListener(new InfinispanListener());
ldapCache.put("Test","azerty");
log.info("Have inserted an entry to the LDAP cache");
}
}
and it works as the listener addKey method fires. Now, I want to use javax.cache annotations, as follows:
@CacheResult(cacheName="ldap-cache")
public Company findByDistinguishedName(Name name)
{
return companyRepo.findOne(name);
}
Calling this method, I expect that it creates a new entry in the associated cache and then fire the listener as in the previous test. But this doesn't happen.
To resume, when entries are directly created by put statements the listener fires but it doesn't seem to do so when using javax.cache annotations. Any suggestion of what I'm missing here ?
Many tanks in advance fpr any help.
Nicolas