Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-11642

Remote JCacheManager doesn't apply configuration from URI

XMLWordPrintable

    • Hide

      Sample Test Class (fill in host, username, and password):

      import java.io.File;
      import java.net.URI;
      import java.util.ArrayList;
      import java.util.Properties;
      
      import javax.cache.CacheManager;
      import javax.cache.Caching;
      import javax.cache.configuration.MutableConfiguration;
      import javax.cache.expiry.EternalExpiryPolicy;
      
      public class InfinispanRemoteTest {
      
          public static void main(String[] args) throws Exception {
              
              /*
               * <infinispan>
               * <cache-container>
               *  <replicated-cache-configuration name="com.myproject.*"/>
               * </cache-container>
               *</infinispan>
               */
              File infinispanXml = new File("./infinispan.xml");
              URI uri = infinispanXml.toURI();
              
              Properties vendorProperties = new Properties();
              vendorProperties.put("infinispan.client.hotrod.server_list", "localhost:11222");
              vendorProperties.put("infinispan.client.hotrod.marshaller", "org.infinispan.commons.marshall.JavaSerializationMarshaller");
              vendorProperties.put("infinispan.client.hotrod.java_serial_whitelist", ".*");
              vendorProperties.put("infinispan.client.hotrod.auth_username", "username");
              vendorProperties.put("infinispan.client.hotrod.auth_password", "password");
              vendorProperties.put("infinispan.client.hotrod.auth_realm", "default");
              vendorProperties.put("infinispan.client.hotrod.sasl_mechanism", "DIGEST-MD5");
              vendorProperties.put("infinispan.client.hotrod.auth_server_name", "infinispan");
              
              MutableConfiguration<String, ArrayList> config = new MutableConfiguration<String, ArrayList>()
                              .setTypes(String.class, ArrayList.class)
                              .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
              
              
              CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, Thread.currentThread().getContextClassLoader(), vendorProperties);
              
              
              //TestJCache API
              cacheManager.createCache("com.myproject.testJCacheAPI2", config);
          }
      }
      

      Sample infinispan.xml

      <infinispan>
       <cache-container>
        <replicated-cache-configuration name="com.myproject.*"/>
       </cache-container>
      </infinispan>
      

      The resulting cache shows the following local-cache configuration on the Infinispan server:

      {
        "local-cache": {
          "transaction": {
            "mode": "NONE"
          },
          "memory": {
            "object": {}
          }
        }
      }
      
      Show
      Sample Test Class (fill in host, username, and password): import java.io.File; import java.net.URI; import java.util.ArrayList; import java.util.Properties; import javax.cache.CacheManager; import javax.cache.Caching; import javax.cache.configuration.MutableConfiguration; import javax.cache.expiry.EternalExpiryPolicy; public class InfinispanRemoteTest { public static void main( String [] args) throws Exception { /* * <infinispan> * <cache-container> * <replicated-cache-configuration name= "com.myproject.*" /> * </cache-container> *</infinispan> */ File infinispanXml = new File( "./infinispan.xml" ); URI uri = infinispanXml.toURI(); Properties vendorProperties = new Properties(); vendorProperties.put( "infinispan.client.hotrod.server_list" , "localhost:11222" ); vendorProperties.put( "infinispan.client.hotrod.marshaller" , "org.infinispan.commons.marshall.JavaSerializationMarshaller" ); vendorProperties.put( "infinispan.client.hotrod.java_serial_whitelist" , ".*" ); vendorProperties.put( "infinispan.client.hotrod.auth_username" , "username" ); vendorProperties.put( "infinispan.client.hotrod.auth_password" , "password" ); vendorProperties.put( "infinispan.client.hotrod.auth_realm" , " default " ); vendorProperties.put( "infinispan.client.hotrod.sasl_mechanism" , "DIGEST-MD5" ); vendorProperties.put( "infinispan.client.hotrod.auth_server_name" , "infinispan" ); MutableConfiguration< String , ArrayList> config = new MutableConfiguration< String , ArrayList>() .setTypes( String .class, ArrayList.class) .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf()); CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, Thread .currentThread().getContextClassLoader(), vendorProperties); //TestJCache API cacheManager.createCache( "com.myproject.testJCacheAPI2" , config); } } Sample infinispan.xml <infinispan> <cache-container> <replicated-cache-configuration name= "com.myproject.*" /> </cache-container> </infinispan> The resulting cache shows the following local-cache configuration on the Infinispan server: { "local-cache" : { "transaction" : { "mode" : "NONE" }, "memory" : { "object" : {} } } }

      Our project is using JCache API's backed by Infinspan. This is a client-server scenario where we are configuring the Hot Rod Java Client to connect to an Infinispan server.

      We are using javax.cache.spi.CachingProvider.getCacheManager(URI, ClassLoader, Properties) to obtain a CacheManager. The URI passed points to an infinispan XML that specifies replicated-cache-configuration as part of the configuration. However the cache created from CacheManager.createCache() ends up being a local cache. This proves to be a problem when connecting to a cluster of Infinispan servers, as when other connections attempt to utilize the cached data, they connect to a different Infinispn sever that doesn't have the cached data. We have verified the XML file pointed to by the URI is on the ClassLoader passed to the CacheManager, and still see the same results.

      When we attempt this same scenario using embedded mode instead of client server mode, the configuration in the URI is applied correctly. We have even been able to create a cluster of embedded Infinispan servers via JGroups and confirmed the caches are replicated and not local.

      We have also attempted this scenario using Infinispan's proprietary APIs:
      RemoteCacheManager.administration().getOrCreateCache(String name, BasicConfiguration configuration)
      The configuration object passed to RemoteCacheManagerAdmin.getOrCreateCache() loads the same Infinispan XML configuration used in the failing remote JCache scenario (as a XMlStringConfiguration object).

              ttarrant@redhat.com Tristan Tarrant
              nmittles Nathan Mittlestat (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: