5 Replies Latest reply on May 30, 2014 12:32 PM by smohanan

    NullPointerException for KeyAffinityService

    smohanan

      I was trying to implement the KeyAffinityService in order to get the key associated with the local node but I get a NullPointerException. I was hoping if someone can help me figure my mistake.

      The code snippet is the following:

       

              // Create the affinity service to find the Key for the manager
              KeyAffinityService keyAffinityService = KeyAffinityServiceFactory.newLocalKeyAffinityService(
                      cache,
                      (KeyGenerator)new RndKeyGenerator(),
                      Executors.newSingleThreadExecutor(),
                      100);
      
      

       

      The implementation of cache is done as following:

       

      EmbeddedCacheManager manager = new DefaultCacheManager();
              try{
        manager = new DefaultCacheManager("democluster.xml");
              }catch(IOException e){}
        Cache<Integer, String> cache = manager.getCache();
      
      

       

      The xml file used is the following:

       

      <infinispan
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
            xmlns="urn:infinispan:config:5.1">
      
      
         <global>
            <transport clusterName="demoCluster"/>
            <globalJmxStatistics enabled="true"/>
         </global>
      
      
         <namedCache name="clusteredCache">
              <clustering mode="distributed">
              <hash numOwners="1" >
                 <groups enabled="true"/>
              </hash>
              </clustering>
          </namedCache>
      
      
      </infinispan>
      
      

       

      The error I get is the following:

       

      Exception in thread "main" java.lang.NullPointerException
        at org.infinispan.affinity.KeyAffinityServiceFactory.newLocalKeyAffinityService(KeyAffinityServiceFactory.java:95)
        at org.infinispan.affinity.KeyAffinityServiceFactory.newLocalKeyAffinityService(KeyAffinityServiceFactory.java:104)
        at SimpleCache.start(SimpleCache.java:46)
        at SimpleCache.main(SimpleCache.java:96)
      
      

      I was wondering if anyone had encountered anything similar or might have any ideas regarding this problem.

       

      Best Regards,

      Sree Ram Mohanan