anandbright
anandbright

Reputation: 19

ignite.getOrCreateCache(cfg) throwing NullPointerException when creating cache with a custom cache configuration

I have a Test Harness where I am trying to replace ConcurrentHashMap DS with IgniteCache.  I created an IgniteCache and a CacheConfiguration with same data structure which I want my new IgniteCache to be. Upon running it goes from start to stop. In debugging it shows that on ignite.getOrCreateCache(cfg); step it throws 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. 

Code snippet:

        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] 

I am new to Ignite and this is the very first application after some sample runs. Please mention if I am missing out on any obvious config file or setting. 

Thank you,  Vijay

Upvotes: 1

Views: 440

Answers (1)

Evgenii Zhuravlev
Evgenii Zhuravlev

Reputation: 3017

it throws NullPointerException on line

   harnessCacheMap = ignite.getOrCreateCache(cfg);

because you don't have anything set in variable ignite, it equals null. If you want to use this variable, you should set it:

ignite = Ignition.start();

Upvotes: 2

Related Questions