radinho
radinho

Reputation: 1

Initialization of Infinispan cache fails

I use JBoss 6.4 EAP and Infinispan 6.

  <dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-core</artifactId>
    <version>6.0.2.G1.Final</version>
  </dependency>

I have a code that initializes Infinispan cache manager.

public class CacheManager {
    ...

    private synchronized DefaultCacheManager getManager() {
        if (this.manager != null) {
            return this.manager;
        }

        if (externalConfigFile != null) {
            FileInputStream configurationStream = null;
            try {
                configurationStream = new FileInputStream(externalConfigFile);
                ConfigurationBuilderHolder holder = new ParserRegistry().parse(configurationStream);
                initJmx(holder.getGlobalConfigurationBuilder());
                manager = new DefaultCacheManager(holder, true);
            } catch (IOException e) {
                String msg = "Error creating Infinispan cache manager from file " + externalConfigFile;
                throw new SomeException(msg, e);
            } finally {
                if (configurationStream != null) {
                    try {
                        configurationStream.close();
                    } catch (IOException e) {
                        throw new CacheInitException(e);
                    }
                }
            }
        } else {
            GlobalConfigurationBuilder globalConfigurationBuilder = new GlobalConfigurationBuilder();
            initJmx(globalConfigurationBuilder);
            manager = new DefaultCacheManager(globalConfigurationBuilder.build());
        }

        started = true;
        return manager;
    }

    private void initJmx(GlobalConfigurationBuilder globalConfigurationBuilder) {
        globalConfigurationBuilder.globalJmxStatistics().cacheManagerName("aaaa");
        globalConfigurationBuilder.globalJmxStatistics().allowDuplicateDomains(true);
    }

   ...
}

It works without any problem when I don't provide additional configuration in the form of XML file. But when I provide following additional configuration

<infinispan>
    <namedCache name="my_cache" >
        <eviction strategy="LIRS" maxEntries="65535" />
        <clustering mode="dist">
            <async />
        </clustering>
    </namedCache>  
</infinispan>

and when my application tries to get 'my_cache' cache instance, the cache instance is null.

package org.infinispan.manager;

public class DefaultCacheManager implements EmbeddedCacheManager, CacheManager {
   ...

   @Override
   public <K, V> Cache<K, V> getCache(String cacheName) {
      assertIsNotTerminated();
      if (cacheName == null)
         throw new NullPointerException("Null arguments not allowed");

      CacheWrapper cw = caches.get(cacheName);
      if (cw != null) {
         return cw.getCache();
      }

      return createCache(cacheName);
   }

   ...
}

In this case method cw.getCache() returns null (name of the cache is available into the list of caches and configuration is also available).

I need distributed my_cache cache instance that I can define into XML file.

Could someone explain why Infinispan returns null in this case?

Upvotes: 0

Views: 1832

Answers (1)

Sebastian Łaskawiec
Sebastian Łaskawiec

Reputation: 2737

Have you tried using DefaultCacheManagher#defineConfiguration(cacheName, configuration)? It should does exactly what you need (but probably you will need to migrate your XML to ConfigurationBuilder and friends).

Upvotes: 1

Related Questions