Infinispan's BaseCustomInterceptor not loading the cache attribute
gbataille Jun 29, 2014 9:26 AMHey 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);
@Inject
CacheManager cacheManager;
@Override
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) {
logger.info(command.getRemotelyFetchedValue().toString());
}
return super.visitGetKeyValueCommand(ctx, command);
}
}