【问题标题】:ignite.getOrCreateCache(cfg) throwing NullPointerException when creating cache with a custom cache configurationignite.getOrCreateCache(cfg) 在使用自定义缓存配置创建缓存时抛出 NullPointerException
【发布时间】:2018-08-06 22:29:13
【问题描述】:

我有一个测试工具,我试图用 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. 

代码sn-p:

        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 的新手,这是运行一些示例后的第一个应用程序。请提及我是否遗漏了任何明显的配置文件或设置。

谢谢你, 维杰

【问题讨论】:

    标签: ignite


    【解决方案1】:

    它在行上抛出 NullPointerException

       harnessCacheMap = ignite.getOrCreateCache(cfg);
    

    因为您没有在变量 ignite 中设置任何内容,所以它等于 null。 如果你想使用这个变量,你应该设置它:

    ignite = Ignition.start();
    

    【讨论】:

    • 谢谢,知道了。当我在 spring 的 startup() 方法中推送 Ignition.start() 时,我错过了。进行上述更改后,它不会抛出 Null,但会显示 IllegalArgumentException : Error Creating bean with name 'harnessCache' 但 ignite.getOrCreateCache(cfg) 的示例生成与我写的相同。如果我将缓存配置声明为 CacheConfiguration> 并在初始化时传递它,会有什么问题吗?
    • @anandbright 我会发布另一个关于创建 bean 的错误的问题。您必须提供堆栈跟踪和其他相关信息。
    • 同意 Dmitriy,我建议发布新问题
    猜你喜欢
    • 2015-07-16
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 2018-11-29
    • 2015-06-25
    • 1970-01-01
    • 2012-08-25
    相关资源
    最近更新 更多