我有一个测试工具,我试图用IgniteCache替换ConcurrentHashMap DS。 我创建了具有相同数据结构的IgniteCache和CacheConfiguration,而我希望新的IgniteCache成为该结构。运行时,它从开始到停止。在调试中,它显示在ignite.getOrCreateCache(cfg);上。步骤会引发NullPointerException
Notes:
1. I need to run this in embedded mode only without any external installations or external start stop service.
2. Added Ignite start and stop in spring lifecycle events of startup() and shutdown() functions.
3. I have added the entries in maven dependency and tested the sample run.
4. It asks for is IGNITE_HOME set? not sure where and what to do if I only want it in embedded mode
5. Default XML file not found on output screen. I added a sample xml file with configuration and imported it into my main sprint-integration.xml file.
代码段:
public class HarnessCache {
Ignite ignite;
private IgniteCache<HarnessCacheKey, ConcurrentHashMap<HarnessDataGroupKey, Object>> harnessCacheMap;
private CacheConfiguration<HarnessCacheKey, ConcurrentHashMap<HarnessDataGroupKey, Object>> cfg;
// private ConcurrentHashMap<HarnessCacheKey, ConcurrentHashMap<HarnessDataGroupKey, Object>> _harnessCacheMap;
private ConcurrentHashMap<String, List<OutMessageDto>> harnessOutMessageMap;
public void startup() {
// Ignition.start("/mte-testharness/src/main/resources/spring-Ignite-cache-load.xml");
Ignition.start();
System.out.println("Test Harness Cache startup....");
cfg = new CacheConfiguration<>();
harnessCacheMap = ignite.getOrCreateCache(cfg);
harnessOutMessageMap = new ConcurrentHashMap<String, List<OutMessageDto>>();
System.out.println("Test Harness Cache ready....");
}
public void shutdown() {
System.out.println("Test Harness Cache shutting down....");
harnessCacheMap.clear();
harnessOutMessageMap.clear();
ignite.close();
}
}
Output console:
[14:05:25] Configured failure handler: [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0]]
[14:05:25] Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides.
[14:05:25] Security status [authentication=off, tls/ssl=off]
[14:05:28] Performance suggestions for grid (fix if possible)
[14:05:28] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[14:05:28] ^-- Enable G1 Garbage Collector (add '-XX:+UseG1GC' to JVM options)
[14:05:28] ^-- Specify JVM heap max size (add '-Xmx<size>[g|G|m|M|k|K]' to JVM options)
[14:05:28] ^-- Set max direct memory size if getting 'OOME: Direct buffer memory' (add '-XX:MaxDirectMemorySize=<size>[g|G|m|M|k|K]' to JVM options)
[14:05:28] ^-- Disable processing of calls to System.gc() (add '-XX:+DisableExplicitGC' to JVM options)
[14:05:28] ^-- Disable assertions (remove '-ea' from JVM options)
[14:05:28] Refer to this page for more performance suggestions: https://apacheignite.readme.io/docs/jvm-and-system-tuning
[14:05:28]
[14:05:28] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[14:05:28]
[14:05:28] Ignite node started OK (id=a9e097dd)
[14:05:28] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, offheap=3.2GB, heap=3.5GB]
[14:05:28] ^-- Node [id=A9E097DD-64E1-4699-9237-65AF0E68D975, clusterState=ACTIVE]
[14:05:28] Data Regions Configured:
[14:05:28] ^-- default [initSize=256.0 MiB, maxSize=3.2 GiB, persistenceEnabled=false]
Test Harness Cache startup....
[14:05:28] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml
[14:05:29] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml
[14:05:29] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml
[14:05:30] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml
[14:05:30] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml
[14:05:30] Ignite node stopped OK [uptime=00:00:02.341]
我是Ignite的新手,这是运行一些示例后的第一个应用程序。如果我缺少任何明显的配置文件或设置,请提及。
谢谢你, 维杰
答案 0 :(得分:2)
它在行上抛出NullPointerException
harnessCacheMap = ignite.getOrCreateCache(cfg);
因为变量ignite中没有设置任何内容,所以它等于null。 如果要使用此变量,则应进行设置:
ignite = Ignition.start();