11 Replies Latest reply on Jun 22, 2016 4:45 PM by Paul Ferraro

    WildFly10: What is the right way to get preconfigured Infinispan cache instance?

    Maxim Karavaev Newbie

      Dear forum,

       

      Does someone managed to get access to the preconfigured Infinispan cache instance in the WildFly 10? Because, I can't to do it (at least the same way as in WildFly9)

       

      Here was my way:

       

      I just uses a cache with a custom store configuration. Cache configured through the jboss-cli like this:

       

      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer:add()
      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer/transport=TRANSPORT:add(lock-timeout=60000)
      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer/replicated-cache=test:add(mode=ASYNC)
      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer/replicated-cache=test/store=STORE:add(class=org.infinispan.persistence.sifs.configuration.SoftIndexFileStoreConfigurationBuilder,passivation=false,preload=false,purge=false,properties={dataLocation=${jboss.server.data.dir}/infinispan/container/testData,indexLocation=${jboss.server.data.dir}/infinispan/container/testIndex})
      

      I want to use a custom persistance implementation (corresponded modules added to the WildFly).

      Ok, I found, that the WF10 uses different configuration model (WFLY-4452 Use Flag.RESTART_RESOURCE_SERVICES for child resources of cache by pferraro · Pull Request #7407 · wildfly/wil…) and changed scripts accordingly.

      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer:add()
      /profile=full-ha/subsystem=infinispan/cache-container=acheContainer/transport=jgroups:add(lock-timeout=60000)
      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer/replicated-cache=test:add(mode=ASYNC)
      /profile=full-ha/subsystem=infinispan/cache-container=cacheContainer/replicated-cache=test/store=custom:add(class=org.infinispan.persistence.sifs.configuration.SoftIndexFileStoreConfigurationBuilder,passivation=false,preload=false,purge=false,properties={dataLocation=${jboss.server.data.dir}/infinispan/container/testData,indexLocation=${jboss.server.data.dir}/infinispan/container/testIndex})
      

       

      But it doesn't help.

       

      I know, that to start my Infinispan container in WF9 I need to inject a CacheContainer instance inside the EJB container and after that, I can use CacheContainer.getCache("test") to get access to a properly configured cache instance.

       

      @Singleton
      @Startup
      public class CacheAccessBean {
      
      @Resource(lookup = "java:jboss/infinispan/container/cacheContainer")
      private CacheContainer cc;
      
      @PostConstruct
      public void init() {
          Cache cache = cc.getCache("test");
      ...
      }
      

       

      This is not work in WilfFly10. As I can see, the CacheContainer which is injected into the EJB container doesn't have any named configurations. So the invocation of the CacheContainer.getCache("test") returns a default cache (without any specific configurations).

       

      I was told by Paul Ferraro, that I should use a direct injection of the Cache instance:

      @Resource(lookup="java:jboss/infinispan/cache/cacheContainer/test") Cache<K, V> cache;
      

       

      But such trick does not work. It didn't work in WF9 too. I just get a deploy time exception, that the resource reference "java:jboss/infinispan/cache/cacheContainer/test" cannot be populated (it just doesn't binded at all).

       

      What did I wrong? Is there any special trick to start Cache service with the predefined configuration in WildFly10?

       

      Thanks for any advice!