[英]Initialization of Infinispan cache fails
I use JBoss 6.4 EAP and Infinispan 6. 我使用JBoss 6.4 EAP和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. 我有一个初始化Infinispan缓存管理器的代码。
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. 当我不以XML文件的形式提供其他配置时,它可以正常工作。 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. 当我的应用程序尝试获取“ my_cache”缓存实例时,该缓存实例为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). 在这种情况下,方法cw.getCache()返回null(高速缓存的名称在高速缓存列表中可用,并且配置也可用)。
I need distributed my_cache cache instance that I can define into XML file. 我需要可以定义为XML文件的分布式my_cache缓存实例。
Could someone explain why Infinispan returns null in this case? 有人可以解释为什么Infinispan在这种情况下返回null吗?
Have you tried using DefaultCacheManagher#defineConfiguration(cacheName, configuration)
? 您是否尝试过使用
DefaultCacheManagher#defineConfiguration(cacheName, configuration)
? It should does exactly what you need (but probably you will need to migrate your XML to ConfigurationBuilder
and friends). 它应该完全满足您的需要(但可能需要将XML迁移到
ConfigurationBuilder
和朋友)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.