7 Replies Latest reply on Jan 17, 2017 4:39 AM by simplex-software

    Infinispan listener won't fire

    simplex-software

      Hello,

       

      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

        • 1. Re: Infinispan listener won't fire
          sebastian.laskawiec

          Could you please confirm that the interceptor is working? Just invoke a method with @CacheResult annotation a couple of times and check content of the CacheContainer.

           

          If it doesn't work, you might need to add these interceptors in your beans.xml file:

          <beans>

              <interceptors>

                  <class>org.infinispan.jcache.annotation.InjectedCacheResultInterceptor</class>

                  <class>org.infinispan.jcache.annotation.InjectedCachePutInterceptor</class>

                  <class>org.infinispan.jcache.annotation.InjectedCacheRemoveEntryInterceptor</class>

                  <class>org.infinispan.jcache.annotation.InjectedCacheRemoveAllInterceptor</class>

              </interceptors>

          </beans>

          • 2. Re: Infinispan listener won't fire
            simplex-software

            If I could confirm that the interceptor is working, do you think I would have posted an issue titled "Infinispan listener won't fire" ? And yes, of course I added the interceptors.

            So, it simply doesn't work. If someone has real working code using Infinispan listeners with javax.cache annotations, then I'd be interested to exchange on that. But for me, Infinispan comming with Wildfly 10.0 doesn't support javax.cache annotations.

             

            Kind regards,

             

            Nicolas

            • 3. Re: Infinispan listener won't fire
              galder.zamarreno

              If I could confirm that the interceptor is working, do you think I would have posted an issue titled "Infinispan listener won't fire" ? And yes, of course I added the interceptors.

              Maybe you misunderstood Sebastian's attempt to help out, but I think the aim of his post was to see if even before any listener invocations happen, whether the actual interceptors that deal with the javax.annotation instances work at all. In other words, whether a cache put is actually being executed at all indirectly via the annotations.

               

              If things are not still working, it helps everyone if we all work together to get to the bottom of this. To start with, enabling TRACE logging for "org.infinispan" package would a step forward to inspect what is going on underneath.

               

              Moreover, if you have a working test case that you can attach that we can run locally, it would help even further.

               

              Finally, if you want to go the extra mile, you can even fork our repository and maybe extend CacheResultInterceptorTest to add your scenario. AFAIK, we don't currently have such a test where we combine javax.annotation instances along with cache listeners.

              • 4. Re: Infinispan listener won't fire
                simplex-software

                AFAIK, we don't currently have such a test where we combine javax.annotation instances along with cache listeners.

                Thanks for this update. I'm not sure who is "we" here above. But since such a test case doesn't seem to exist, do you think that I could  consider that the feature I'm looking for isn't tested at all yet ? And hence, waiting for it to be tested, there is no worth trying to use it for now ? 'Cause then I don't have time to test or trace it myself and I prefer using solutions which I know for sure they work.

                 

                Many thanks in advance,

                 

                Nicolas

                • 5. Re: Infinispan listener won't fire
                  rvansa

                  If you prefer "solutions", Infinispan is productized as Red Hat JBoss Data Grid . Infinispan is a community project, and that means that users actively help out developers to test the functionality, report problems (as you did) and can even become contributors, making sure that their use case works as expected. Since you seem in hurry, that is what Galder suggested.

                  • 6. Re: Infinispan listener won't fire
                    galder.zamarreno

                    > I'm not sure who is "we" here above

                     

                    We means the Infinispan community, whose work is layed out here: https://github.com/infinispan/infinispan

                    • 7. Re: Infinispan listener won't fire
                      simplex-software

                      Yeah, it doesn't help much in solving my issue but thanks for mentioning it. It was worth asking as it would have been difficult to guess it.