1 Reply Latest reply on Jun 30, 2014 5:50 AM by Grégory Bataille

    Infinispan's BaseCustomInterceptor not loading the cache attribute

    Grégory Bataille Newbie

      Hey guys,


      so I wanted to play with cache interceptors and register one that react to get operations.

      As per the doc, CDI does not work in infinispan interceptors (I tried). What you are supposed to do is inherit from the BaseCustomInterceptor class that has a cache attribute as well as a embeddedCacheManager one. So I did that.

      - I created my interceptor that extends BaseCustomInterceptor,

      - I register it programatically at runtime

      - It works (the code is executing, as traced in the logs)

      - but both cache and embeddedCacheManager attributes are null.

      I have absolutely no stack trace or warning to go by!


      Anyone has ever seen that or has an idea what can be done?




      cacheManager.getPositionCache().getAdvancedCache().addInterceptor(new LoaderInterceptor(), 0);



      package com.octo.randd.bigdata.rtpm.lazyload;



      import com.octo.randd.bigdata.rtpm.cache.CacheManager;

      import org.infinispan.commands.read.GetKeyValueCommand;

      import org.infinispan.context.InvocationContext;

      import org.infinispan.interceptors.base.BaseCustomInterceptor;

      import org.jboss.logging.Logger;



      import javax.inject.Inject;




      * Created by gbataille on 24/06/14.


      public class LoaderInterceptor extends BaseCustomInterceptor {

          private static final Logger logger = Logger.getLogger(LoaderInterceptor.class);




          CacheManager cacheManager;




          public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {

              logger.info( "accessing a key : " + command.getKey());

              logger.info( (ctx.isOriginLocal() ? "local" : "remote"));

              if (cache != null) {

                  logger.info("This key sits on " + cache.getAdvancedCache().getDistributionManager().locate(command.getKey()));

              } else {

                  if (cacheManager != null) {

                      logger.info("cacheManager is accessible");

                      if (cacheManager.getPositionCache() != null) {

                          logger.info("access to position cache");



                  logger.info("cache is null");


              if (embeddedCacheManager == null) {

                  logger.info("embeddedCacheManager is null");


              if (command.getRemotelyFetchedValue() != null) {



              return super.visitGetKeyValueCommand(ctx, command);





        • 1. Re: Infinispan's BaseCustomInterceptor not loading the cache attribute
          Grégory Bataille Newbie

          Adding a bit more data. Looking at the Infinispan code, I see that BaseCustomInterceptor has a setup(Cache<?, ?>, EmbeddedCacheManager) method, annotated with @Inject.

          I figured that maybe I should not do a new LoaderInterceptor in my code, but rather inject it. If I do so, I get an error:


          [Server:server-two] 11:29:14,512 ERROR [org.infinispan.interceptors.InterceptorChain] (ServerService Thread Pool -- 78) ISPN000173: Custom interceptor com.octo.randd.bigdata.rtpm.lazyload.LoaderInterceptor$Proxy$_$$_Weld$EnterpriseProxy$ has used @Inject, @Start or @Stop. These methods will not be processed. Please extend org.infinispan.interceptors.base.BaseCustomInterceptor instead, and your custom interceptor will have access to a cache and cacheManager.  Override stop() and start() for lifecycle methods.


          I have tried quite a few things now, and I still don't get anything in the cache attribute!