4 Replies Latest reply on Sep 21, 2016 7:10 PM by pferraro

    Infinispan subsystem does not work as expected

    arielcarrera

      I tried to configure a new replicated cache in a wildfly node configured with a "full-ha" domain profile but I can't get the cache by a jndi reference.

       

      I am developing with an instance of Wildfly 10.0.0.Final (upgraded to 10.1.0.Final).

       

      I added to infinispan subsytem:

                      <cache-container name="test" default-cache="default" >

                          <transport lock-timeout="60000"/>

                          <replicated-cache name="default" mode="SYNC">

                              <locking isolation="REPEATABLE_READ"/>

                              <transaction mode="BATCH"/>

                              <eviction strategy="LRU" max-entries="10000"/>

                          </replicated-cache>

                      </cache-container>

       

      I added the following lines in my Application Bean:

      @ApplicationScoped

      public class AppConfig {

      @Resource(lookup = "java:jboss/infinispan/cache/test/default") 

      private Cache<String,String> testCache;

       

      @Produces @MyCache

      public Cache<String, String> getCache() {

      return testCache;

        }

      }

       

      But I got the following exception:

      Caused by: javax.naming.NameNotFoundException: infinispan/cache/test/default [Root exception is java.lang.IllegalStateException]

      [Server:server-one]       at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:153)

       

      I looked at the jndi tree and I not found any reference to infinispan.

       

      I tried setting jndi-name, looking for "java:jboss/infinispan/container/test/default",  looking for "java:jboss/infinispan/test/default", looking for CacheContainer "java:jboss/infinispan/cache/test", and setting the mappedName attribute...

       

      Anyone have a working example of this?

        • 1. Re: Infinispan subsystem does not work as expected
          pferraro

          CDI beans result in the @Resource annotation being processed by Weld rather than the EE subsystem.  To workaround this, create a <resource-ref/> or <resource-env-ref/> in your deployment descriptor and reference the @Resource by its mapped name.  This way, the EE subsytem will process the deployment descriptor and weld will have no issues resolving the @Resource from the application/module namespace.

          e.g.

          <resource-ref>
             <res-ref-name>testCache</res-ref-name>
             <lookup-name>java:jboss/infinispan/cache/test/default</lookup-name>
          <resource-ref>
          

           

          @Resource(name="testCache")
          private Cache<String,String> testCache;
          
          • 2. Re: Infinispan subsystem does not work as expected
            arielcarrera

            Thanks Paul but I don't have a servlet deployment descriptor (web.xml)... my application is packaged as a default switchyard deployment (jar file).

            Do you know if another workaround exists? Currently I use a programmatically definition to solve it but I prefer to use an infinispan subsystem if can be possible....

            • 3. Re: Infinispan subsystem does not work as expected
              pferraro

              I didn't say anything about needing a servlet deployment descriptor.  Any EE deployment descriptor will do.  I suggest creating an ejb-jar.xml or application-client.xml.

              • 4. Re: Infinispan subsystem does not work as expected
                arielcarrera

                OK Paul. I will take into consideration the suggested change.

                Thanks.