我是Infinispan的新手。我试图通过我的Java代码获取缓存的统计信息。通过谷歌搜索,我发现了一些方法,但没有任何结果证明是我的解决方案。请查看代码,并告诉我我失踪的地方。
import java.io.IOException;
import org.infinispan.Cache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfiguration;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
public class InfinispanCacheStats {
public static void main(String[] args) throws InterruptedException, IOException {
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.globalJmxStatistics()
.enable()
.build();
Configuration config = new ConfigurationBuilder()
.expiration().wakeUpInterval(5000l).lifespan(1000l).maxIdle(500l)
.build();
config.jmxStatistics().enabled();
DefaultCacheManager m = new DefaultCacheManager(globalConfig, config, true);
// DefaultCacheManager m = new DefaultCacheManager("D:\\infinispan.xml");
Cache<Integer, String> cache = m.getCache();
cache.start();
System.out.println(m.getCache().getAdvancedCache().getStats().getStores());
}
}
我也尝试配置infinispan.xml文件并将其提供给DefaultCacheManager(),但它会产生以下异常
Exception in thread "main" java.util.ServiceConfigurationError: org.infinispan.lifecycle.ModuleLifecycle: Provider org.infinispan.query.impl.LifecycleManager could not be instantiated
at java.util.ServiceLoader.fail(Unknown Source)
at java.util.ServiceLoader.access$100(Unknown Source)
at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
at java.util.ServiceLoader$1.next(Unknown Source)
at org.infinispan.commons.util.ServiceFinder.addServices(ServiceFinder.java:60)
at org.infinispan.commons.util.ServiceFinder.load(ServiceFinder.java:42)
at org.infinispan.util.ModuleProperties.resolveModuleLifecycles(ModuleProperties.java:41)
at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:94)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:292)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:271)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:244)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:231)
at com.practice.asrl.infinispan.InfinispanCacheStats.main(InfinispanCacheStats.java:26)
Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
... 11 more
Caused by: java.lang.IllegalArgumentException: Logger implementation class org.infinispan.query.logging.Log_$logger has no matching constructor
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2256)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
at org.infinispan.util.logging.LogFactory.getLog(LogFactory.java:21)
at org.infinispan.query.impl.LifecycleManager.<clinit>(LifecycleManager.java:82)
... 16 more
infinispan.xml的内容:
<infinispan>
<cache-container statistics="true"/>
</infinispan>
任何帮助将不胜感激
答案 0 :(得分:1)
You need to enable the statistics from the ConfigurationBuilder object. They are disabled by default.
Configuration config = new ConfigurationBuilder()
.expiration().wakeUpInterval(5000l).lifespan(1000l).maxIdle(500l)
.jmxStatistics().enable()
.build();
When you call config.jmxStatistics().enabled();
this will tell you if the statistics are enabled or not, but that won't change the configuration.